question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
SimenBcommented, Feb 23, 2022

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?

1reaction
fabbcommented, Feb 23, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found