Skip to content

Commit 2bee60b

Browse files
authored
Merge pull request #170 from microsoft/octref/vscode-test
Update vscode-test & @types/vscode usage for microsoft/vscode#71048
2 parents 54de9fa + df8f14f commit 2bee60b

14 files changed

Lines changed: 193 additions & 123 deletions

File tree

generators/app/templates/ext-command-js/package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
}]
2121
},
2222
"scripts": {
23-
"postinstall": "node ./node_modules/vscode/bin/install",
24-
"test": "node ./node_modules/vscode/bin/test"
23+
"test": "node ./test/runTest.js"
2524
},
2625
"devDependencies": {
27-
"typescript": "^3.3.1",
28-
"vscode": "^1.1.28",
29-
"eslint": "^5.13.0",
26+
"@types/glob": "^7.1.1",
27+
"@types/mocha": "^5.2.6",
3028
"@types/node": "^10.12.21",
31-
"@types/mocha": "^2.2.42"
29+
"@types/vscode": "^1.32.0",
30+
"eslint": "^5.13.0",
31+
"glob": "^7.1.4",
32+
"mocha": "^6.1.4",
33+
"typescript": "^3.3.1",
34+
"vscode-test": "^0.4.2"
3235
}
3336
}

generators/app/templates/ext-command-js/test/extension.test.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

generators/app/templates/ext-command-js/test/index.js

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path');
2+
3+
const { runTests } = require('vscode-test');
4+
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionPath = path.resolve(__dirname, '../../');
10+
11+
// The path to test runner
12+
// Passed to --extensionTestsPath
13+
const testRunnerPath = path.resolve(__dirname, './suite');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionPath, testRunnerPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const assert = require('assert');
2+
const { before } = require('mocha');
3+
4+
// You can import and use all API from the 'vscode' module
5+
// as well as import your extension to test it
6+
const vscode = require('vscode');
7+
// const myExtension = require('../extension');
8+
9+
suite('Extension Test Suite', () => {
10+
before(() => {
11+
vscode.window.showInformationMessage('Start all tests.');
12+
});
13+
14+
test('Sample test', () => {
15+
assert.equal(-1, [1, 2, 3].indexOf(5));
16+
assert.equal(-1, [1, 2, 3].indexOf(0));
17+
});
18+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path');
2+
const Mocha = require('mocha');
3+
const glob = require('glob');
4+
5+
function run(testsRoot, cb) {
6+
// Create the mocha test
7+
const mocha = new Mocha({
8+
ui: 'tdd'
9+
});
10+
// Use any mocha API
11+
mocha.useColors(true);
12+
13+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
14+
if (err) {
15+
return cb(err);
16+
}
17+
18+
// Add files to the test suite
19+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
20+
21+
try {
22+
// Run the mocha test
23+
mocha.run(failures => cb(null, failures));
24+
} catch (err) {
25+
cb(err);
26+
}
27+
});
28+
}
29+
30+
module.exports = {
31+
run
32+
};

generators/app/templates/ext-command-ts/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
"vscode:prepublish": "<%= pkgManager %> run compile",
2424
"compile": "tsc -p ./",
2525
"watch": "tsc -watch -p ./",
26-
"postinstall": "node ./node_modules/vscode/bin/install",
27-
"test": "<%= pkgManager %> run compile && node ./node_modules/vscode/bin/test"
26+
"test": "<%= pkgManager %> run compile && node ./out/test/runTest.js"
2827
},
2928
"devDependencies": {
29+
"@types/glob": "^7.1.1",
30+
"@types/mocha": "^5.2.6",
31+
"@types/node": "^10.12.21",
32+
"@types/vscode": "^1.32.0",
33+
"glob": "^7.1.4",
34+
"mocha": "^6.1.4",
3035
"typescript": "^3.3.1",
31-
"vscode": "^1.1.28",
3236
"tslint": "^5.12.1",
33-
"@types/node": "^10.12.21",
34-
"@types/mocha": "^2.2.42"
37+
"vscode-test": "^0.4.2"
3538
}
3639
}

generators/app/templates/ext-command-ts/src/test/extension.test.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

generators/app/templates/ext-command-ts/src/test/index.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from 'vscode-test';
4+
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionPath = path.resolve(__dirname, '../../');
10+
11+
// The path to test runner
12+
// Passed to --extensionTestsPath
13+
const testRunnerPath = path.resolve(__dirname, './suite');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionPath, testRunnerPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();

0 commit comments

Comments
 (0)