'jest: _interopRequireWildcard is not defined
I'm using swc/jest instead of ts-jest and babel-jest to run my tests with jest. It works for every tests, except those that must deal with files which have wildcard imports or exports (that is to say: import * from "./myfile").
Like babel, swc/jest transforms wildcard (*) import to _interopRequireWildcard(require("./myfile")). (see swc tests). But when doing so, jest throws the following error:
ReferenceError: _interopRequireWildcard is not defined
Here is my jest config:
const path = require("path");
const resolve = (_path) => path.resolve(__dirname, _path);
module.exports = {
testURL: "http://localhost",
testEnvironment: "jsdom",
snapshotSerializers: ["jest-serializer-html"],
testPathIgnorePatterns: ["e2e/", ".*donottest.*"],
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest"],
},
setupFiles: ["jest-canvas-mock"],
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
moduleFileExtensions: ["js", "jsx", "json", "ts", "tsx", "svg"],
globals: {
"ts-jest": {
tsconfig: resolve("./tsconfig.test.json"),
diagnostics: false,
},
},
};
How to fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
