aboutsummaryrefslogtreecommitdiff
path: root/editors/code/tests
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/tests')
-rw-r--r--editors/code/tests/runTests.ts46
-rw-r--r--editors/code/tests/unit/index.ts38
-rw-r--r--editors/code/tests/unit/launch_config.test.ts52
3 files changed, 136 insertions, 0 deletions
diff --git a/editors/code/tests/runTests.ts b/editors/code/tests/runTests.ts
new file mode 100644
index 000000000..81600f6a8
--- /dev/null
+++ b/editors/code/tests/runTests.ts
@@ -0,0 +1,46 @@
1import * as path from 'path';
2import * as fs from 'fs';
3
4import { runTests } from 'vscode-test';
5
6async function main() {
7 try {
8 // The folder containing the Extension Manifest package.json
9 // Passed to `--extensionDevelopmentPath`
10 const extensionDevelopmentPath = path.resolve(__dirname, '../../');
11
12 // Minimum supported version.
13 const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json'));
14 const json = JSON.parse(jsonData.toString());
15 let minimalVersion: string = json.engines.vscode;
16 if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1);
17
18 const launchArgs = ["--disable-extensions"];
19
20 // All test suites (either unit tests or integration tests) should be in subfolders.
21 const extensionTestsPath = path.resolve(__dirname, './unit/index');
22
23 // Run tests using the minimal supported version.
24 await runTests({
25 version: minimalVersion,
26 launchArgs,
27 extensionDevelopmentPath,
28 extensionTestsPath
29 });
30
31 // and the latest one
32 await runTests({
33 version: 'stable',
34 launchArgs,
35 extensionDevelopmentPath,
36 extensionTestsPath
37 });
38
39 } catch (err) {
40 // eslint-disable-next-line no-console
41 console.error('Failed to run tests', err);
42 process.exit(1);
43 }
44}
45
46main();
diff --git a/editors/code/tests/unit/index.ts b/editors/code/tests/unit/index.ts
new file mode 100644
index 000000000..1deb1c403
--- /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((c, e) => {
15 glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16 if (err) {
17 return e(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 e(new Error(`${failures} tests failed.`));
29 } else {
30 c();
31 }
32 });
33 } catch (err) {
34 e(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});