aboutsummaryrefslogtreecommitdiff
path: root/editors/code/tests
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/tests')
-rw-r--r--editors/code/tests/runTests.ts43
-rw-r--r--editors/code/tests/unit/index.ts38
-rw-r--r--editors/code/tests/unit/launch_config.test.ts52
3 files changed, 133 insertions, 0 deletions
diff --git a/editors/code/tests/runTests.ts b/editors/code/tests/runTests.ts
new file mode 100644
index 000000000..22df80ad3
--- /dev/null
+++ b/editors/code/tests/runTests.ts
@@ -0,0 +1,43 @@
1import * as path from 'path';
2import * as fs from 'fs';
3
4import { runTests } from 'vscode-test';
5
6async function main() {
7 // The folder containing the Extension Manifest package.json
8 // Passed to `--extensionDevelopmentPath`
9 const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10
11 // Minimum supported version.
12 const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json'));
13 const json = JSON.parse(jsonData.toString());
14 let minimalVersion: string = json.engines.vscode;
15 if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1);
16
17 const launchArgs = ["--disable-extensions"];
18
19 // All test suites (either unit tests or integration tests) should be in subfolders.
20 const extensionTestsPath = path.resolve(__dirname, './unit/index');
21
22 // Run tests using the minimal supported version.
23 await runTests({
24 version: minimalVersion,
25 launchArgs,
26 extensionDevelopmentPath,
27 extensionTestsPath
28 });
29
30 // and the latest one
31 await runTests({
32 version: 'stable',
33 launchArgs,
34 extensionDevelopmentPath,
35 extensionTestsPath
36 });
37}
38
39main().catch(err => {
40 // eslint-disable-next-line no-console
41 console.error('Failed to run tests', err);
42 process.exit(1);
43});
diff --git a/editors/code/tests/unit/index.ts b/editors/code/tests/unit/index.ts
new file mode 100644
index 000000000..5165720b4
--- /dev/null
+++ b/editors/code/tests/unit/index.ts
@@ -0,0 +1,38 @@
1import * as path from 'path';
2import Mocha from 'mocha';
3import glob from 'glob';
4
5export function run(): Promise<void> {
6 // Create the mocha test
7 const mocha = new Mocha({
8 ui: 'tdd',
9 color: true
10 });
11
12 const testsRoot = __dirname;
13
14 return new Promise((resolve, reject) => {
15 glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16 if (err) {
17 return reject(err);
18 }
19
20 // Add files to the test suite
21 files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22
23 try {
24 // Run the mocha test
25 mocha.timeout(100000);
26 mocha.run(failures => {
27 if (failures > 0) {
28 reject(new Error(`${failures} tests failed.`));
29 } else {
30 resolve();
31 }
32 });
33 } catch (err) {
34 reject(err);
35 }
36 });
37 });
38}
diff --git a/editors/code/tests/unit/launch_config.test.ts b/editors/code/tests/unit/launch_config.test.ts
new file mode 100644
index 000000000..d5cf1b74e
--- /dev/null
+++ b/editors/code/tests/unit/launch_config.test.ts
@@ -0,0 +1,52 @@
1import * as assert from 'assert';
2import * as cargo from '../../src/cargo';
3
4suite('Launch configuration', () => {
5
6 suite('Lens', () => {
7 test('A binary', async () => {
8 const args = cargo.artifactSpec(["build", "--package", "pkg_name", "--bin", "pkg_name"]);
9
10 assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "pkg_name", "--message-format=json"]);
11 assert.deepEqual(args.filter, undefined);
12 });
13
14 test('One of Multiple Binaries', async () => {
15 const args = cargo.artifactSpec(["build", "--package", "pkg_name", "--bin", "bin1"]);
16
17 assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "bin1", "--message-format=json"]);
18 assert.deepEqual(args.filter, undefined);
19 });
20
21 test('A test', async () => {
22 const args = cargo.artifactSpec(["test", "--package", "pkg_name", "--lib", "--no-run"]);
23
24 assert.deepEqual(args.cargoArgs, ["test", "--package", "pkg_name", "--lib", "--no-run", "--message-format=json"]);
25 assert.notDeepEqual(args.filter, undefined);
26 });
27 });
28
29 suite('QuickPick', () => {
30 test('A binary', async () => {
31 const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "pkg_name"]);
32
33 assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "pkg_name", "--message-format=json"]);
34 assert.deepEqual(args.filter, undefined);
35 });
36
37
38 test('One of Multiple Binaries', async () => {
39 const args = cargo.artifactSpec(["run", "--package", "pkg_name", "--bin", "bin2"]);
40
41 assert.deepEqual(args.cargoArgs, ["build", "--package", "pkg_name", "--bin", "bin2", "--message-format=json"]);
42 assert.deepEqual(args.filter, undefined);
43 });
44
45 test('A test', async () => {
46 const args = cargo.artifactSpec(["test", "--package", "pkg_name", "--lib"]);
47
48 assert.deepEqual(args.cargoArgs, ["test", "--package", "pkg_name", "--lib", "--message-format=json", "--no-run"]);
49 assert.notDeepEqual(args.filter, undefined);
50 });
51 });
52});