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

What is your average running time for React Testing Library tests? #819

Closed
kensongoo opened this issue Nov 9, 2020 · 8 comments
Closed
Labels
question Further information is requested

Comments

@kensongoo
Copy link

We have just started using React Testing Library. The biggest issue that we are facing right now is the test takes very long to run. One simple integration test (testing the behavior of several components on a container) takes about 80s to 100s. The test running speed is equal or worse than our Cypress tests now.

What are the recommended ways to troubleshoot the running speed of the react testing library?

Also, what are the main culprits of slowness? Could it be component re-rendering issues?

What are your average test running speed?

@nickserv
Copy link
Member

JSDOM can be fairly slow, and some parts of testing library can be slow, but it's hard to tell without seeing the test. Could you post code for testing library and Cypress in comparison?

@kentcdodds
Copy link
Member

I'll add to what @nickmccurdy said by saying that you might consider using https://github.com/bahmutov/cypress-react-unit-test + https://github.com/testing-library/cypress-testing-library and you'll get basically the same experience just running in a real browser. Hard to tell whether it'll be faster though. The overhead of loading a real browser and the challenge of running in parallel is pretty significant.

@domarmstrong
Copy link

Stick console.times throughout your test suite and you can get an idea of which are the slow parts.

I've found ByRole queries can be in the region of 40x slower than some simpler equivalent ByText etc queries (but not always), so we are trying to only use ByRole when the semantics are significantly better (which they are in a lot of cases annoyingly, but still not always necessary).

Make sure you are using fake timers and not waiting for any realtime timers.

Also if using jest and running suites in parallel, I've found setting the max workers to 50% knocked 20% of our test suite run time, that could depend on the hardware you are using though and wouldn't affect running a single suite.

@dougbacelar
Copy link

Perhaps you could try disabling the isInaccessible checks on local environments and only running it on CI. Unsure how much that would help though.

If there is a specific component that takes too long to render and it is unrelated to your test, you could try mocking that. As long as it is tested somewhere else the tradeoff might be worth it.

@dougbacelar
Copy link

You might want to check the comments in this thread:

testing-library/dom-testing-library#820 (comment)

@nickserv nickserv added the question Further information is requested label Nov 21, 2020
@eps1lon
Copy link
Member

eps1lon commented Dec 7, 2020

Closing in favor of #820 where we discuss performance of *ByRole and potential workarounds. There is no useful answer to the average running time of your tests since that depends on the UI you render and what you test.

@eps1lon eps1lon closed this as completed Dec 7, 2020
@lpaulger
Copy link

lpaulger commented Jul 13, 2021

#820

I'm running into poor performance with react-testing-library and mock-service-worker libraries and trying to dig into the reason.

@eps1lon When I got into #820 I see not mention of *ByRole being discussed, perhaps it's a different ticket?

@kgregory
Copy link

@lpaulger It's this issue 820 (for dom-testing-library). @dougbacelar had linked it earlier, but when the issue was referenced in a subsequent comment by number it was linked to an issue in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

8 participants