簡體   English   中英

Jest watch 未檢測到文件更改

[英]Jest watch not detecting changes to files

運行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,
    },
  },
};

事實證明,問題是我將 Jest 配置為使用./作為覆蓋位置(一切都是.gitignore 'd,所以誰在乎 ¯\\_(ツ)_/¯),這就造成了問題。 更多信息可以在 Jest repo上的相關問題上找到。

嘗試npm jest --clearCache如果您使用打字稿,有時 jests 緩存也會停止捕獲更改,請嘗試刪除您的 dist 文件夾並重建。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM