Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Running jest with about 100 tests take around 10-14 seconds on my machine. After doing some profiling, I figured out it calls fs.statSync()
about 150,000 times (so about 1,500 times per single test), and spends there about 6.5 seconds, which is roughly half of the run time. All these calls are initiated by jest-resolve
(which eventually uses the resolve
package).
Using jest v20.0.1, jest-resolve 20.0.1.
Here are my benchmark results:
Test Suites: 14 passed, 14 total
Tests: 3 skipped, 107 passed, 110 total
Snapshots: 0 total
Time: 13.784s
Ran all test suites.
Total statSync calls: 152244
Total time spent (ms): 6916.388558894396
How did I perform the benchmark?
- I replaced
node_modules/jest-resolve/node_modules/resolve/lib/sync.js
with this instrumented version. I instrumented theisFile()
method to figure out how many times it is called and time spent inside. - I ran
jest --runInBand
Also tried to disable cache, but the method was still called ~ 150,000 times.
finally, here is my jest configuration:
"jest": {
"preset": "jest-preset-angular",
"rootDir": "app",
"setupTestFrameworkScriptFile": "<rootDir>/setupJest.ts",
"testRegex": "\\.spec\\.(ts)$",
"transform": {
"^.+\\.(ts|js|html)$": "<rootDir>/../node_modules/jest-preset-angular/preprocessor.js"
},
"globals": {
"__TS_CONFIG__": "app/tsconfig.spec.json",
"__TRANSFORM_HTML__": true
}
}
If needed, I would love to provide more feedback or dig into it further - but please provide me some pointers where to dig.