diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/cargo.ts | 14 | ||||
-rw-r--r-- | editors/code/tests/runTests.ts | 73 | ||||
-rw-r--r-- | editors/code/tests/unit/index.ts | 10 |
3 files changed, 44 insertions, 53 deletions
diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts index c3e2e5c05..a55b2f860 100644 --- a/editors/code/src/cargo.ts +++ b/editors/code/src/cargo.ts | |||
@@ -25,7 +25,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec { | |||
25 | switch (cargoArgs[0]) { | 25 | switch (cargoArgs[0]) { |
26 | case "run": cargoArgs[0] = "build"; break; | 26 | case "run": cargoArgs[0] = "build"; break; |
27 | case "test": { | 27 | case "test": { |
28 | if (cargoArgs.indexOf("--no-run") === -1) { | 28 | if (!cargoArgs.includes("--no-run")) { |
29 | cargoArgs.push("--no-run"); | 29 | cargoArgs.push("--no-run"); |
30 | } | 30 | } |
31 | break; | 31 | break; |
@@ -36,9 +36,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec { | |||
36 | if (cargoArgs[0] === "test") { | 36 | if (cargoArgs[0] === "test") { |
37 | // for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests | 37 | // for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests |
38 | // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} | 38 | // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} |
39 | result.filter = (artifacts) => { | 39 | result.filter = (artifacts) => artifacts.filter(it => it.isTest); |
40 | return artifacts.filter(a => a.isTest); | ||
41 | }; | ||
42 | } | 40 | } |
43 | 41 | ||
44 | return result; | 42 | return result; |
@@ -48,7 +46,7 @@ export class Cargo { | |||
48 | constructor(readonly rootFolder: string, readonly output: OutputChannel) { } | 46 | constructor(readonly rootFolder: string, readonly output: OutputChannel) { } |
49 | 47 | ||
50 | private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> { | 48 | private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> { |
51 | let artifacts: CompilationArtifact[] = []; | 49 | const artifacts: CompilationArtifact[] = []; |
52 | 50 | ||
53 | try { | 51 | try { |
54 | await this.runCargo(spec.cargoArgs, | 52 | await this.runCargo(spec.cargoArgs, |
@@ -75,11 +73,7 @@ export class Cargo { | |||
75 | throw new Error(`Cargo invocation has failed: ${err}`); | 73 | throw new Error(`Cargo invocation has failed: ${err}`); |
76 | } | 74 | } |
77 | 75 | ||
78 | if (spec.filter) { | 76 | return spec.filter?.(artifacts) ?? artifacts; |
79 | artifacts = spec.filter(artifacts); | ||
80 | } | ||
81 | |||
82 | return artifacts; | ||
83 | } | 77 | } |
84 | 78 | ||
85 | async executableFromArgs(args: readonly string[]): Promise<string> { | 79 | async executableFromArgs(args: readonly string[]): Promise<string> { |
diff --git a/editors/code/tests/runTests.ts b/editors/code/tests/runTests.ts index 81600f6a8..22df80ad3 100644 --- a/editors/code/tests/runTests.ts +++ b/editors/code/tests/runTests.ts | |||
@@ -4,43 +4,40 @@ import * as fs from 'fs'; | |||
4 | import { runTests } from 'vscode-test'; | 4 | import { runTests } from 'vscode-test'; |
5 | 5 | ||
6 | async function main() { | 6 | async function main() { |
7 | try { | 7 | // The folder containing the Extension Manifest package.json |
8 | // The folder containing the Extension Manifest package.json | 8 | // Passed to `--extensionDevelopmentPath` |
9 | // Passed to `--extensionDevelopmentPath` | 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); |
10 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); | 10 | |
11 | 11 | // Minimum supported version. | |
12 | // Minimum supported version. | 12 | const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json')); |
13 | const jsonData = fs.readFileSync(path.join(extensionDevelopmentPath, 'package.json')); | 13 | const json = JSON.parse(jsonData.toString()); |
14 | const json = JSON.parse(jsonData.toString()); | 14 | let minimalVersion: string = json.engines.vscode; |
15 | let minimalVersion: string = json.engines.vscode; | 15 | if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1); |
16 | if (minimalVersion.startsWith('^')) minimalVersion = minimalVersion.slice(1); | 16 | |
17 | 17 | const launchArgs = ["--disable-extensions"]; | |
18 | const launchArgs = ["--disable-extensions"]; | 18 | |
19 | 19 | // All test suites (either unit tests or integration tests) should be in subfolders. | |
20 | // All test suites (either unit tests or integration tests) should be in subfolders. | 20 | const extensionTestsPath = path.resolve(__dirname, './unit/index'); |
21 | const extensionTestsPath = path.resolve(__dirname, './unit/index'); | 21 | |
22 | 22 | // Run tests using the minimal supported version. | |
23 | // Run tests using the minimal supported version. | 23 | await runTests({ |
24 | await runTests({ | 24 | version: minimalVersion, |
25 | version: minimalVersion, | 25 | launchArgs, |
26 | launchArgs, | 26 | extensionDevelopmentPath, |
27 | extensionDevelopmentPath, | 27 | extensionTestsPath |
28 | extensionTestsPath | 28 | }); |
29 | }); | 29 | |
30 | 30 | // and the latest one | |
31 | // and the latest one | 31 | await runTests({ |
32 | await runTests({ | 32 | version: 'stable', |
33 | version: 'stable', | 33 | launchArgs, |
34 | launchArgs, | 34 | extensionDevelopmentPath, |
35 | extensionDevelopmentPath, | 35 | extensionTestsPath |
36 | extensionTestsPath | 36 | }); |
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 | } | 37 | } |
45 | 38 | ||
46 | main(); | 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 index 1deb1c403..5165720b4 100644 --- a/editors/code/tests/unit/index.ts +++ b/editors/code/tests/unit/index.ts | |||
@@ -11,10 +11,10 @@ export function run(): Promise<void> { | |||
11 | 11 | ||
12 | const testsRoot = __dirname; | 12 | const testsRoot = __dirname; |
13 | 13 | ||
14 | return new Promise((c, e) => { | 14 | return new Promise((resolve, reject) => { |
15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { | 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { |
16 | if (err) { | 16 | if (err) { |
17 | return e(err); | 17 | return reject(err); |
18 | } | 18 | } |
19 | 19 | ||
20 | // Add files to the test suite | 20 | // Add files to the test suite |
@@ -25,13 +25,13 @@ export function run(): Promise<void> { | |||
25 | mocha.timeout(100000); | 25 | mocha.timeout(100000); |
26 | mocha.run(failures => { | 26 | mocha.run(failures => { |
27 | if (failures > 0) { | 27 | if (failures > 0) { |
28 | e(new Error(`${failures} tests failed.`)); | 28 | reject(new Error(`${failures} tests failed.`)); |
29 | } else { | 29 | } else { |
30 | c(); | 30 | resolve(); |
31 | } | 31 | } |
32 | }); | 32 | }); |
33 | } catch (err) { | 33 | } catch (err) { |
34 | e(err); | 34 | reject(err); |
35 | } | 35 | } |
36 | }); | 36 | }); |
37 | }); | 37 | }); |