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.

Is jest fully scanning node_modules and then ignoring its content by default ?

See original GitHub issue

⚡ Performance improvement ?

Jest has been slow to start on my computer, which has a relatively slow filesystem (windows ntfs and a few layers of encryption).

Reading the default configuration, I’m wondering whether jest scans every file in the <rootDir> and then ignores the ones in node_modules. I replaced my roots with <rootDir>/src/ instead of <rootDir> and it feels faster.

To Reproduce

  • Develop a javascript project with a lot of npm dependencies with many files on a slow filesystem.
  • Run jest with no config.
  • Run jest with roots: ['<rootDir>/src/'] in its config.

Expected behavior

Jest should scan the files to find the tests relatively fast. But by default I’m not sure it’s the case.

envinfo

System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  Binaries:
    Node: 12.13.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^25.4.0 => 25.4.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:12

github_iconTop GitHub Comments

2reactions
ustuncommented, Dec 9, 2020

See also this config change for watchman so that it ignores node_modules. That speeds up the initial run significantly: https://github.com/facebook/jest/issues/10833#issuecomment-741748347

2reactions
lexaurincommented, Sep 16, 2020

Also worth mentioning that last saved index must be available in jest cache and cache key must be valid otherwise it builds index again.

And completely agree that it should be evident from CLI that indexing is happening and in documentation I think it should be stated how to avoid it.

From jest-haste-map code:

 * The HasteMap is created as follows:
 *  1. read data from the cache or create an empty structure.
 *
 *  2. crawl the file system.
 *     * empty cache: crawl the entire file system.
 *     * cache available:
 *       * if watchman is available: get file system delta changes.
 *       * if watchman is unavailable: crawl the entire file system.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
The directory where Jest should output its coverage files. coveragePathIgnorePatterns [array<string>]​. Default: ["/node_modules/"]. An array of regexp pattern ...
Read more >
jest ignore all node_modules except 1 package - Stack Overflow
this basically says, ignore all node_modules except my-package. However, the thing to note here is, testPathIgnorePatterns does not determine ...
Read more >
Configuring Jest compiled - w3resource
Jest will attempt to scan your dependency tree once (up-front) and cache it so as to ease some of the filesystem raking that...
Read more >
wordpress/scripts | Block Editor Handbook
When using the start or build commands, the source code directory ( the default is ./src ) and its subdirectories are scanned for...
Read more >
Generating code coverage report in Jest
If test coverage is enforced with some additional analysis about the quality of tests, defect clustering, and other parameters that can ...
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