Skip to content

Commit c41a10c

Browse files
committed
Apply suggestions from @Veetaha code review
1 parent 8ee40cc commit c41a10c

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

editors/code/src/cargo.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec {
2525
switch (cargoArgs[0]) {
2626
case "run": cargoArgs[0] = "build"; break;
2727
case "test": {
28-
if (cargoArgs.indexOf("--no-run") === -1) {
28+
if (!cargoArgs.includes("--no-run")) {
2929
cargoArgs.push("--no-run");
3030
}
3131
break;
@@ -36,9 +36,7 @@ export function artifactSpec(args: readonly string[]): ArtifactSpec {
3636
if (cargoArgs[0] === "test") {
3737
// for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests
3838
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
39-
result.filter = (artifacts) => {
40-
return artifacts.filter(a => a.isTest);
41-
};
39+
result.filter = (artifacts) => artifacts.filter(it => it.isTest);
4240
}
4341

4442
return result;
@@ -48,7 +46,7 @@ export class Cargo {
4846
constructor(readonly rootFolder: string, readonly output: OutputChannel) { }
4947

5048
private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> {
51-
let artifacts: CompilationArtifact[] = [];
49+
const artifacts: CompilationArtifact[] = [];
5250

5351
try {
5452
await this.runCargo(spec.cargoArgs,
@@ -75,11 +73,7 @@ export class Cargo {
7573
throw new Error(`Cargo invocation has failed: ${err}`);
7674
}
7775

78-
if (spec.filter) {
79-
artifacts = spec.filter(artifacts);
80-
}
81-
82-
return artifacts;
76+
return spec.filter?.(artifacts) ?? artifacts;
8377
}
8478

8579
async executableFromArgs(args: readonly string[]): Promise<string> {

editors/code/tests/runTests.ts

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,40 @@ import * as fs from 'fs';
44
import { runTests } from 'vscode-test';
55

66
async 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-
}
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+
});
4437
}
4538

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+
});

editors/code/tests/unit/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function run(): Promise<void> {
1111

1212
const testsRoot = __dirname;
1313

14-
return new Promise((c, e) => {
14+
return new Promise((resolve, reject) => {
1515
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
1616
if (err) {
17-
return e(err);
17+
return reject(err);
1818
}
1919

2020
// Add files to the test suite
@@ -25,13 +25,13 @@ export function run(): Promise<void> {
2525
mocha.timeout(100000);
2626
mocha.run(failures => {
2727
if (failures > 0) {
28-
e(new Error(`${failures} tests failed.`));
28+
reject(new Error(`${failures} tests failed.`));
2929
} else {
30-
c();
30+
resolve();
3131
}
3232
});
3333
} catch (err) {
34-
e(err);
34+
reject(err);
3535
}
3636
});
3737
});

0 commit comments

Comments
 (0)