Skip to content

Commit 1ea3cfd

Browse files
committed
Fix failing tests on VSCode 1.74.0
This fixes the tests on VSCode 1.74.0. The issue is as follows: 1. Jest wil try reset all mocks after each test, as it should. 2. When Jest does this, it will loop over all global variables and check if they are mocks. 3. One of the global variables it checks is _VSCODE_NODE_MODULES, which is a proxy object. 4. When Jest checks whether it is a proxy by getting _isMockFunction on it, the `get` function on the proxy object will be called. 5. This will in turn call require, which will try to load the non-existing `_isMockFunction` module. This throws the error we are seeing. By removing the `_VSCODE_NODE_MODULES` property from the global object in the Jest environment, Jest will not try to reset it, and the tests should work again. See: https://github.com/facebook/jest/blob/41bf2300895a2c00d0525d21260f0a392819871f/packages/jest-runtime/src/index.ts#L1173-L1186 See: https://github.com/microsoft/vscode/blob/ed442a9e99ff68a3bb9e4953081305766862f450/src/bootstrap-amd.js#L15
1 parent 993b8c9 commit 1ea3cfd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
diff --git a/node_modules/jest-runner-vscode/dist/child/environment.js b/node_modules/jest-runner-vscode/dist/child/environment.js
2+
index 1ac28d5..52665c7 100644
3+
--- a/node_modules/jest-runner-vscode/dist/child/environment.js
4+
+++ b/node_modules/jest-runner-vscode/dist/child/environment.js
5+
@@ -10,6 +10,14 @@ const wrap_io_1 = __importDefault(require("./wrap-io"));
6+
const load_pnp_1 = __importDefault(require("./load-pnp"));
7+
const ipc = new ipc_client_1.default('env');
8+
class VSCodeEnvironment extends jest_environment_node_1.default {
9+
+ constructor(config, context) {
10+
+ super(config, context);
11+
+ // The _VSCODE_NODE_MODULES is a proxy which will require a module if any property
12+
+ // on it is accessed. This is a workaround for the fact that jest will call
13+
+ // _isMockFunction on the module, which will cause that function to be required.
14+
+ delete this.global._VSCODE_NODE_MODULES;
15+
+ }
16+
+
17+
async setup() {
18+
await super.setup();
19+
await (0, load_pnp_1.default)();
120
diff --git a/node_modules/jest-runner-vscode/dist/child/runner.js b/node_modules/jest-runner-vscode/dist/child/runner.js
221
index 0663c5c..4991663 100644
322
--- a/node_modules/jest-runner-vscode/dist/child/runner.js

0 commit comments

Comments
 (0)