()
| 13 | import {waitFor} from './utils'; |
| 14 | |
| 15 | export async function run() { |
| 16 | const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; |
| 17 | if (!workspaceRoot) { |
| 18 | throw new Error('No workspace root found'); |
| 19 | } |
| 20 | |
| 21 | const extTsFilePath = path.join(workspaceRoot, 'diagnostics_ext_test.ts'); |
| 22 | const extTsUri = vscode.Uri.file(extTsFilePath); |
| 23 | const extHtmlFilePath = path.join(workspaceRoot, 'diagnostics_ext_test.html'); |
| 24 | const extHtmlUri = vscode.Uri.file(extHtmlFilePath); |
| 25 | |
| 26 | const extTsContent = ` |
| 27 | import {Component} from '@angular/core'; |
| 28 | @Component({ |
| 29 | selector: 'app-diag-ext-test', |
| 30 | templateUrl: './diagnostics_ext_test.html', |
| 31 | standalone: true, |
| 32 | }) |
| 33 | export class AppDiagExtTestComponent { |
| 34 | name: string = "hello"; |
| 35 | } |
| 36 | `; |
| 37 | |
| 38 | const extHtmlContent = `<div>{{ nonExistentProp }}</div>`; |
| 39 | |
| 40 | console.log(`Creating files: ${extHtmlFilePath}, ${extTsFilePath}`); |
| 41 | await Promise.all([ |
| 42 | fs.writeFile(extHtmlFilePath, extHtmlContent), |
| 43 | fs.writeFile(extTsFilePath, extTsContent), |
| 44 | ]); |
| 45 | |
| 46 | try { |
| 47 | console.log(`Open external test TS file: ${extTsFilePath}`); |
| 48 | const tsDoc = await vscode.workspace.openTextDocument(extTsUri); |
| 49 | await vscode.window.showTextDocument(tsDoc); |
| 50 | |
| 51 | // Wait for server to analyze TS file |
| 52 | await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 53 | |
| 54 | console.log(`Open external test HTML file: ${extHtmlFilePath}`); |
| 55 | const htmlDoc = await vscode.workspace.openTextDocument(extHtmlUri); |
| 56 | await vscode.window.showTextDocument(htmlDoc); |
| 57 | |
| 58 | console.log(`Waiting for diagnostics on HTML file...`); |
| 59 | const diagnostics = await waitFor( |
| 60 | () => vscode.languages.getDiagnostics(extHtmlUri), |
| 61 | (diags) => diags.length > 0, |
| 62 | {timeout: 10000}, |
| 63 | ); |
| 64 | |
| 65 | assert.ok(diagnostics.length > 0, 'Should return at least one diagnostic'); |
| 66 | |
| 67 | const found = diagnostics.find((d) => d.message.includes('nonExistentProp')); |
| 68 | assert.ok( |
| 69 | found, |
| 70 | `Should find a diagnostic mentioning nonExistentProp. Available diagnostics: ${diagnostics.map((d) => d.message).join(', ')}`, |
| 71 | ); |
| 72 |
nothing calls this directly
no test coverage detected