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.

Jest doesn't always try to run test suites in parallel

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Repro here: https://github.com/gsteacy/jest-bug-repro. Running npm test is sufficient. Ignore the test failure. I’m using the same repro for multiple bugs.

The problem (assuming this is not by design) is not consistently reproducible. For the repro given, Jest runs both test suites in parallel when the cache is ignored with --no-cache or if there is no cache available. Subsequent runs with a cache run the test suites serially.

For some larger projects I have (with more complex configurations) Jest will always run the tests in parallel unless told to do otherwise, but for other projects it won’t. I haven’t been able to find a pattern.

What is the expected behavior?

Jest runs the test suites in parallel as --runInBand has not been specified.

Please provide your exact Jest configuration

Defaults

Run npx envinfo --preset jest in your project directory and paste the results here

  System:
    OS: Windows 8.1
    CPU: x64 Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz
  Binaries:
    Node: 6.13.1
    Yarn: 1.3.2
    npm: 3.10.10
  npmPackages:
    jest:
      wanted: ^22.4.2
      installed: 22.4.2

I have also tried it with Node 8 and there is no apparent difference in behaviour.

  System:
    OS: Windows 8.1
    CPU: x64 Intel(R) Core(TM) i7 CPU         920  @ 2.67GHz
  Binaries:
    Node: 8.10.0
    Yarn: 1.3.2
    npm: 5.6.0
  npmPackages:
    jest:
      wanted: ^22.4.2
      installed: 22.4.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

19reactions
thymikeecommented, Apr 23, 2018

Create at least 21 test files and invoke with --maxWorkers=4 to run tests on 4 threads for example. That should be enough to trick Jest into running your tests always in parallel.

17reactions
gae123commented, May 18, 2019

Not sure whether this is a very recent regression somewhere in the stack, but I just discovered that around upgrading to 24.8.0, I had to remove --detectOpenHandles if I wanted tests to run in parallel. This was not the case until very recently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run Jest tests sequentially? - Stack Overflow
Yes: it ensures within test suites/files that the order works, but the files themselves run in an order chosen essentially for parallelization ...
Read more >
How to run Jest tests sequentially - Code with Hugo
The --runInBand or -i option of the Jest CLI allows you to run tests sequentially (in non-parallel mode). The final command will look...
Read more >
Jest CLI Options
You can run jest --help to view all available options. Many of the options ... It is possible to run test suites by...
Read more >
Jest Sequential & Parallel Execution | Playwright - Part 20
Jest Sequential & Parallel ExecutionIn this video, we'll learn how to run a playwright test script in sequential and parallel.
Read more >
TestNG vs Jest comparison of testing frameworks
How to run parallel tests on your CI server to execute 1-hour test suite in 2 minutes? Do you wait 15 minutes or...
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