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

After upgrade to CRA 2.0, tests run very slow. #5304

Closed
Ektomorfik opened this issue Oct 5, 2018 · 27 comments

Comments

@Ektomorfik
Copy link

commented Oct 5, 2018

Is this a bug report?

I think so.

After upgrade to CRA 2.0 Jest tests run much slower than before.
I think it could be made by Jest 23

Did you try recovering your dependencies?

yes, but problem still exists

Which terms did you search for in User Guide?

Running Tests

Environment

Environment:
OS: Windows 10
Node: 8.11.2
Yarn: 1.10.1
npm: 6.4.1
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found

Packages: (wanted => installed)
react: ^16.5.2 => 16.5.2
react-dom: ^16.5.2 => 16.5.2
react-scripts: 2.0.3 => 2.0.3

Steps to Reproduce

Tests in previous version reloaded less than 1s. After upgrade to CRA 2.0 tests reload in about 3-4sec. Problec occurs even if I create new empty project

  1. create-react-app app
  2. npm run test

Expected Behavior

It should be faster :(

Actual Behavior

image

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

@Timer

This comment has been minimized.

Copy link
Collaborator

commented Oct 5, 2018

Did you use the Node test environment previously? We switched the default to JSDOM which has some overhead.

@Timer Timer added this to the 2.x milestone Oct 5, 2018

@Ektomorfik

This comment has been minimized.

Copy link
Author

commented Oct 5, 2018

I used default settings

@Ektomorfik

This comment has been minimized.

Copy link
Author

commented Oct 5, 2018

Maybe it would help a bit. Some time ago, I setup next.js project with Jest 23 and I had the same issue. I solved problem by downgrade Jest to 22.x.x.

@gaearon

This comment has been minimized.

Copy link
Member

commented Oct 5, 2018

cc @rogeliog is there a reason to expect slowdown in 23?

@rogeliog

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

I don’t think so, any ideas @SimenB @thymikee?

@SimenB

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

We've had reports of slowdown on windows, see e.g. facebook/jest#6783

We haven't been able to pin it down, though, unfortunately...

@thymikee

This comment has been minimized.

Copy link

commented Oct 5, 2018

IIRC this was slowing down watch mode a bit: facebook/jest#6647

@rogeliog

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

@SimenB do you know if the issue is only affecting windows?
@Ektomorfik do they also run slower when you run them in "non watch mode"(i.e CI=true npm run test)

@bugzpodder

This comment has been minimized.

Copy link
Collaborator

commented Oct 5, 2018

I've had cases where I saw a big slow down on mac and not on watch mode. Two snapshot tests took over 30 seconds to run (and time varies on different runs). Will test it a bit more today and see if i can file something.

@rogeliog

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

I set up a repo locally where I run 100 test suites to benchmark jest@21, jest@22 and jest@23. It seems that... All tests suites have this exact code.

describe('Simple assertions', () => {
  it('has a simple assertion', () => {
    expect(1).toBe(1);
  });

  it('using matchers', () => {
    expect({
      username: 'foo',
      password: '123456'
    }).toMatchObject(expect.objectContaining({
      username: 'foo'
    }));
  });
})

And I am running them all in non-watch mode. Jest@23 is running slower in my benchmark. After doing a lot of git bisect and I see a big performance hit introduced in this PR facebook/jest#5932... Checking out a version right before that PR performs way better, any thoughts @cpojer?

@SimenB

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

Hmmm, might be related to facebook/jest#6694

Maybe we should look into caching module lookups?

@Timer Timer modified the milestones: 2.x, 2.0.x Oct 5, 2018

@rogeliog

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

By "related", you mean that facebook/jest#5932 might be the part of the root cause of facebook/jest#6694?

@rogeliog rogeliog referenced this issue Oct 5, 2018
@SimenB

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2018

Kinda. My point was that resolution is probably slow as we do it for every single modules in every single test. So anything adding work to the resolution by definition is super-hot code, and thus suspectible to performance regressions. Especially FS stuff as that's notoriously slow on Windows

@Ektomorfik

This comment has been minimized.

Copy link
Author

commented Oct 6, 2018

@rogeliog - yes I tried do that. Problem still occurs :(

@someden

This comment has been minimized.

Copy link

commented Oct 11, 2018

Not only Windows. Test also run very slow inside node container, example:

$ cd ~/MyProject
$ docker run -p 3000:3000 -it --rm -v "$(pwd)":"$(pwd)" -w "$(pwd)" node:latest bash
$ yarn test
 PASS  src/__tests__/actions.test.js (17.432s)
 PASS  src/__tests__/reducers.test.js (18.061s)
...
@rogeliog

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

I've been investigating the issue and created facebook/jest#7110, but I don't think that is the specific reason for CRA... I'll keep investigating it.

@Ektomorfik

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

@rogeliog Thanks so much :)
@Timer - Is there opportunity to speed it up? I mean eg. downgrade jest, custom config etc?

@mcmillion

This comment has been minimized.

Copy link

commented Nov 14, 2018

@someden are you also noticing long startup times in a node container?

I'm in the process of upgrading to Babel 7 and I'm now running across this. Outside the container tests are fast (<1s a piece), inside the suite takes 20-30s to start, and then each test takes 15-20s.

@someden

This comment has been minimized.

Copy link

commented Nov 21, 2018

@eparizzi

This comment has been minimized.

Copy link

commented Dec 21, 2018

Fresh create-react-app (2.1.1).

 PASS  src/App.test.js
  √ renders without crashing (41ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        6.447s
Ran all test suites.

Watch Usage: Press w to show more.

So while the test actually seems to run pretty fast (41ms), the setup takes 6 seconds. Re-running doesn't make it faster.

Windows 10 x64, I7 4690K, SSD...

@lukaszczernal

This comment has been minimized.

Copy link

commented Jan 1, 2019

We also struggle with slow tests if we run:
react-scripts-ts test --env=jsdom
image

but if we run them with coverage flag they are way faster
react-scripts-ts test --env=jsdom --coverage
image

I understand that it should be the opposite :-)

We are running:
"react": "^16.2.0", "react-dom": "^16.2.0", "react-redux": "^5.0.6", "react-router-dom": "^4.2.2", "react-scripts-ts": "2.17.0", "enzyme-adapter-react-16": "^1.1.1",

@johnbowdenatfacet

This comment has been minimized.

Copy link

commented Jan 24, 2019

Confirmed, jest is running ~18 seconds with --coverage as opposed to ~28 seconds without... for 60 odd tests. Why so slow? And ~12 seconds with CI=true ...

@iansu iansu modified the milestones: 2.1.x, 3.x Mar 10, 2019

@petetnt

This comment has been minimized.

Copy link
Collaborator

commented Apr 23, 2019

Could someone check if the issue still persists with Jest 24, shipped with CRA@3

@marius-ionescu

This comment has been minimized.

Copy link

commented Apr 23, 2019

Hey, have just tested this now and yes, there is a huge improvement:
(running in band)
w 2.1.8
Test Suites: 3 skipped, 98 passed, 98 of 101 total
Tests: 35 skipped, 379 passed, 414 total
Time: 646.448s
(running with coverage does bring some improvement but not that much)

w 3.0.0
Test Suites: 3 skipped, 98 passed, 98 of 101 total
Tests: 35 skipped, 379 passed, 414 total
Time: 139.081s
I've got some statistics without running in band, but it's mostly around the same for 3.0.0.

So the bump to 3.0.0 seems to have fixed this issue for windows(windows 10, w node 11.9.0)

@petetnt

This comment has been minimized.

Copy link
Collaborator

commented Apr 24, 2019

That's awesome @marius-ionescu!

For everyone else: closing this as improved on 3.0.0, but do still post if having similar issues and we can re-open this one.

@SimenB

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2019

A bunch of performance improvements landed in 24.6.0, happy to see it translates to real gains!
https://github.com/facebook/jest/blob/4d3c1a187bd429fd8611f6b0f19e4aa486fa2a85/CHANGELOG.md#performance-2

@bugzpodder

This comment has been minimized.

Copy link
Collaborator

commented Apr 24, 2019

Thanks SimenB

@bugzpodder bugzpodder closed this Apr 24, 2019

@lock lock bot locked and limited conversation to collaborators Apr 29, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
You can’t perform that action at this time.