-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathjest-runner-installed-extensions.ts
More file actions
65 lines (51 loc) · 2.02 KB
/
jest-runner-installed-extensions.ts
File metadata and controls
65 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { spawnSync } from "child_process";
import { dirname } from "path";
import type * as JestRunner from "jest-runner";
import type { RunnerOptions } from "jest-runner-vscode";
import VSCodeTestRunner from "jest-runner-vscode";
import { cosmiconfig } from "cosmiconfig";
import {
downloadAndUnzipVSCode,
resolveCliArgsFromVSCodeExecutablePath,
} from "@vscode/test-electron";
import { ensureCli } from "./ensureCli";
export default class JestRunnerInstalledExtensions extends VSCodeTestRunner {
async runTests(
tests: JestRunner.Test[],
watcher: JestRunner.TestWatcher,
onStart: JestRunner.OnTestStart,
onResult: JestRunner.OnTestSuccess,
onFailure: JestRunner.OnTestFailure,
): Promise<void> {
// The CLI integration tests require certain extensions to be installed, which needs to happen before the tests are
// actually run. The below code will resolve the path to the VSCode executable, and then use that to install the
// required extensions.
const installedOnVsCodeVersions =
new Set<`${RunnerOptions["version"]}-${RunnerOptions["platform"]}`>();
for (const test of tests) {
const testDir = dirname(test.path);
const options: RunnerOptions =
((await cosmiconfig("jest-runner-vscode").search(testDir))
?.config as RunnerOptions) ?? {};
const { version, platform } = options;
const versionKey = `${version}-${platform}` as const;
if (installedOnVsCodeVersions.has(versionKey)) {
continue;
}
const vscodeExecutablePath = await downloadAndUnzipVSCode(
version,
platform,
);
console.log(`Installing required extensions for ${vscodeExecutablePath}`);
const [cli, ...args] =
resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
spawnSync(cli, args, {
encoding: "utf-8",
stdio: "inherit",
});
installedOnVsCodeVersions.add(versionKey);
}
await ensureCli(true);
return super.runTests(tests, watcher, onStart, onResult, onFailure);
}
}