Skip to content

Commit b221114

Browse files
committed
Switches to @types/vscode & @vscode/test-electron
Also updates the tests to use strictEqual Adds production, test and dev tscofig compilation Fixes Migrate from vscode module #263
1 parent 801c7f3 commit b221114

9 files changed

+137
-51
lines changed

package.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,31 @@
207207
},
208208
"scripts": {
209209
"vscode:prepublish": "npm run compile",
210-
"compile": "tsc -p ./",
211-
"watch": "tsc -watch -p ./",
212-
"postinstall": "node ./node_modules/vscode/bin/install",
213-
"test": "CODE_TESTS_WORKSPACE='./' node ./node_modules/vscode/bin/test",
210+
"compile": "tsc -p tsconfig.prod.json",
211+
"compile-dev": "tsc -p tsconfig.json",
212+
"watch": "tsc -watch -p tsconfig.prod.json",
213+
"watch-dev": "tsc -watch -p tsconfig.json",
214+
"pretest": "tsc -p tsconfig.test.json",
215+
"test": "node ./out/test/runTest.js",
214216
"test:grammar-free": "vscode-tmgrammar-snap -s source.fortran.free -g ./syntaxes/fortran_free-form.tmLanguage.json -t \"./test/**/*{.f90,F90}\"",
215217
"test:grammar-fixed": "vscode-tmgrammar-snap -s source.fortran.fixed -g ./syntaxes/fortran_fixed-form.tmLanguage.json -t \"./test/**/*{.f,F}\"",
216218
"test:grammar": "npm run test:grammar-free && npm run test:grammar-fixed",
217219
"test:grammar-update": "npm run test:grammar -- -u",
218220
"lint": "node ./node_modules/tslint/bin/tslint ./src/**/*.ts "
219221
},
220222
"devDependencies": {
221-
"@types/mocha": "^2.2.32",
222-
"@types/node": "^15.12.1",
223-
"husky": "^1.1.2",
224-
"lint-staged": "^7.3.0",
225-
"mocha": "^9.0.1",
223+
"@types/glob": "^7.1.4",
224+
"@types/mocha": "^9.0.0",
225+
"@types/node": "^15.14.9",
226+
"@types/vscode": "^1.30.0",
227+
"@types/which": "^2.0.1",
228+
"@vscode/test-electron": "^1.6.2",
229+
"glob": "^7.2.0",
230+
"husky": "^7.0.2",
231+
"lint-staged": "^11.2.3",
232+
"mocha": "^9.1.3",
226233
"tslint": "^5.20.1",
227-
"typescript": "^3.5.1",
228-
"vscode": "^1.1.37",
234+
"typescript": "^3.9.10",
229235
"vscode-tmgrammar-test": "^0.0.11"
230236
},
231237
"husky": {

test/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ suite("Extension Tests", () => {
2121
vscode.window.showTextDocument(doc);
2222
const symbolProvider = new FortranDocumentSymbolProvider();
2323
const symbols = await symbolProvider.provideDocumentSymbols(doc, null);
24-
assert.equal(symbols.length, 1);
24+
assert.strictEqual(symbols.length, 1);
2525
});
2626
});

