简体   繁体   English

Jest watch 未检测到文件更改

[英]Jest watch not detecting changes to files

Running npm t -- --watch is not detecting changes to test files.运行npm t -- --watch未检测到对测试文件的更改。 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.如果我运行npm tnpm run test:changed (我的脚本仅用于运行通过jest -o覆盖已更改文件的测试)一切正常,但是,不会检测到任何更改并且不会重新运行测试。

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:对于额外的上下文,我正在使用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,
    },
  },
};

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.事实证明,问题是我将 Jest 配置为使用./作为覆盖位置(一切都是.gitignore 'd,所以谁在乎 ¯\\_(ツ)_/¯),这就造成了问题。 More info can be found on the relevant issue on the Jest repo .更多信息可以在 Jest repo上的相关问题上找到。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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