运行npm t -- --watch不会检测到对测试文件的更改。如果我运行npm t或npm run test:changed (我的脚本只运行通过jest -o覆盖更改文件的测试),那么一切都正常,但是不会检测到任何更改,测试也不会重新运行。
知道我可能做错什么了吗?
对于额外的上下文,我使用的是ts-jest,下面是一些相关的配置文件:
src/tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"outDir": "../dist",
"esModuleInterop": true,
"noImplicitAny": true,
"noEmitOnError": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext", "esnext.asynciterable"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": ["./**/*.ts"],
"exclude": ["node_modules", "./**/*.test.ts"]
}jest.config.ts
module.exports = {
globals: {
'ts-jest': {
tsConfig: 'src/tsconfig.json',
},
},
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx'],
roots: ['src'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testMatch: ['**/*.test.(ts|js)'],
testEnvironment: 'node',
preset: 'ts-jest',
collectCoverageFrom: ['./src/**/*.ts', '!./src/migration/**', '!./src/tests/**'],
coverageDirectory: './',
coverageThreshold: {
global: {
statements: 60,
branches: 45,
functions: 35,
lines: 60,
},
},
};发布于 2019-12-04 17:38:47
结果是,我将Jest配置为使用./作为覆盖位置(所有内容都是.gitignore'd,所以谁在乎¯\_(ツ)_/ツ),这造成了问题。更多的信息可以在Jest回购的相关问题上找到。
发布于 2022-01-19 12:30:42
尝试npm jest --clearCache有时会停止jests缓存捕捉更改,如果使用类型记录,也可以尝试删除dist文件夹并重新生成。
发布于 2022-11-03 04:01:21
在我的示例中,配置将测试设置为在--runInBand模式下运行。如果你把这个移开,表就能用了。
https://stackoverflow.com/questions/59164590
复制相似问题