-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Jest 28.0.0 breaks vscode Jest testing with "Cannot find module '_isMockFunction' #14095
Comments
Could you try swapping two lines in the environment file: - const NodeEnvironment = require("jest-environment-node");
- const vscode = require("vscode");
+ const vscode = require("vscode");
+ const NodeEnvironment = require("jest-environment-node"); It might be that you are hitting #14086 |
@mrazauskas thanks for the response! No dice, same error in Jest 29. In Jest 27, swapping those two lines prevents the vscode global from being seen to the test. The main issue is that the vscode global can't be seen with Jest when running inside of the vscode-test spawned instance, hence the workaround that uses a custom test environment to bring in the global with the modulenamemapper. If there's a better way I should be going about this that might avoid the problem, let me know. |
@mrazauskas upon further investigation, it seems to still break on Jest 29 upgrade even if I remove the node environment config completely. jest.config.js const path = require("path");
// see https://github.com/microsoft/vscode-test/issues/37#issuecomment-700167820
const rootDir = path.join(__dirname, "dist")
module.exports = {
rootDir,
moduleFileExtensions: ["js"],
testMatch: ["<rootDir>/src/log.test.js"],
// testEnvironment: path.resolve(rootDir, "../test", "vscode-environment.js"), // Required for the test to see the vscode global
// moduleNameMapper: {
// vscode: path.resolve(rootDir, "../test", "vscode.js"), // Maps to the testEnvironment specified above
// },
verbose: true
}; Downgrading to 27 and it "works", albeit the test fails because it cannot find the vscode global without the environment. Looks like some kind of conflict with the |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
I randomly decided to update some of my packages today and ran into this issue as well. |
I came up with the same problem. The temporal workaround was to downgrade to Jest 27.5.1 version as @JustinGrote suggested. |
Per microsoft/vscode#175548 (comment), the exception is thrown when trying to access jest/packages/jest-runtime/src/index.ts Lines 1218 to 1224 in 6460335
to this: if (
((typeof globalMock === 'object' && globalMock !== null) ||
typeof globalMock === 'function') &&
"_isMockFunction" in globalMock && globalMock._isMockFunction === true
) {
globalMock.mockClear();
} Where the property access on |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
28.0.0 (and latest)
Steps to reproduce
Example Repo:
https://github.com/daddykotex/jest-tests
Further issue description here:
microsoft/vscode#175548
Expected behavior
Tests run as expected
Actual behavior
Additional context
Works fine on Jest 27, downgrading is an effective workaround
Environment
The text was updated successfully, but these errors were encountered: