| 12 | import {waitFor} from './utils'; |
| 13 | |
| 14 | export async function run() { |
| 15 | console.log('Running TCB tests...'); |
| 16 | |
| 17 | const workspaceRoot = vscode.workspace.workspaceFolders?.[0].uri.fsPath; |
| 18 | if (!workspaceRoot) { |
| 19 | throw new Error('No workspace folder found'); |
| 20 | } |
| 21 | |
| 22 | const appComponentUri = vscode.Uri.file(path.join(workspaceRoot, 'app.ts')); |
| 23 | const document = await vscode.workspace.openTextDocument(appComponentUri); |
| 24 | const editor = await vscode.window.showTextDocument(document); |
| 25 | |
| 26 | // Position inside the template (e.g., inside 'track $index' or 'name') |
| 27 | // Line 34 is @for... let's use line 33 (0-indexed) for $index |
| 28 | const position = new vscode.Position(33, 20); // $index |
| 29 | editor.selection = new vscode.Selection(position, position); |
| 30 | |
| 31 | console.log('Executing angular.getTemplateTcb command...'); |
| 32 | await vscode.commands.executeCommand('angular.getTemplateTcb'); |
| 33 | |
| 34 | console.log('Waiting for TCB document to open...'); |
| 35 | // Poll for the TCB document to open |
| 36 | const tcbEditor = await waitFor( |
| 37 | () => vscode.window.visibleTextEditors.find((e) => e.document.uri.scheme === 'ng'), |
| 38 | (editor) => !!editor, |
| 39 | ); |
| 40 | |
| 41 | assert.ok(tcbEditor, 'Expected a TCB editor to be open with scheme "ng"'); |
| 42 | |
| 43 | const content = tcbEditor.document.getText(); |
| 44 | assert.ok(content.length > 0, 'Expected TCB content to be non-empty'); |
| 45 | |
| 46 | // Strict assertions |
| 47 | assert.ok( |
| 48 | content.match(/function\s+.*AppComponent/), |
| 49 | 'Expected TCB to contain the component Type Check Function', |
| 50 | ); |
| 51 | assert.ok( |
| 52 | content.includes('.routes'), |
| 53 | 'Expected TCB to reference component properties used in the template (routes)', |
| 54 | ); |
| 55 | assert.ok( |
| 56 | content.includes('RouterLinkStub'), |
| 57 | 'Expected TCB to reference directive types used in the template (RouterLinkStub)', |
| 58 | ); |
| 59 | |
| 60 | console.log('TCB tests passed!'); |
| 61 | } |