我正在用打字稿编写测试,并且我在node_modules/@my-modules
文件夹中有私有依赖项。我正在使用ts-jest
编译器,但 jest 仍然抱怨 node_modules 文件夹中的 esnext 模块。
包版本:
"@types/jest": "^23.3.12",
"jest": "^23.6.0",
"ts-jest": "^23.10.5",
tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./src",
"outDir": "build/dist",
"module": "commonjs",
"target": "es5",
"lib": ["es5", "es6", "dom", "esnext"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"strict": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}
jest.config.js:
module.exports = {
globals: {
"ts-jest": {
diagnostics: true,
tsConfig: "<rootDir>/tsconfig.json",
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
preset: "ts-jest",
roots: ["<rootDir>/src/"],
setupTestFrameworkScriptFile: "<rootDir>/src/setupEnzyme.ts",
snapshotSerializers: ["enzyme-to-json/serializer"],
testEnvironment: "jest-environment-jsdom",
transformIgnorePatterns: [
"node_modules/(?!(@my-modules)/)",
]
};
运行 jest 时的确切错误:
Details:
/sites/frontend/node_modules/@my-modules/ui-components/.dist/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as Calendar } from './components/calendar';
^^^^^^
SyntaxError: Unexpected token export
什么是@my-modules
为了开玩笑而转换文件的正确方法?