test/helper.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,46 @@ import {
1414

1515
suite("function helper test", () => {
1616
test("validVariableName does not allow variables starting with number", () => {
17-
assert.equal(false, validVariableName("1as"));
17+
assert.strictEqual(false, validVariableName("1as"));
1818
});
1919

2020
test("validVariableName returns true with correct variable", () => {
21-
assert.equal(true, validVariableName("matA"));
21+
assert.strictEqual(true, validVariableName("matA"));
2222
});
2323

2424
test("validVariableName returns true for variables starting with uppercase", () => {
25-
assert.equal(true, validVariableName("MatA"));
25+
assert.strictEqual(true, validVariableName("MatA"));
2626
});
2727

2828
test("validVariableName return true for variable starting with _", () => {
29-
assert.equal(true, validVariableName("_matA"));
29+
assert.strictEqual(true, validVariableName("_matA"));
3030
});
3131

3232
test("parseFuntion return undefined on empty line", () => {
33-
// assert.equal(undefined, parseFunction({text: ""}));
33+
// assert.strictEqual(undefined, parseFunction({text: ""}));
3434
});
3535

3636
test("parseFuntion return undefined if function keyword is missing", () => {
37-
// assert.equal(undefined, parseFunction({"hello"));
37+
// assert.strictEqual(undefined, parseFunction({"hello"));
3838
});
3939

4040
test("parseFuntion return correct function name", () => {
41-
// assert.equal("hello", parseFunction("function hello()").name);
41+
// assert.strictEqual("hello", parseFunction("function hello()").name);
4242
});
4343

4444
test("parseFuntion return correct number of args", () => {
45-
// assert.equal(2, parseFunction("function hello( a, b)").args.length);
45+
// assert.strictEqual(2, parseFunction("function hello( a, b)").args.length);
4646
});
4747

4848
test("parseArgs return the correct number of args", () => {
49-
assert.equal(2, parseArgs("a,b").length);
49+
assert.strictEqual(2, parseArgs("a,b").length);
5050
});
5151

5252
test("parseArgs handle spaces well", () => {
53-
assert.equal(2, parseArgs(" a, b").length);
53+
assert.strictEqual(2, parseArgs(" a, b").length);
5454
});
5555

5656
test("parseArgs handle empty args", () => {
57-
assert.equal(0, parseArgs("").length);
57+
assert.strictEqual(0, parseArgs("").length);
5858
});
5959
});

test/index.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
2-
// Licensed under the MIT license. See LICENSE file in the project root for details.
1+
import * as path from 'path';
2+
import * as Mocha from 'mocha';
3+
import * as glob from 'glob';
34

4-
// This file is used by VS Code's default test runner to configure Mocha before the test run.
5+
export function run(): Promise<void> {
6+
// Create the mocha test
7+
const mocha = new Mocha({
8+
ui: 'tdd',
9+
color: true
10+
});
511

6-
/* tslint:disable:no-var-keyword no-var-requires */
7-
var testRunner = require("vscode/lib/testrunner");
8-
/* tslint:enable:no-var-keyword no-var-requires */
12+
const testsRoot = __dirname;
913

10-
let mochaOptions: any = {
11-
ui: "tdd",
12-
useColors: true,
13-
invert: true,
14-
grep: "debuggerContext" // Do not run tests intended for the debuggerContext
15-
};
14+
return new Promise((c, e) => {
15+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16+
if (err) {
17+
return e(err);
18+
}
1619

17-
// Look for the env variable to decide wheter to use the TeamCity reporter or not
18-
if (process.env.VSCODE_REACT_NATIVE_TEAMCITY_TEST) {
19-
mochaOptions.reporter = "mocha-teamcity-reporter";
20-
}
21-
22-
// Register Mocha options
23-
testRunner.configure(mochaOptions);
20+
// Add files to the test suite
21+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
2422

25-
module.exports = testRunner;
23+
try {
24+
// Run the mocha test
25+
mocha.timeout(100000);
26+
mocha.run(failures => {
27+
if (failures > 0) {
28+
e(new Error(`${failures} tests failed.`));
29+
} else {
30+
c();
31+
}
32+
});
33+
} catch (err) {
34+
e(err);
35+
}
36+
});
37+
});
38+
}

test/runTest.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from '@vscode/test-electron';
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 runner script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './index');
14+
15+
const launchArgs = ["--disable-extensions", "--install-extension ms-vscode.cpptools"];
16+
// Download VS Code, unzip it and run the integration test
17+
await runTests({ launchArgs, extensionDevelopmentPath, extensionTestsPath });
18+
} catch (err) {
19+
console.error(err);
20+
console.error('Failed to run tests');
21+
process.exit(1);
22+
}
23+
}
24+
25+
main();

test/tokenizer.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { Tokenizer, TokenType } from '../src/lib/tokenizer';
66

77
suite("fortran tokenizer", () => {
88

9-
test("get correct amount of tokens", () => {
10-
const fortranTokenizer = constructFortranTokenizer();
11-
fortranTokenizer.tokenize("function a( m, n)\n 2 + 3\nend");
12-
let tokens = fortranTokenizer.tokens;
13-
assert.equal(tokens.length, 11);
14-
});
9+
test("get correct amount of tokens", () => {
10+
const fortranTokenizer = constructFortranTokenizer();
11+
fortranTokenizer.tokenize("function a( m, n)\n 2 + 3\nend");
12+
let tokens = fortranTokenizer.tokens;
13+
assert.strictEqual(tokens.length, 11);
14+
});
1515
});
1616

1717
function constructFortranTokenizer() {
@@ -28,4 +28,4 @@ function constructFortranTokenizer() {
2828
tokenizer.add(/^,\s*/, TokenType.COMMA); // comma separator
2929
tokenizer.add(/[+\-*\/]\s*/, TokenType.BINARY_OPERATOR); // operators
3030
return tokenizer;
31-
}
31+
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"include": [
1414
"src/**/*.ts",
1515
"src/docs/**/*.json",
16-
"test/**/*.ts"
1716
],
1817
"exclude": [
1918
"node_modules",

tsconfig.prod.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"outDir": "out",
6+
"lib": [
7+
"es6"
8+
],
9+
"sourceMap": false,
10+
"removeComments": true,
11+
"rootDir": ".",
12+
"resolveJsonModule": true
13+
},
14+
"include": [
15+
"src/**/*.ts",
16+
"src/docs/**/*.json",
17+
],
18+
"exclude": [
19+
"node_modules",
20+
".vscode-test"
21+
]
22+
}

tsconfig.test.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"outDir": "out",
6+
"lib": [
7+
"es6"
8+
],
9+
"sourceMap": true,
10+
"rootDir": ".",
11+
"resolveJsonModule": true
12+
},
13+
"include": [
14+
"test/**/*.ts",
15+
"syntaxes/*.json",
16+
],
17+
"exclude": [
18+
"node_modules",
19+
".vscode-test"
20+
]
21+
}

0 commit comments

Comments
 (0)