Skip to content

Commit 9a9a8c5

Browse files
committed
Fix multiple VSCode instances launching
Multiple VSCode instances were being launched when a second instance of VSCode was being spawned with the same user data directory. This is probably because VSCode restores the windows from the previous session, even when `-n`/`--new-window` is passed. This fixes it by patching `jest-runner-vscode` to always create a new temporary user data directory, rather than re-using the same one for all test suites.
1 parent 644bea2 commit 9a9a8c5

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

extensions/ql-vscode/patches/jest-runner-vscode+3.0.1.patch

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,44 @@ index 8657ace..4d35409 100644
4141
-export default function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, }: RunVSCodeOptions): Promise<void>;
4242
+export default function runVSCode(options: RunVSCodeOptions): Promise<void>;
4343
diff --git a/node_modules/jest-runner-vscode/dist/run-vscode.js b/node_modules/jest-runner-vscode/dist/run-vscode.js
44-
index 5d8e513..6edf99a 100644
44+
index 5d8e513..cacbc42 100644
4545
--- a/node_modules/jest-runner-vscode/dist/run-vscode.js
4646
+++ b/node_modules/jest-runner-vscode/dist/run-vscode.js
47-
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47+
@@ -5,8 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4848
Object.defineProperty(exports, "__esModule", { value: true });
4949
const child_process_1 = __importDefault(require("child_process"));
5050
const console_1 = __importDefault(require("console"));
5151
-async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, }) {
52+
- return await new Promise(resolve => {
53+
+const fs_1 = __importDefault(require("fs"));
54+
+const path_1 = __importDefault(require("path"));
55+
+const os_1 = __importDefault(require("os"));
5256
+async function runVSCode(options) {
5357
+ const { vscodePath, args, jestArgs, env, tests, globalConfig, filterOutput, onStart, onResult, onFailure, ipc, quiet, attempt, maxRetries, } = options;
54-
return await new Promise(resolve => {
58+
+ const tempUserDir = await fs_1.default.promises.mkdtemp(path_1.default.resolve(os_1.default.tmpdir(), 'jest-runner-vscode-user-data-'));
59+
+ return await new Promise(promiseResolve => {
60+
+ const resolve = () => {
61+
+ fs_1.default.rm(tempUserDir, { recursive: true }, () => {
62+
+ promiseResolve();
63+
+ });
64+
+ };
5565
const useStdErr = globalConfig.json || globalConfig.useStderr;
5666
const log = useStdErr
57-
@@ -101,11 +102,31 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
67+
? console_1.default.error.bind(console_1.default)
68+
@@ -82,7 +92,11 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
69+
ipc.server.on('stdout', onStdout);
70+
ipc.server.on('stderr', onStderr);
71+
ipc.server.on('error', onError);
72+
- const vscode = child_process_1.default.spawn(vscodePath, args, { env: environment });
73+
+ const launchArgs = args;
74+
+ if (!hasArg('user-data-dir', launchArgs)) {
75+
+ launchArgs.push(`--user-data-dir=${tempUserDir}`);
76+
+ }
77+
+ const vscode = child_process_1.default.spawn(vscodePath, launchArgs, { env: environment });
78+
if (!silent && !filterOutput) {
79+
vscode.stdout.pipe(process.stdout);
80+
vscode.stderr.pipe(process.stderr);
81+
@@ -101,11 +115,31 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
5882
const message = `VS Code exited with exit code ${exit}`;
5983
if (typeof code !== 'number' || code !== 0) {
6084
silent || quiet || console_1.default.error(message);
@@ -91,6 +115,13 @@ index 5d8e513..6edf99a 100644
91115
}
92116
}
93117
}
118+
@@ -138,3 +172,6 @@ async function runVSCode({ vscodePath, args, jestArgs, env, tests, globalConfig,
119+
});
120+
}
121+
exports.default = runVSCode;
122+
+function hasArg(argName, argList) {
123+
+ return argList.some(a => a === `--${argName}` || a.startsWith(`--${argName}=`));
124+
+}
94125
diff --git a/node_modules/jest-runner-vscode/dist/runner.js b/node_modules/jest-runner-vscode/dist/runner.js
95126
index e24c976..c374022 100644
96127
--- a/node_modules/jest-runner-vscode/dist/runner.js

extensions/ql-vscode/src/vscode-tests/jest-runner-vscode.config.base.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const config = {
1111
launchArgs: [
1212
"--disable-gpu",
1313
"--extensions-dir=" + path.join(rootDir, ".vscode-test", "extensions"),
14-
"--user-data-dir=" + path.join(tmpDir.name, "user-data"),
1514
],
1615
extensionDevelopmentPath: rootDir,
1716
};

0 commit comments

Comments
 (0)