Skip to content

Commit 4a44394

Browse files
committed
Add a diagnostics test
1 parent 746dd5a commit 4a44394

File tree

5 files changed

+98
-7
lines changed

5 files changed

+98
-7
lines changed

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
// The profile can be found under /test/csharp-test-profile.
7777
"--profile",
7878
"csharp-test-profile",
79-
"${workspaceRoot}/test/razor/razorIntegrationTests/testAssets/RazorApp/.vscode/RazorApp.code-workspace",
79+
"${workspaceRoot}/test/razor/razorIntegrationTests/testAssets/RazorApp/.vscode/devkit_RazorApp.code-workspace",
8080
"--extensionDevelopmentPath=${workspaceRoot}",
8181
"--extensionTestsPath=${workspaceRoot}/out/test/razor/razorIntegrationTests",
8282
"--log",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as path from 'path';
7+
import * as vscode from 'vscode';
8+
import { beforeAll, afterAll, test, expect } from '@jest/globals';
9+
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10+
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
11+
12+
integrationHelpers.describeIfDevKit(`Razor Diagnostics ${testAssetWorkspace.description}`, function () {
13+
beforeAll(async function () {
14+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
15+
return;
16+
}
17+
18+
await integrationHelpers.activateCSharpExtension();
19+
});
20+
21+
afterAll(async () => {
22+
await testAssetWorkspace.cleanupWorkspace();
23+
});
24+
25+
test('CSharp Diagnostics', async () => {
26+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
27+
return;
28+
}
29+
30+
let count = 0;
31+
let error;
32+
33+
while (count < 5) {
34+
try {
35+
await integrationHelpers.closeAllEditorsAsync();
36+
await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'Diagnostics.razor'));
37+
38+
await integrationHelpers.waitForExpectedResult<vscode.Diagnostic[]>(
39+
() => vscode.languages.getDiagnostics(vscode.window.activeTextEditor!.document.uri),
40+
5000,
41+
500,
42+
(diagnostics) => {
43+
expect(diagnostics.length).toBe(3);
44+
45+
expect(diagnostics[0].code).toBe('RZ10012');
46+
expect(diagnostics[0].message).toBe(
47+
"Found markup element with unexpected name 'TagHelperDoesNotExist'. If this is intended to be a component, add a @using directive for its namespace."
48+
);
49+
expect(diagnostics[0].severity).toBe(vscode.DiagnosticSeverity.Warning);
50+
expect(diagnostics[0].range).toStrictEqual(new vscode.Range(2, 0, 2, 25));
51+
expect(diagnostics[0].source).toBe('Razor');
52+
53+
expect(diagnostics[1].message).toBe("The name 'Message' does not exist in the current context");
54+
expect(diagnostics[1].severity).toBe(vscode.DiagnosticSeverity.Error);
55+
expect(diagnostics[1].range).toStrictEqual(new vscode.Range(6, 9, 6, 16));
56+
expect(diagnostics[1].source).toBe(undefined);
57+
58+
expect(diagnostics[2].message).toBe(
59+
"The type or namespace name 'TypeDoesNotExist' could not be found (are you missing a using directive or an assembly reference?)"
60+
);
61+
expect(diagnostics[2].severity).toBe(vscode.DiagnosticSeverity.Error);
62+
expect(diagnostics[2].range).toStrictEqual(new vscode.Range(15, 20, 15, 36));
63+
expect(diagnostics[2].source).toBe(undefined);
64+
}
65+
);
66+
67+
// If this hits that means the expected results succeeded
68+
// and we can stop the loop
69+
return;
70+
} catch (e) {
71+
error = e;
72+
}
73+
74+
count++;
75+
}
76+
77+
throw error;
78+
});
79+
});

test/razor/razorIntegrationTests/testAssets/RazorApp/.vscode/RazorApp.code-workspace

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
],
77
"settings": {
88
"dotnet.defaultSolution": "RazorApp.sln",
9-
"dotnet.server.useOmnisharp": false,
10-
"omnisharp.enableLspDriver": false,
11-
"razor.server.trace": "Trace",
129
"dotnet.preferCSharpExtension": true
1310
}
1411
}

test/razor/razorIntegrationTests/testAssets/RazorApp/.vscode/devkit_RazorApp.code-workspace

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
],
77
"settings": {
88
"dotnet.defaultSolution": "RazorApp.sln",
9-
"dotnet.server.useOmnisharp": false,
10-
"omnisharp.enableLspDriver": false,
11-
"razor.server.trace": "Trace",
129
"dotnet.preferCSharpExtension": false
1310
}
1411
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/diagnostics"
2+
3+
<TagHelperDoesNotExist />
4+
5+
@if (true)
6+
{
7+
<h1>@Message</h1>
8+
}
9+
10+
<div />
11+
12+
@code
13+
{
14+
public void M()
15+
{
16+
var x = new TypeDoesNotExist();
17+
}
18+
}

0 commit comments

Comments
 (0)