Running npm t -- --watch
is not detecting changes to test files. If I run npm t
or npm run test:changed
(my script for only running tests that cover changed files via jest -o
) everything works fine, however, no changes are ever detected and the tests aren't re-run.
Any idea what I could be doing wrong?
For extra context, I'm using ts-jest
and here are some of my relevant config files:
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,
},
},
};
Turns out the issue was that I configured Jest to use ./
for the coverage location (everything was .gitignore
'd, so who cares ¯\_(ツ)_/¯) and that was creating problems. More info can be found on the relevant issue on the Jest repo.