我有一个AWS Amplify项目,我正在使用JEST为后端运行单元测试。该项目仅包含后端代码(不像大多数这些问题一样具有create-react-app代码)。
FAIL amplify/backend/function/project/src/ts/flows/services/transforms/stepTransformer.spec.ts
● Test suite failed to run
TypeError: environment.teardown is not a function
at node_modules/@jest/core/node_modules/jest-runner/build/runTest.js:440:25
我的笑话配置如下:
module.exports = {
preset: 'ts-jest',
clearMocks: true,
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [
'/node_modules/'
],
moduleFileExtensions: [
'js',
'json',
'ts'
],
testEnvironment: 'node',
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[tj]s?(x)'
],
testPathIgnorePatterns: [
'node_modules',
'#current-cloud-backend',
'_out'
]
};
我的包裹是:
"devDependencies": {
"@aws-amplify/cli": "^4.6.0",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.17",
"husky": "^3.1.0",
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
"jest-junit": "^10.0.0",
"lint-staged": "^9.5.0",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
},
这里唯一的一件事是,我开玩笑的配置位于根文件夹中,并且每个文件夹都有自己的node_modules(我认为这可能是罪魁祸首)。看起来像:
不确定会发生什么。感谢您的任何建议!