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

Slow jest tests on Windows #1299

Closed
Karql opened this issue Apr 27, 2019 · 20 comments
Closed

Slow jest tests on Windows #1299

Karql opened this issue Apr 27, 2019 · 20 comments
Assignees
Labels
blocked: retry with latest Retry with latest release or head. outdated type: bug

Comments

@Karql
Copy link

Karql commented Apr 27, 2019

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: kulshekhar/ts-jest#259 (comment))

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 kulshekhar/ts-jest#961 (comment)

Regards!

@ernie58
Copy link

ernie58 commented May 23, 2019

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

@jeneg
Copy link

jeneg commented Jul 17, 2019

+1 tests are super slow on windows, can we get some support on this?

@LiamDobbelaere
Copy link

LiamDobbelaere commented Jul 18, 2019

Colleague of @ernie58 here with some more info

It works fine if I use WSL with Debian and node on it.
My node versions are the same on WSL and my Windows machine (10.15.3)
Jest 24 has a specific ticket on performance issues on their github jestjs/jest#7811

Since the tests also run fast on our Linux build agents, this seems like something Windows specific?

@jeneg
Copy link

jeneg commented Jul 19, 2019

@TomDobbelaere yes looks like Windows specific, on macOS it's OK too

@haskelcurry
Copy link

haskelcurry commented Jul 22, 2019

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:

var tsJestConfig = {
  isolatedModules: true,
  ...

Worked for my team, thanks!

@tmtron
Copy link

tmtron commented Jul 25, 2019

Maybe not directly related but a friendly reminder, to check your antivirus software.

In my case the new IntellIJ version has added some exclusions to Windows Defender and it has speed up my tests by over 30%.
see: Antivirus Impact on Build Speed

@evtk
Copy link

evtk commented Sep 23, 2019

Any updates on this? I had the above working for NX 7.x, but upgrading now to 8.5 and coming across this issue again. @FrozenPandaz I believe there is still no way to pass the isolatedModules flag to the builder (without the hack?)

@jdpearce jdpearce added the blocked: retry with latest Retry with latest release or head. label Sep 23, 2019
@jdpearce
Copy link
Collaborator

I made a recent change to merge the jest.config.js globals with the ones set in the jest builder. You should be able to add the isolatedModules flag there and have it persist now.

Can someone (@Karql, @evtk, @mtuzinskiy...) try again? I don't have a Windows machine to hand to try this out :(

@evtk
Copy link

evtk commented Sep 23, 2019

@jdpearce I have just tested it, but it doens't look like it is merged. Without the hack the tests are still very very slow. This is my jest.config.js:

module.exports = {
  testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
  transform: {
    '^.+\\.(ts|html)$': 'ts-jest'
  },
  resolver: '@nrwl/builders/plugins/jest/resolver',
  testEnvironment: 'jest-environment-jsdom-thirteen',
  moduleFileExtensions: ['ts', 'js', 'html', 'json'],
  collectCoverage: true,
  coverageDirectory: 'reports/coverage/',
  coverageReporters: ['html', 'cobertura'],
  setupTestFrameworkScriptFile: './test-setup.ts',
  globals: {
    'ts-jest': {
      tsConfig: '<rootDir>/tsconfig.spec.json',
      stringifyContentPathRegex: '\\.html$',
      astTransformers: [require.resolve('jest-preset-angular/InlineHtmlStripStylesTransformer')],
      isolatedModules: true
    },
  },
  testPathIgnorePatterns: ['node_modules', 'tools/schematics', '-e2e'],
  transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
  snapshotSerializers: [
    'jest-preset-angular/AngularSnapshotSerializer.js',
    'jest-preset-angular/HTMLCommentSerializer.js'
  ]
};

I did add it correct right?

@jdpearce
Copy link
Collaborator

@evtk - apologies, the change I made hasn't actually been released yet! That jest.config.js looks good to me, but the globals are probably still being overridden :(

Should be fixed in 8.5.1 though.

@evtk
Copy link

evtk commented Sep 23, 2019

no problems, it's great you took the effort to fix this. Will wait for the 8.5.1 though!

@jdpearce
Copy link
Collaborator

@evtk - we've just released 8.5.1, can you try again? 🙏

@evtk
Copy link

evtk commented Sep 24, 2019

wel this is interesting.. no matter what if I do or don't add the isolatedModules: true flag in the globals, jest seems to be somewhat quicker anyways!

maybe is isolatedModules: true now a default? Though testing this on our CI server (windows devops) doesn't seem to do the trick. Too slow.

edit: nah.. I tested some more and the global config from jest.config.js seems still overriden.

@jdpearce
Copy link
Collaborator

@evtk 😞

I'll have to investigate this again, thanks for giving it a try!

@erik-slack
Copy link

My team is also experiencing this problem on Windows machines. I temporarily fixed it using the isolatedModules workaround. Upgrading to Nrwl 8.5.1 from 8.5.0 didn't solve it for us either.

@evtk
Copy link

evtk commented Oct 5, 2019

@erik-slack check-in on this issue to get updates on merging the jest global config.

@jdpearce
Copy link
Collaborator

With this PR merged into Jest, it should now be possible to set globals and have them persist.

As a result, I'm going to close this issue for now. I'd suggest raising another issue if there is something else that can be done about this in Nx.

Thanks to all for contributing on this thread. 👍

@luchsamapparat
Copy link
Contributor

luchsamapparat commented Dec 3, 2019

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

@ahnpnl
Copy link
Contributor

ahnpnl commented Apr 21, 2020

FYI: kulshekhar/ts-jest#1549 will be in alpha version of ts-jest (possibly today). You can test the alpha version and give some feedbacks for kulshekhar/ts-jest#1115

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: retry with latest Retry with latest release or head. outdated type: bug
Projects
None yet
Development

No branches or pull requests