diff options
author | Mikhail Rakhmanov <[email protected]> | 2020-06-03 19:10:54 +0100 |
---|---|---|
committer | Mikhail Rakhmanov <[email protected]> | 2020-06-03 19:10:54 +0100 |
commit | eefa10bc6bff3624ddd0bbb6bc89d8beb4bed186 (patch) | |
tree | 15c38c2993c52f4065d338090ca9185cc1fcd3da /editors/code/tests | |
parent | a9d567584857b1be4ca8eaa5ef2c7d85f7b2845e (diff) | |
parent | 794f6da821c5d6e2490b996baffe162e4753262d (diff) |
Merge branch 'master' into assists_extract_enum
Diffstat (limited to 'editors/code/tests')
-rw-r--r-- | editors/code/tests/runTests.ts | 43 | ||||
-rw-r--r-- | editors/code/tests/unit/index.ts | 38 | ||||
-rw-r--r-- | editors/code/tests/unit/launch_config.test.ts | 52 |
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 @@ | |||
1 | import * as path from 'path'; | ||
2 | import * as fs from 'fs'; | ||
3 | |||
4 | import { runTests } from 'vscode-test'; | ||
5 | |||
6 | async 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 | |||
39 | main().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 @@ | |||
1 | import * as path from 'path'; | ||
2 | import Mocha from 'mocha'; | ||
3 | import glob from 'glob'; | ||
4 | |||
5 | export 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..68794d53e --- /dev/null +++ b/editors/code/tests/unit/launch_config.test.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import * as assert from 'assert'; | ||
2 | import { Cargo } from '../../src/toolchain'; | ||
3 | |||
4 | suite('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 | }); | ||