jest: jest --watch fails to determine files to run tests against if there are changes since last commit

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

We have an angular project using jest. Jest uses git to determine file changes and run tests against these files.

Clean project

If the project is “clean” with no change since last commit, then running jest --watch starts properly. Then we can use it normally, it detects changes properly and run expected tests suits.

Dirty project

if the projects has changes on certain files since last commit and we try to run jest --watch then Jest struggles to start and stay forever on the Determining test suites to run... state. Any change after that doesn’t change the stuck jest state.

If we revert our changes (nothing to be commited) then retry to launch jest --watch works. So it seems it’s a real problem with git changes detection by Jest.

Environment

This behavior is always encountered on windows. And sometimes on mac OS.

What is the expected behavior?

Being able to run jest --watch even if there are modified files since last commit. If the changes files are not detected properly we expect to be able to even load jest and being able to pattern filter on the files we want.

Please provide your exact Jest configuration

module.exports = {
  setupTestFrameworkScriptFile: "<rootDir>/src/setupJest.ts",
  globals: {
    'ts-jest': {
      'tsConfigFile': 'src/tsconfig.spec.json'
    },
    '__TRANSFORM_HTML__': true
  },
  transform: {
    '^.+\\.(ts|js|html)$': '<rootDir>/node_modules/jest-preset-angular/preprocessor.js',
  },
  testMatch: [
    "**/__tests__/**/*.+(ts|js)?(x)",
    "**/+(*.)+(spec).+(ts|js)?(x)"
  ],
  moduleFileExtensions: [
    'ts',
    'js',
    'html'
  ],
  moduleNameMapper: {
    "assets/(.*)": "<rootDir>/src/assets/$1"
  },
  transformIgnorePatterns: [
    'node_modules/(?!@ngrx)'
  ],
  coverageReporters: ['html', 'text-summary', 'text']
};

Run npx envinfo --preset jest in your project directory and paste the results here

System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  Binaries:
    Yarn: 1.6.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 5.8.0 - C:\Program Files\nodejs\npm.CM

  System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 8.11.1 - /usr/local/bin/node
    Yarn: 1.6.0 - /usr/local/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  npmPackages:
    @types/jest: 22.2.3 => 22.2.3
    jest: 22.4.3 => 22.4.3

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 19 (6 by maintainers)

Most upvoted comments

@SimenB, I have added tracing to jest and was able to find root cause of the issue in my case. Please, see image below. There was an error inside jest-resolve-dependencies and it was “eaten” without any reporting causing jest to stuck.

Error Logging

The problem was related to coverage folder (produced by karma), it contained some garbage but jest was trying to work with it contents. I have added the following to jest.config.js and jest now works OK:

modulePathIgnorePatterns: ['<rootDir>/coverage/'],

jest-resolve-dependencies error handling can be improved to not hide such errors. Thank you for your work on such great tool anyway.

Oh. Should have read each comment here carefully. The issue is with the coverage folder. Apparently the coverage was referring to some old code that was deleted, and jest is still trying to find it. Deleting the coverage folder fixes the issue for me.

I also need moduleNameMapper.

@SimenB Here is a recording of the problem:

jest-bug

For your information:

  • running without clearCache doesn’t solve the problem
  • running with watchAll works

So it’s certainly a git change detection problem within jest. As you can see VSCode detects the change in control versioning panel, also is my command line (master switching to red).