MCPcopy Create free account
hub / github.com/angular/angular / run

Function run

ngp-vscode-ng-language-service/e2e/src/diagnostics_ext.ts:15–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import {waitFor} from './utils';
14
15export 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

Callers

nothing calls this directly

Calls 12

waitForFunction · 0.90
setTimeoutFunction · 0.85
okMethod · 0.80
mapMethod · 0.80
rmMethod · 0.80
joinMethod · 0.65
logMethod · 0.65
writeFileMethod · 0.65
getDiagnosticsMethod · 0.65
fileMethod · 0.45
allMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected