Skip to content

Commit cf1fbe1

Browse files
akaromlfbricon
authored andcommitted
Migrate to 'vscode-test' (#981)
Signed-off-by: Rome Li <rome.li@microsoft.com>
1 parent 89d3921 commit cf1fbe1

7 files changed

Lines changed: 88 additions & 70 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
5050
"stopOnEntry": false,
5151
"sourceMaps": true,
52-
"outFiles": ["${workspaceRoot}/out/test/**"],
52+
"outFiles": ["${workspaceRoot}/out/**/*.js"],
5353
"preLaunchTask": "npm: compile"
5454
}
5555
]
56-
}
56+
}

package-lock.json

Lines changed: 9 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"preview": true,
1212
"enableProposedApi": false,
1313
"engines": {
14-
"vscode": "^1.33.0"
14+
"vscode": "^1.36.0"
1515
},
1616
"repository": {
1717
"type": "git",
@@ -500,18 +500,18 @@
500500
},
501501
"scripts": {
502502
"vscode:prepublish": "webpack --mode production",
503-
"compile": "tsc -p ./",
503+
"compile": "tsc -p ./&webpack --mode development",
504504
"watch": "webpack --mode development --watch --info-verbosity verbose",
505-
"postinstall": "node ./node_modules/vscode/bin/install",
506-
"test": "node ./node_modules/vscode/bin/test",
505+
"pretest": "npm run compile",
506+
"test": "node ./out/test/runtest.js",
507507
"build-server": "./node_modules/.bin/gulp build_server",
508-
"watch-server": "./node_modules/.bin/gulp watch_server",
509-
"webpack": "webpack --mode development"
508+
"watch-server": "./node_modules/.bin/gulp watch_server"
510509
},
511510
"devDependencies": {
512511
"@types/glob": "5.0.30",
513512
"@types/mocha": "^5.2.5",
514513
"@types/node": "^6.0.40",
514+
"@types/vscode": "^1.36.0",
515515
"gulp": "^4.0.0",
516516
"gulp-decompress": "2.0.1",
517517
"gulp-download": "0.0.1",
@@ -520,7 +520,7 @@
520520
"tslint": "^5.11.0",
521521
"typescript": "^3.4.1",
522522
"typescript-tslint-plugin": "^0.3.1",
523-
"vscode": "^1.1.35",
523+
"vscode-test": "^1.0.0",
524524
"webpack": "^4.27.1",
525525
"webpack-cli": "^3.1.2"
526526
},

src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Commands } from './commands';
66

77
let existingExtensions: Array<string>;
88

