-
Notifications
You must be signed in to change notification settings - Fork 702
Add Razor Diagnostic Test #8266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryzngard
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
ryzngard:diagnostic_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
test/razor/razorIntegrationTests/diagnostics.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import { beforeAll, afterAll, test, expect } from '@jest/globals'; | ||
import testAssetWorkspace from './testAssets/testAssetWorkspace'; | ||
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers'; | ||
|
||
integrationHelpers.describeIfDevKit(`Razor Diagnostics ${testAssetWorkspace.description}`, function () { | ||
beforeAll(async function () { | ||
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { | ||
return; | ||
} | ||
|
||
await integrationHelpers.activateCSharpExtension(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testAssetWorkspace.cleanupWorkspace(); | ||
}); | ||
|
||
test('CSharp and Razor Diagnostics', async () => { | ||
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) { | ||
return; | ||
} | ||
|
||
let count = 0; | ||
let error; | ||
|
||
while (count < 5) { | ||
try { | ||
await integrationHelpers.closeAllEditorsAsync(); | ||
await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'Diagnostics.razor')); | ||
|
||
await integrationHelpers.waitForExpectedResult<vscode.Diagnostic[]>( | ||
() => vscode.languages.getDiagnostics(vscode.window.activeTextEditor!.document.uri), | ||
5000, | ||
500, | ||
(diagnostics) => { | ||
expect(diagnostics.length).toBe(3); | ||
|
||
expect(diagnostics[0].code).toBe('RZ10012'); | ||
expect(diagnostics[0].message).toBe( | ||
"Found markup element with unexpected name 'TagHelperDoesNotExist'. If this is intended to be a component, add a @using directive for its namespace." | ||
); | ||
expect(diagnostics[0].severity).toBe(vscode.DiagnosticSeverity.Warning); | ||
expect(diagnostics[0].range).toStrictEqual(new vscode.Range(2, 0, 2, 25)); | ||
expect(diagnostics[0].source).toBe('Razor'); | ||
|
||
expect(diagnostics[1].message).toBe("The name 'Message' does not exist in the current context"); | ||
expect(diagnostics[1].severity).toBe(vscode.DiagnosticSeverity.Error); | ||
expect(diagnostics[1].range).toStrictEqual(new vscode.Range(6, 9, 6, 16)); | ||
expect(diagnostics[1].source).toBe(undefined); | ||
const diag1Code = diagnostics[1].code as { | ||
value: string | number; | ||
target: vscode.Uri; | ||
}; | ||
expect(diag1Code).toBeDefined(); | ||
expect(diag1Code.value).toBe('CS0103'); | ||
expect(diag1Code.target.toString()).toBe( | ||
'https://msdn.microsoft.com/query/roslyn.query?appId%3Droslyn%26k%3Dk%28CS0103%29' | ||
); | ||
|
||
expect(diagnostics[2].message).toBe( | ||
"The type or namespace name 'TypeDoesNotExist' could not be found (are you missing a using directive or an assembly reference?)" | ||
); | ||
expect(diagnostics[2].severity).toBe(vscode.DiagnosticSeverity.Error); | ||
expect(diagnostics[2].range).toStrictEqual(new vscode.Range(15, 20, 15, 36)); | ||
expect(diagnostics[2].source).toBe(undefined); | ||
const diag2Code = diagnostics[2].code as { | ||
value: string | number; | ||
target: vscode.Uri; | ||
}; | ||
expect(diag2Code).toBeDefined(); | ||
expect(diag2Code.value).toBe('CS0246'); | ||
expect(diag2Code.target.toString()).toBe( | ||
'https://msdn.microsoft.com/query/roslyn.query?appId%3Droslyn%26k%3Dk%28CS0246%29' | ||
); | ||
} | ||
); | ||
|
||
// If this hits that means the expected results succeeded | ||
// and we can stop the loop | ||
return; | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
count++; | ||
} | ||
|
||
throw error; | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/razor/razorIntegrationTests/testAssets/RazorApp/Pages/Diagnostics.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/diagnostics" | ||
|
||
<TagHelperDoesNotExist /> | ||
|
||
@if (true) | ||
{ | ||
<h1>@Message</h1> | ||
} | ||
|
||
<div /> | ||
|
||
@code | ||
{ | ||
public void M() | ||
{ | ||
var x = new TypeDoesNotExist(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not validate the C# diagnostic code too? Would confirm we're sending it through correctly etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me add that. I wasn't sure how to do it because it's a weird definition but I think I can use
toStrictEqual
and achieve thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's not the same as the Razor one above? That's interesting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it's a code + uri