Skip to content

Commit 6f36e72

Browse files
committed
Update test runner as necessary
1 parent 407c166 commit 6f36e72

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

test/testRunner.ts renamed to test/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import * as glob from "glob";
5-
import * as Mocha from "mocha";
4+
// NOTE: This code is borrowed under permission from:
5+
// https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample/src/test
6+
67
import * as path from "path";
8+
import * as Mocha from "mocha";
9+
import * as glob from "glob";
710

811
export function run(): Promise<void> {
912
// Create the mocha test
1013
const mocha = new Mocha({
11-
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
14+
ui: "tdd",
1215
color: !process.env.TF_BUILD, // colored output from test results
1316
reporter: "mocha-multi-reporters",
1417
timeout: 5000,
@@ -23,24 +26,26 @@ export function run(): Promise<void> {
2326
const testsRoot = path.resolve(__dirname, "..");
2427

2528
return new Promise((c, e) => {
26-
glob("**/**.test.js", { cwd: testsRoot }, (err: any, files: any[]) => {
29+
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
2730
if (err) {
2831
return e(err);
2932
}
3033

3134
// Add files to the test suite
32-
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
35+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
3336

3437
try {
3538
// Run the mocha test
36-
mocha.run((failures) => {
39+
mocha.run(failures => {
3740
if (failures > 0) {
3841
e(new Error(`${failures} tests failed.`));
3942
} else {
4043
c();
4144
}
4245
});
4346
} catch (err) {
47+
// tslint:disable-next-line:no-console
48+
console.error(err);
4449
e(err);
4550
}
4651
});

test/runTests.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import * as path from "path";
4+
// NOTE: This code is borrowed under permission from:
5+
// https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample/src/test
56

6-
import { runTests } from "vscode-test";
7+
import * as path from "path";
78

8-
// tslint:disable-next-line: no-var-requires
9-
const PackageJSON: any = require("../../package.json");
10-
const testExtensionId = `${PackageJSON.publisher}.${PackageJSON.name}`;
9+
import { runTests } from "@vscode/test-electron";
1110

1211
async function main() {
1312
try {
1413
// The folder containing the Extension Manifest package.json
1514
// Passed to `--extensionDevelopmentPath`
1615
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
1716

18-
// The path to the extension test runner script
17+
// The path to the extension test script
1918
// Passed to --extensionTestsPath
20-
const extensionTestsPath = path.resolve(__dirname, "./testRunner");
19+
const extensionTestsPath = path.resolve(__dirname, "./index");
2120

22-
// Download VS Code, unzip it and run the integration test from the local directory.
21+
// Download VS Code, unzip it and run the integration test
2322
await runTests({
2423
extensionDevelopmentPath,
2524
extensionTestsPath,
26-
launchArgs: [
27-
"--disable-extensions",
28-
"--enable-proposed-api", testExtensionId,
29-
"./test"
30-
],
25+
launchArgs: ["--disable-extensions", "./test"],
26+
// This is necessary because the tests fail if more than once
27+
// instance of Code is running.
3128
version: "insiders"
3229
});
3330
} catch (err) {
34-
// tslint:disable-next-line:no-console
35-
console.error(err);
3631
// tslint:disable-next-line:no-console
3732
console.error("Failed to run tests");
3833
process.exit(1);

0 commit comments

Comments
 (0)