Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fungiboletus opened this issue Apr 22, 2020 · 16 comments

Comments

@fungiboletus
Copy link

fungiboletus commented Apr 22, 2020

⚡ 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
@fungiboletus
Copy link
Author

https://github.com/facebook/jest/blob/32aaff83f02c347ccd591727544002490fb4ee9a/packages/jest-core/src/SearchSource.ts#L139-L144

I'm wondering whether this._context.hasteFS.getAllFiles() returns all files in <rootDir> including the files from node_modules.

@sibelius
Copy link

what is the right configuration in monorepo to improve this?

@jufemaiz
Copy link

I'm certain this is what I'm seeing right now.

ps aux gives me the following file scan (docker linux):

find /app -type f ( -iname *.snap -o -iname *.js -o -iname *.json -o -iname *.jsx -o -iname *.ts -o -iname *.tsx -o -iname *.node )

This is causing around a 30s run for a single test file in /app/src/test/simple.test.js:

describe('simple', () => {
  it('should be sane', () => {
    expect(false).not.toBe(true);
  });
});

@lexaurin
Copy link

lexaurin commented Sep 14, 2020

Just figured out how it works and it's a sad story.. 😞

First it checks if you have watchman installed..

https://github.com/facebook/jest/blob/ac73de8989ca06675858b4c8b4f3e6f864a071f0/packages/jest-haste-map/src/index.ts#L738

and if not...

https://github.com/facebook/jest/blob/ac73de8989ca06675858b4c8b4f3e6f864a071f0/packages/jest-haste-map/src/crawlers/node.ts#L233

it either uses native find (your usecase @jufemaiz ) for all files in rootDir!!!

https://github.com/facebook/jest/blob/ac73de8989ca06675858b4c8b4f3e6f864a071f0/packages/jest-haste-map/src/crawlers/node.ts#L236

or if find is not available, on Windows for example if I understand correctly, then it travers recursively all directories in Node.js code.. Seems like @fungiboletus case

@lexaurin
Copy link

And the worst part is that all this Jest do completely silently.. No message like "Hey install watchman" or "Warning: Native find is not available on your system"..

@sibelius
Copy link

is it much faster using watchman?

@lexaurin
Copy link

In our project, with watchman, startup time is almost instantaneous.
In comparison without watchman, it takes 10s to start first test - find output includes even files from node_modules so in our case it is more than 8MB just this file list..

@fungiboletus
Copy link
Author

Sounds like having a warning on the console output would be a good improvement.

@jufemaiz
Copy link

Definitely @fungiboletus !

@lexaurin
Copy link

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.

@beckerei
Copy link

beckerei commented Nov 9, 2020

Is the startup time going only up when you are actually running in watch mode or is it sufficient to have watchman installed?

We have a quite big mono repo with > 3k tests and quite some dependencies. It takes 20-40s for jest to actually start a test run.
Tests itself have expected speed.

@ustun
Copy link

ustun commented Dec 9, 2020

See also this config change for watchman so that it ignores node_modules. That speeds up the initial run significantly: #10833 (comment)

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@fungiboletus
Copy link
Author

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

Dear GitHub bot, please hear my plea,
Don't close my issue, let it be free.
Your automated ways are fine,
But human touch is more divine.

So please ask the one who set you up,
To disable your auto-close cup.
Let's work together, you and I,
And keep this issue open, high and dry.

@github-actions github-actions bot removed the Stale label Feb 17, 2023
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 17, 2024
@fungiboletus
Copy link
Author

.

@github-actions github-actions bot removed the Stale label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants