【问题标题】:Jest watch not detecting changes to filesJest watch 未检测到文件更改
【发布时间】:2022-01-19 20:30:42
【问题描述】:

运行npm t -- --watch 未检测到对测试文件的更改。如果我运行npm tnpm 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,
    },
  },
};

【问题讨论】:

    标签: node.js typescript jestjs ts-jest


    【解决方案1】:

    原来问题是我将 Jest 配置为使用 ./ 作为覆盖位置(一切都是 .gitignore'd,所以谁在乎¯\_(ツ)_/¯),这会产生问题。更多信息请访问relevant issue on the Jest repo

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-28
        • 2021-05-26
        • 2019-08-21
        • 1970-01-01
        • 1970-01-01
        • 2021-12-17
        • 2018-08-27
        • 2011-11-16
        相关资源
        最近更新 更多