-
Notifications
You must be signed in to change notification settings - Fork 455
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
Unit test runs very slow (6 sec per a test) #259
Comments
I can't comment on this without seeing what setup you're using. Please create a minimal repo with this issue |
I'm experiencing this as well. Updating from |
I am using it with angular-jest preset which uses ts-jest. You may want to use the example there are a minimal repo. |
I am also seeing a substantial increase in test time between 20.0.4 and 20.0.7.
ts-jest 20.0.4: 30-35s It's sadly not open source, the only thing I am able to provide is our jest.json{
"setupTestFrameworkScriptFile": "<rootDir>/node_modules/project-watchtower/lib/test/setup-tests.js",
"transform": {
".tsx?": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": [
"node_modules/(?!swm-component-library)"
],
"testRegex": "\\.(spec|test)\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"moduleDirectories": [
"node_modules"
],
"modulePaths": [
"<rootDir>/common",
"<rootDir>/app",
"<rootDir>"
],
"moduleNameMapper": {
"\\.(s?css|png|svg|jpg)$": "<rootDir>/node_modules/project-watchtower/lib/test/test-mapper.js",
"^bundle-loader": "<rootDir>/node_modules/project-watchtower/lib/test/bundle-loader-mapper.js"
},
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"verbose": false,
"collectCoverageFrom": [
"**/*.{ts,tsx}",
"!**/*.d.ts",
"!**/node_modules/**",
"!config/**"
],
"coverageReporters": ["json", "lcov", "text", "teamcity"],
"testResultsProcessor": "jest-teamcity-reporter",
"rootDir": "../../../.."
}
|
Using the node-inspector I've found a potential reason for the slowness: Every time a Error is created the stacktrace is prepared and this retriggers the Typescript transpile step. Weird, as Typescript already compiled. What causes this I don't know. Does ts-lint manually patch some of these methods to inject the TS compile step? And if so, doesn't that need to use some sort of cache? |
Sample project: https://github.com/hermanbanken/ts-jest-bugfix |
CPU-20170804T145819.cpuprofile.zip |
I think this is due to the fact that our sourcemap-support recompiles the typescript to make the line numbers match in stack traces. We should be able to cache the files though, shouldn't we @kulshekhar ? |
I'm not sure but I think this might be possible |
#292 is low hanging fruit - but I actually think we might be able to cache better than that - we could cache the files the first time we transpile them (e.g.) in the preprocessor, and then just look up the transpiled files in the source-map-support plugin. This of course, assumes that source-map-support has access to our preprocessor, even after the preprocess step. |
Wouldn't jest handle the caching part if nothing (source code/tsconfig/jest config) has changed? |
I'm not actually sure. Anyways, let's take a look at the performance after merging in #292, and then see if we actually need to do more. |
@kidqn @clayne11 @kryops @hermanbanken Could you please test with 20.0.10 and share your results. |
See that #292 is merged 🎉 Will test it in the morning too with my actual project. Good work 👍 |
Tested 20.0.10 - no visible improvement. Rather small test environment of 65 tests runs 18-20 seconds. |
wow, this really made our tests a lot faster!
ts-jest@20.0.4: 35-40s Thanks so much! |
✓ creates many Timeout errors (1995ms)
✓ throwing 1000 Errors (5042ms)
✓ throwing 1000 Errors, not touching Error.stack (4ms)
✓ creates many Timeout errors (325ms)
✓ throwing 1000 Errors (355ms)
✓ throwing 1000 Errors, not touching Error.stack (5ms) 🎉 For my real project the difference is visible too, however, the difference is smaller. The time during which our tests run is indeed much shorter though. Setting |
@kompot would it be possible for you to create a sample repo with one of the long running tests?
@kryops awesome!
@hermanbanken That cache is specific to source-map-support. The cache from the first compilation is handled by jest and not by ts-jest.
Thanks. You deserve the bulk of the credit for this though. The repo and the profile were immensely helpful. At this point, I think any significant speed improvement beyond this might have to come from Jest itself |
@kompot can you try compiling the tests with tsc and then just running regular jest (i.e. without ts-jest) on them? It'd be interesting to see whether this is just jest being a little tardy or our problem. |
Well, seems like the problem was with |
@ahnpnl has this issue been addressed? The inactivity doesn't indicate that there is no problem here... |
@ahnpnl imo changing default for isolationModule is not fix for this. |
I agree changing isolatedModules true is just a workaround. For clean keeping I closed this issue because it’s a known issue after 23.10 and has been addressed. |
@ahnpnl Has been addressed by a workaround 😆? If there is an existing issue that tracks performance after 23.10, can you link it here, please? Otherwise, I don't follow either why to close this one. Plenty of valuable feedback here. |
No I don’t mean addresses by a workaround. I mean workaround is isolatedModule=true. By default, isolatedModule=false which causes the issue. Since this has been linked to the other issue as related area (performance after 23.10, I don’t see any issues of closing this. You can always look back from the link issue |
Hi all, would you guys help testing with the new changes mentioned in #1310 (comment) ? |
We found that by having a separate tsconfig.json for testing where |
Yes that is exactly what I implemented for alpha release version |
I'm still facing the issue now. A very simple test of checking 1+1 equals 2 takes 6s. Doing the |
If you wish, you can use this workaround in
Reduced complex tests time from 7 seconds to 2.7 seconds and times are much more consistent. |
or using |
in my case, using babel-jest instead of ts-jest, which is what I had, reports errors in the lines with typescript specific syntax |
This helped me a lot. Reduced the running time on very large test suite by 15%. its awsome :) Thank you guys! |
My observations (and I don't know much about jest internals or ts-jest internals, so take with a grain of salt):
All in one, I try following workaround now:
I hope that the issue with caching can be pinned down and resolved. @ahnpnl can you please reopen this issue? Related, but I don't think that it is the same: #1310 |
Your observation is correct. Caching is Jest itself does based on cache key which |
as per kulshekhar/ts-jest#259 (comment) using maxWorkers: 1 ends up being faster
* fix type errors * chore: speed up tests as per kulshekhar/ts-jest#259 (comment) using maxWorkers: 1 ends up being faster * set typescript to only build the webapp/javascript dir * use a specific tsconfig just for linting * speed up tests * lint test files as well * use esbuild * optimize local refresh by only building the index page * print to stderr from webpack to make it easier to save stats * inject livereload script to index.html * fix prod build by enabling ts-jest
* fix type errors * chore: speed up tests as per kulshekhar/ts-jest#259 (comment) using maxWorkers: 1 ends up being faster * set typescript to only build the webapp/javascript dir * use a specific tsconfig just for linting * speed up tests * lint test files as well * use esbuild * optimize local refresh by only building the index page * print to stderr from webpack to make it easier to save stats * inject livereload script to index.html * fix prod build by enabling ts-jest
@bbugh I appreciate your solution! However, setting maxWorkers to 1 actually made our unit tests much much slower. We have a library that consists of 115 icon svg components, and it runs it one at a time, taking forever. Also these are Angular projects |
Install SWC with
And add this to your
|
@flolu thanks for the great example. AFAIK swc doesn't check types either, so there shouldn't be much difference between swc and |
@Bessonov you are right, it is not a huge difference. But it's almost twice as fast in many cases |
Sadly, swc does not work in angular projects. And I also see very slow test times in simple tests. Is there not anything one can do about this? Even just go to an older jest version or something? |
Same issue here, i'm using it on a Nest.js project, but it still use ts-jest under the hood so.. Even basic tests like @cookernetes have shown takes 20 seconds ! I'm currently using the 29.0.3 version |
After config ts-jest to create-react app successfully, I saw a test case run 6s.
That's very slow. My jest config following the document: (ts|tsx)": "/node_modules/ts-jest/preprocessor.js"
My code
Result: PASS src/containers/test/App.spec.tsx (6.119s)
I searched some tutorials on the internet, there is a preprocessor.js file:
If I use this file, the test case runs on 3 -4s.
Can you explain me this problem? Does preprocessor.js of TS-Jest have more functionalities than that file as well?
The text was updated successfully, but these errors were encountered: