[Feature]: Separate jsdom instances for parallel running test suits to avoid flakiness
See original GitHub issue🚀 Feature Proposal
Add an option to use a jsdom instance per test suite to avoid test flakiness when test suites interfere with each other (e.g. both use localStorage
).
Motivation
Currently when two test suites read/write localStorage
in their executed application code, it might cause flaky tests because the tests use a shared jsdom instance and thus shared localStorage. Clearing localStorage in beforeEach
does not solve the issue. —runInBand
solves the issue but slows down test execution massively (e.g. 14min instead of 7min in our case). A clean solution would be to use separate jsdom instances for each test suite.
Example
No response
Pitch
Jest initializes the jsdom environment, so initializing environments per test suite needs to be done by Jest itself.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
The Value of Concurrency in Tests - Manning
To speed-up your tests, Jest can run them in parallel. By default, Jest will parallelise tests that are in different files.
Read more >Tips for Unit Testing Vue Components with Jest - Medium
Using Jest to unit test Vue.js components can be tricky. We need a separate Vue Test Utils (@vue/test-utils) scoped package in order to ......
Read more >Frontend testing · Testing guide · Development · Help · GitLab
We use Jest to write frontend unit and integration tests. Jest tests can be found in /spec/frontend and /ee/spec/frontend in EE. Limitations of...
Read more >Frontend testing standards and style guidelines - GitLab Docs
There are two types of test suites encountered while developing frontend code at GitLab. ... Jest uses jsdom instead of a browser for...
Read more >A Practical Guide to Testing React Applications ... - LambdaTest
A Test Runner is software that aids in running the tests of the React application either by an individual selection of React script...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We already instantiate per test suite (test file): https://github.com/facebook/jest/blob/491e7cb0f2daa8263caccc72d48bdce7ba759b11/packages/jest-environment-jsdom/src/index.ts#L34-L53
Sounds like JSDOM has some global state which interfere? Can you put together a reproduction which shows the issue?
Hm, you are right, writing/reading localStorage in separate test suites works fine in a test project: https://github.com/fabb/jest-jsdom-flaky
So the flakiness in my project needs to be caused by something else, I need to investigate further. Sorry to bother you.