Skip to content

Commit 7bad2ec

Browse files
committed
test: quality of life updates for e2e tests
- update vscode version - use __dirname for resolving test file locations to be more fault tolerant of potential errors in directory resolution - wait for definitions to be available during activation rather than waiting a set time
1 parent a4f1eb9 commit 7bad2ec

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

integration/e2e/definition_spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import * as vscode from 'vscode';
2+
23
import {APP_COMPONENT} from '../test_constants';
3-
import {activate} from './helper';
44

5-
const DEFINITION_COMMAND = 'vscode.executeDefinitionProvider';
6-
const APP_COMPONENT_URI = vscode.Uri.file(APP_COMPONENT);
5+
import {activate, APP_COMPONENT_URI, DEFINITION_COMMAND} from './helper';
76

87
describe('Angular Ivy LS', () => {
98
beforeAll(async () => {
109
await activate(APP_COMPONENT_URI);
11-
}, 25000 /* 25 seconds */);
10+
});
1211

1312
it(`returns definition for variable in template`, async () => {
1413
// vscode Position is zero-based

integration/e2e/helper.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import * as vscode from 'vscode';
2+
import {APP_COMPONENT} from '../test_constants';
3+
4+
export const DEFINITION_COMMAND = 'vscode.executeDefinitionProvider';
5+
export const APP_COMPONENT_URI = vscode.Uri.file(APP_COMPONENT);
26

37
function sleep(ms: number) {
48
return new Promise(resolve => setTimeout(resolve, ms));
59
}
610

7-
export async function activate(uri: vscode.Uri) {
11+
export async function activate(uri: vscode.Uri, timeoutSeconds = 20) {
12+
await waitForAngularDefinitions(timeoutSeconds);
813
await vscode.window.showTextDocument(uri);
9-
await sleep(20 * 1000); // Wait for server activation, including ngcc run
14+
}
15+
16+
async function waitForAngularDefinitions(timeoutSeconds: number) {
17+
await vscode.window.showTextDocument(APP_COMPONENT_URI);
18+
// template: `<h1>Hello {{name}}</h1>`,
19+
// ^-------- here
20+
const position = new vscode.Position(4, 25);
21+
let tries = 0;
22+
let definitions: vscode.LocationLink[]|undefined;
23+
while ((definitions?.length ?? 0) < 1 && tries < timeoutSeconds) {
24+
definitions = await vscode.commands.executeCommand<vscode.LocationLink[]>(
25+
DEFINITION_COMMAND, APP_COMPONENT_URI, position);
26+
await sleep(1000);
27+
tries++;
28+
}
29+
if (definitions === undefined || definitions.length === 0) {
30+
fail('Waiting for Angular definitions to be available timed out.');
31+
}
1032
}

integration/e2e/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function main() {
99
try {
1010
await runTests({
1111
// Keep version in sync with vscode engine version in package.json
12-
version: '1.56.0',
12+
version: '1.56.2',
1313
extensionDevelopmentPath: EXT_DEVELOPMENT_PATH,
1414
extensionTestsPath: EXT_TESTS_PATH,
1515
launchArgs: [

integration/e2e/jasmine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ export async function run(): Promise<void> {
44
const jasmine = new Jasmine({});
55

66
jasmine.loadConfig({
7-
spec_dir: 'dist/integration/e2e',
7+
spec_dir: __dirname,
88
spec_files: [
99
'*_spec.js',
1010
],
1111
});
1212

13+
console.log(`Expecting to run ${jasmine.specFiles.length} specs.`);
14+
1315
if (jasmine.specFiles.length === 0) {
1416
throw new Error('No specs found');
1517
}

0 commit comments

Comments
 (0)