-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathjest-runner-vscode+3.0.1.patch
More file actions
165 lines (165 loc) · 8.18 KB
/
jest-runner-vscode+3.0.1.patch
File metadata and controls
165 lines (165 loc) · 8.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
diff --git a/node_modules/jest-runner-vscode/dist/child/environment.js b/node_modules/jest-runner-vscode/dist/child/environment.js
index 1ac28d5..f91f216 100644
--- a/node_modules/jest-runner-vscode/dist/child/environment.js
+++ b/node_modules/jest-runner-vscode/dist/child/environment.js
@@ -10,6 +10,21 @@ const wrap_io_1 = __importDefault(require("./wrap-io"));
const load_pnp_1 = __importDefault(require("./load-pnp"));
const ipc = new ipc_client_1.default('env');
class VSCodeEnvironment extends jest_environment_node_1.default {
+ constructor(config, context) {
+ super(config, context);
+ // The _VSCODE_NODE_MODULES is a proxy which will require a module if any property
+ // on it is accessed. This is a workaround for the fact that jest will call
+ // _isMockFunction on the module, which will cause that function to be required.
+ this.global._VSCODE_NODE_MODULES = new Proxy(this.global._VSCODE_NODE_MODULES, {
+ get(target, prop) {
+ if (prop === '_isMockFunction') {
+ return undefined;
+ }
+ return target[prop];
+ },
+ });
+ }
+
async setup() {
await super.setup();
await (0, load_pnp_1.default)();
diff --git a/node_modules/jest-runner-vscode/dist/child/runner.js b/node_modules/jest-runner-vscode/dist/child/runner.js
index 0663c5c..bdf4a8b 100644
--- a/node_modules/jest-runner-vscode/dist/child/runner.js
+++ b/node_modules/jest-runner-vscode/dist/child/runner.js
@@ -18,10 +18,13 @@ async function run() {
const ipc = new ipc_client_1.default('child');
const disconnected = new Promise(resolve => ipc.on('disconnect', resolve));
try {
- const { PARENT_JEST_OPTIONS } = process_1.default.env;
+ const { PARENT_JEST_OPTIONS, PARENT_CWD } = process_1.default.env;
if (!PARENT_JEST_OPTIONS) {
throw new Error('PARENT_JEST_OPTIONS is not defined');
}
+ if (PARENT_CWD) {
+ process_1.default.chdir(PARENT_CWD);
+ }
const options = JSON.parse(PARENT_JEST_OPTIONS);
const jestOptions = [
...options.args,
@@ -39,6 +42,9 @@ async function run() {
...(argv.projects?.map(project => path_1.default.resolve(project)) || []),
options.workspacePath,
]);
+ const testPaths = new Set(argv._.map(testPath => path_1.default.resolve(testPath)));
+ argv._ = [...testPaths];
+
await (0, core_1.runCLI)(argv, [...projects]);
}
catch (error) {
diff --git a/node_modules/jest-runner-vscode/dist/public-types.d.ts b/node_modules/jest-runner-vscode/dist/public-types.d.ts
index 57716e5..d8614af 100644
--- a/node_modules/jest-runner-vscode/dist/public-types.d.ts
+++ b/node_modules/jest-runner-vscode/dist/public-types.d.ts
@@ -59,4 +59,5 @@ export interface RunnerOptions {
* code, or download progress. Defaults to `false`.
*/
quiet?: boolean;
+ retries?: number;
}
diff --git a/node_modules/jest-runner-vscode/dist/run-vscode.d.ts b/node_modules/jest-runner-vscode/dist/run-vscode.d.ts
index 8657ace..4d35409 100644
--- a/node_modules/jest-runner-vscode/dist/run-vscode.d.ts
+++ b/node_modules/jest-runner-vscode/dist/run-vscode.d.ts
@@ -16,5 +16,7 @@ export declare type RunVSCodeOptions = {
onFailure: JestRunner.OnTestFailure;
ipc: InstanceType<typeof IPC>;
quiet?: boolean;
+ attempt?: number;
+ maxRetries?: number;
};
-export default function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, }: RunVSCodeOptions): Promise<void>;
+export default function runVSCode(options: RunVSCodeOptions): Promise<void>;
diff --git a/node_modules/jest-runner-vscode/dist/run-vscode.js b/node_modules/jest-runner-vscode/dist/run-vscode.js
index 5d8e513..7e556ee 100644
--- a/node_modules/jest-runner-vscode/dist/run-vscode.js
+++ b/node_modules/jest-runner-vscode/dist/run-vscode.js
@@ -5,8 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = __importDefault(require("child_process"));
const console_1 = __importDefault(require("console"));
-async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, }) {
- return await new Promise(resolve => {
+const fs_1 = __importDefault(require("fs"));
+const path_1 = __importDefault(require("path"));
+const os_1 = __importDefault(require("os"));
+async function runVSCode(options) {
+ const { vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, attempt, maxRetries, } = options;
+ const tempUserDir = await fs_1.default.promises.mkdtemp(path_1.default.resolve(os_1.default.tmpdir(), 'jest-runner-vscode-user-data-'));
+ return await new Promise(promiseResolve => {
+ const resolve = () => {
+ fs_1.default.rm(tempUserDir, { recursive: true }, () => {
+ promiseResolve();
+ });
+ };
const useStdErr = globalConfig.json || globalConfig.useStderr;
const log = useStdErr
? console_1.default.error.bind(console_1.default)
@@ -82,7 +92,11 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
ipc.server.on('stdout', onStdout);
ipc.server.on('stderr', onStderr);
ipc.server.on('error', onError);
- const vscode = child_process_1.default.spawn(vscodePath, args, { env: environment });
+ const launchArgs = args;
+ if (!hasArg('user-data-dir', launchArgs)) {
+ launchArgs.push(`--user-data-dir=${tempUserDir}`);
+ }
+ const vscode = child_process_1.default.spawn(vscodePath, launchArgs, { env: environment });
if (!silent && !filterOutput) {
vscode.stdout.pipe(process.stdout);
vscode.stderr.pipe(process.stderr);
@@ -99,6 +113,29 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
exited = true;
const exit = code ?? signal ?? '<unknown>';
const message = `VS Code exited with exit code ${exit}`;
+ const currentAttempt = attempt ?? 0;
+ const incompleteTests = tests.some(test => !completedTests.has(test));
+ if (maxRetries &&
+ maxRetries > 0 &&
+ currentAttempt < maxRetries &&
+ incompleteTests) {
+ silent || quiet || log(message);
+ const newAttempt = currentAttempt + 1;
+ const newTests = tests.filter(test => !completedTests.has(test));
+ ipc.server.off('testFileResult', onTestFileResult);
+ ipc.server.off('testStart', onTestStart);
+ ipc.server.off('testFileStart', onTestStart);
+ ipc.server.off('stdout', onStdout);
+ ipc.server.off('stderr', onStderr);
+ ipc.server.off('error', onError);
+ await runVSCode({
+ ...options,
+ tests: newTests,
+ attempt: newAttempt,
+ });
+ resolve();
+ return;
+ }
if (typeof code !== 'number' || code !== 0) {
silent || quiet || console_1.default.error(message);
const error = vscodeError ?? childError ?? new Error(message);
@@ -138,3 +175,6 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
});
}
exports.default = runVSCode;
+function hasArg(argName, argList) {
+ return argList.some(a => a === `--${argName}` || a.startsWith(`--${argName}=`));
+}
diff --git a/node_modules/jest-runner-vscode/dist/runner.js b/node_modules/jest-runner-vscode/dist/runner.js
index e24c976..c374022 100644
--- a/node_modules/jest-runner-vscode/dist/runner.js
+++ b/node_modules/jest-runner-vscode/dist/runner.js
@@ -107,6 +107,7 @@ class VSCodeTestRunner {
onFailure,
ipc,
quiet: vscodeOptions.quiet,
+ maxRetries: vscodeOptions.retries,
});
}
catch (error) {