9-
export function collectJavaExtensions(extensions: vscode.Extension<any>[]): string[] {
9+
export function collectJavaExtensions(extensions: readonly vscode.Extension<any>[]): string[] {
1010
const result = [];
1111
if (extensions && extensions.length) {
1212
for (const extension of extensions) {
@@ -26,7 +26,7 @@ export function collectJavaExtensions(extensions: vscode.Extension<any>[]): stri
2626
return result;
2727
}
2828

29-
export function onExtensionChange(extensions: vscode.Extension<any>[]) {
29+
export function onExtensionChange(extensions: readonly vscode.Extension<any>[]) {
3030
if (!existingExtensions) {
3131
return;
3232
}

test/extension.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite('Java Language Extension', () => {
2020
});
2121
});
2222

23-
test('should register all java commands', function () {
23+
test('should register all java commands', () => {
2424
return vscode.commands.getCommands(true).then((commands) =>
2525
{
2626
const JAVA_COMMANDS = [
@@ -53,14 +53,14 @@ suite('Java Language Extension', () => {
5353
Commands.APPLY_REFACTORING_COMMAND,
5454
Commands.RENAME_COMMAND
5555
];
56-
const foundJavaCommands = commands.filter(function(value) {
56+
const foundJavaCommands = commands.filter((value) => {
5757
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');
5858
});
5959
assert.equal(foundJavaCommands.length , JAVA_COMMANDS.length, 'Some Java commands are not registered properly or a new command is not added to the test');
6060
});
6161
});
6262

63-
test('should parse VM arguments', function () {
63+
test('should parse VM arguments', () => {
6464
const userArgs = '-Xmx512m -noverify -Dfoo=\"something with blank\" ';
6565
const vmArgs = ['-noverify', 'foo'];
6666

@@ -73,7 +73,7 @@ suite('Java Language Extension', () => {
7373
assert.equal('-Dfoo=something with blank', vmArgs[3]);
7474
});
7575

76-
test('should parse VM arguments with spaces', function () {
76+
test('should parse VM arguments with spaces', () => {
7777
const userArgs = '-javaagent:"C:\\Program Files\\Java\\lombok.jar" -Xbootclasspath/a:"C:\\Program Files\\Java\\lombok.jar" -Dfoo="Some \\"crazy\\" stuff"';
7878
const vmArgs = [];
7979

@@ -85,15 +85,16 @@ suite('Java Language Extension', () => {
8585
assert.equal(vmArgs[2], '-Dfoo=Some "crazy" stuff');
8686
});
8787

88-
test('should collect java extensions', function () {
88+
test('should collect java extensions', () => {
8989
const packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, '../../test/resources/packageExample.json'), 'utf8'));
9090
const fakedExtension = {
9191
id: 'test',
9292
extensionPath: '',
9393
isActive: true,
9494
packageJSON,
9595
exports: '',
96-
activate: null
96+
activate: null,
97+
extensionKind: vscode.ExtensionKind.Workspace
9798
};
9899

99100
const extensions = [fakedExtension];
@@ -102,7 +103,7 @@ suite('Java Language Extension', () => {
102103
assert(result[0].endsWith(path.normalize('./bin/java.extend.jar')));
103104
});
104105

105-
test('should parse Java version', function () {
106+
test('should parse Java version', () => {
106107
// Test boundaries
107108
assert.equal(requirements.parseMajorVersion(null), 0);
108109
assert.equal(requirements.parseMajorVersion(''), 0);

test/index.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,48 @@
1-
//
2-
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
1+
//
2+
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
33
//
44
// This file is providing the test runner to use when running extension tests.
55
// By default the test runner in use is Mocha based.
6-
//
6+
//
77
// You can provide your own test runner if you want to override it by exporting
88
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
99
// host can call to run the tests. The test runner is expected to use console.log
1010
// to report the results back to the caller. When the tests are finished, return
1111
// a possible error to the callback or null if none.
1212

13-
// tslint:disable-next-line:no-require-imports
14-
let testRunner = require('vscode/lib/testrunner');
13+
import * as path from 'path';
14+
import * as Mocha from 'mocha';
15+
import * as glob from 'glob';
16+
17+
export function run(): Promise<void> {
18+
const mocha = new Mocha({
19+
ui: 'tdd',
20+
useColors: true
21+
});
22+
23+
const testsRoot = path.resolve(__dirname, '..');
24+
25+
return new Promise((c, e) => {
26+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
27+
if (err) {
28+
return e(err);
29+
}
1530

16-
// You can directly control Mocha options by uncommenting the following lines
17-
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
18-
testRunner.configure({
19-
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
20-
useColors: true // colored output from test results
21-
});
31+
// Add files to the test suite
32+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
2233

23-
module.exports = testRunner;
34+
try {
35+
// Run the mocha test
36+
mocha.run(failures => {
37+
if (failures > 0) {
38+
e(new Error(`${failures} tests failed.`));
39+
} else {
40+
c();
41+
}
42+
});
43+
} catch (err) {
44+
e(err);
45+
}
46+
});
47+
});
48+
}

test/runtest.ts

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 extensionDevelopmentPath = path.resolve(__dirname, '../..');
10+
11+
// The path to the extension test script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();

0 commit comments

Comments
 (0)