nx: Slow jest tests on Windows
Expected Behavior
Tests are execetued fast on Windows
Current Behavior
Tests are exectued slow on Windows
Failure Information (for bugs)
Problem is with ts-jest which from version to version become slower and slower. (I’ve written about it here: https://github.com/kulshekhar/ts-jest/issues/259#issuecomment-485784109)
Steps to Reproduce
I’ve made sample repo to demonstrate the problem https://github.com/Karql/angular-nx-slow-tests
Please read the README.md - every thing is in it.
Other
Only one work around I’ve found is set isolatedModules: true in ts-jest config.
But for now there is now way to pass this option to JestBuilder
https://github.com/nrwl/nx/blob/625b2837a806e02709bdbe7b45ce3b131760448c/packages/jest/src/builders/jest/jest.builder.ts
To achieve it I’ve made hacky post install script which add this options:
const fs = require('fs');
const path = require('path');
// WORKAROUND for performance issue with ts-jst on windows
// https://github.com/kulshekhar/ts-jest/issues/259
var jestBuilderPath = path.join(__dirname, "..", "node_modules", "@nrwl", "builders", "src", "jest", "jest.builder.js")
let jestBuilder = fs.readFileSync(jestBuilderPath, { encoding: 'utf8' });
if (jestBuilder.indexOf("isolatedModules") < 0) {
jestBuilder = jestBuilder.replace("var tsJestConfig = {", "var tsJestConfig = {\n\t\t\tisolatedModules: true,");
fs.writeFileSync(jestBuilderPath, jestBuilder);
}
Do you have any idea how to fix it?
In jest 24 there is native support for type script: https://jestjs.io/blog/2019/01/25/jest-24-refreshing-polished-typescript-friendly maybe this is the way? Please read the opinion one of the main ts-jest contributors https://github.com/kulshekhar/ts-jest/issues/961#issuecomment-458294885
Regards!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 31
- Comments: 20 (2 by maintainers)
Any updates on this? Btw, if anybody wants to make the workaround that Karql mentions, by hand:
node_modules/@nrwl/jest/src/builders/jest/jest.impl.ts:Worked for my team, thanks!
We have the same problem. tests run under 20s on my macbook pro, but take 300 seconds on my colleagues windows PC since upgrading nx and Jest 24
Just a heads up for everyone in this thread: this change is not yet published in a release
Look for “[jest-config] Merge preset globals with project globals (#9027)” in the changelog to see, if it is released and of which version the change ist be a part of
@erik-slack check-in on this issue to get updates on merging the jest global config.
@EvtK 😞
I’ll have to investigate this again, thanks for giving it a try!
no problems, it’s great you took the effort to fix this. Will wait for the 8.5.1 though!