Skip to content

Commit 03a19f5

Browse files
committed
Merge branch 'topic/vscode-test-infra' into 'master'
Refactor the way VS Code tests are launched Closes #1284 See merge request eng/ide/ada_language_server!1487
2 parents 6a24b8e + 96382ad commit 03a19f5

File tree

2 files changed

+56
-40
lines changed

2 files changed

+56
-40
lines changed

integration/vscode/ada/test/runTest.ts

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import os from 'os';
33

44
import { runTests } from '@vscode/test-electron';
55
import { TestOptions } from '@vscode/test-electron/out/runTest';
6+
import { mkdtemp } from 'fs';
67

78
async function main() {
89
// The folder containing the Extension Manifest package.json
@@ -28,37 +29,52 @@ async function main() {
2829
`test/workspaces/${testsuite}`
2930
);
3031

31-
const testOptions: TestOptions = {
32-
extensionDevelopmentPath,
33-
extensionTestsPath,
34-
// --user-data-dir is set to the OS default directory for temporary files to avoid
35-
// warnings related to longs paths in IPC sockets created by VSCode.
36-
launchArgs: ['--user-data-dir', `${os.tmpdir()}`, testWorkspace],
37-
};
38-
if (process.env.VSCODE) {
39-
// If specified, use the VSCode executable provided externally. This
40-
// can be use to test with an externally installed VS Code version
41-
// such as in a CI environment for example.
42-
//
43-
// The expected value is the path to <install-dir>/code and not
44-
// <install-dir>/bin/code.
45-
testOptions.vscodeExecutablePath = process.env.VSCODE;
46-
} else {
47-
// Otherwise download the latest stable version and test using that.
48-
testOptions.version = 'stable';
49-
}
32+
await new Promise<void>((resolve) => {
33+
mkdtemp(`${os.tmpdir()}/vsc-ada-test-`, (err, folder) => {
34+
if (err) throw err;
35+
36+
const testOptions: TestOptions = {
37+
extensionDevelopmentPath: extensionDevelopmentPath,
38+
extensionTestsPath: extensionTestsPath,
39+
// --user-data-dir is set to a unique dirctory under the OS
40+
// default tmp directory for temporary files to avoid
41+
// warnings related to longs paths in IPC sockets created by
42+
// VSCode. The directory is made unique to avoid
43+
// interference between successive runs.
44+
launchArgs: ['--user-data-dir', folder, testWorkspace],
45+
};
46+
if (process.env.VSCODE) {
47+
// If specified, use the VSCode executable provided externally. This
48+
// can be use to test with an externally installed VS Code version
49+
// such as in a CI environment for example.
50+
//
51+
// The expected value is the path to <install-dir>/code and not
52+
// <install-dir>/bin/code.
53+
testOptions.vscodeExecutablePath = process.env.VSCODE;
54+
} else {
55+
// Otherwise download the latest stable version and test using that.
56+
testOptions.version = 'stable';
57+
}
5058

51-
// Catch any errors running this testsuite, but continue running the remaining ones.
52-
try {
53-
// Download and unzip VS Code (if it has not been done before), and run this testsuite.
54-
await runTests(testOptions);
55-
} catch (err) {
56-
console.error(err);
57-
console.error(`Failed to run ${testsuite} testsuite`);
58-
// If this testsuite failed, flag it so that we can exit with a non zero error code
59-
// later.
60-
someTestsuiteFailed = true;
61-
}
59+
console.info('Calling runTests with: ' + JSON.stringify(testOptions, undefined, 2));
60+
// Download and unzip VS Code (if it has not been done before),
61+
// and run this testsuite.
62+
runTests(testOptions)
63+
.then(() => {
64+
resolve();
65+
})
66+
.catch((err) => {
67+
// Catch any errors running this testsuite, to continue
68+
// running the remaining testsuites.
69+
console.error(err);
70+
console.error(`Failed to run ${testsuite} testsuite`);
71+
// If this testsuite failed, flag it so that we can exit
72+
// with a non zero error code later.
73+
someTestsuiteFailed = true;
74+
resolve();
75+
});
76+
});
77+
});
6278
}
6379

6480
if (someTestsuiteFailed) {

integration/vscode/ada/test/suite/utils.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as vscode from 'vscode';
21
import assert from 'assert';
3-
import { env } from 'process';
4-
import path, { resolve } from 'path';
5-
import Mocha, { MochaOptions } from 'mocha';
6-
import { Glob, GlobOptionsWithFileTypesUnset } from 'glob';
72
import { existsSync, readFileSync, writeFileSync } from 'fs';
3+
import { Glob, GlobOptionsWithFileTypesUnset } from 'glob';
4+
import Mocha, { MochaOptions } from 'mocha';
5+
import path from 'path';
6+
import { env } from 'process';
7+
import * as vscode from 'vscode';
88

99
/**
1010
* This function compares some actual output to an expected referenced stored in
@@ -89,11 +89,11 @@ export function runMochaTestsuite(suiteName: string, suiteDirectory: string) {
8989
// Create the mocha test
9090
const mocha = new Mocha(mochaOptions);
9191

92-
return new Promise<void>((c, e) => {
92+
return new Promise<void>((resolve, reject) => {
9393
const globOptions: GlobOptionsWithFileTypesUnset = { cwd: suiteDirectory };
9494
const glob = new Glob('**/*.test.js', globOptions);
9595
for (const file of glob) {
96-
mocha.addFile(resolve(suiteDirectory, file));
96+
mocha.addFile(path.resolve(suiteDirectory, file));
9797
}
9898
try {
9999
// This variable is set in the launch configuration (launch.json) of
@@ -110,13 +110,13 @@ export function runMochaTestsuite(suiteName: string, suiteDirectory: string) {
110110
// Run the mocha test
111111
mocha.run((failures) => {
112112
if (failures > 0) {
113-
e(new Error(`${failures} tests failed.`));
113+
reject(new Error(`${failures} tests failed.`));
114114
} else {
115-
c();
115+
resolve();
116116
}
117117
});
118118
} catch (err) {
119-
e(err);
119+
reject(err);
120120
}
121121
});
122122
}

0 commit comments

Comments
 (0)