简体   繁体   中英

Jest watch not detecting changes to files

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 .

尝试npm jest --clearCache如果您使用打字稿,有时 jests 缓存也会停止捕获更改,请尝试删除您的 dist 文件夹并重建。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM