question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:19

github_iconTop GitHub Comments

21reactions
eugene-seacommented, Apr 21, 2018

@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.

2reactions
dereklincommented, Aug 10, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run jest for unit tests of modified files only | by SunCommander
In this article, you will learn how to run Jest for modified files only in a Pull Request. This can be done using...
Read more >
Jest CLI Options
If Jest doesn't exit at the end of a test run, it means external resources are still being held on to or timers...
Read more >
Creating snapshots in Jest for testing React applications
Snapshot tests are useful when you want to make sure your UI does not change unexpectedly. A typical snapshot test case renders a...
Read more >
Run tests | IntelliJ IDEA Documentation - JetBrains
If your tests don't require any specific actions before start and you ... From the list on the main toolbar, select the configuration...
Read more >
Learn Jest Watch Mode – Testing React Applications, v2
When configuring Jest watch mode, which allows runs tests related to only the files ... So there's no test found related to files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found