|
| 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 | +}); |
0 commit comments