Jest watch 未检测到文件更改
Jest watch not detecting changes to files
运行 npm t -- --watch
未检测到测试文件的更改。如果我 运行 npm t
或 npm run test:changed
(我的脚本仅用于 运行ning 测试,涵盖通过 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,
},
},
};
原来问题是我将 Jest 配置为使用 ./
作为覆盖位置(一切都是 .gitignore
,所以谁在乎 ¯\_(ツ)_/¯)和那是在制造问题。可以在 relevant issue on the Jest repo.
上找到更多信息
尝试npm jest --clearCache
如果您使用的是打字稿,有时 jests 缓存也会停止捕获更改,请尝试删除您的 dist 文件夹并重建。
运行 npm t -- --watch
未检测到测试文件的更改。如果我 运行 npm t
或 npm run test:changed
(我的脚本仅用于 运行ning 测试,涵盖通过 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,
},
},
};
原来问题是我将 Jest 配置为使用 ./
作为覆盖位置(一切都是 .gitignore
,所以谁在乎 ¯\_(ツ)_/¯)和那是在制造问题。可以在 relevant issue on the Jest repo.
尝试npm jest --clearCache
如果您使用的是打字稿,有时 jests 缓存也会停止捕获更改,请尝试删除您的 dist 文件夹并重建。