Skip to content

failures in test.concurrent tests cause unrelated tests to failย #11691

@also

Description

@also

๐Ÿ› Bug Report

If a test.concurrent test fails while another test is running, both tests report as failing with the same error. This occurs even if the failing test test is skipped with --testNamePattern (related to #10790?).

To Reproduce

Steps to reproduce the behavior:

Given a test that takes a second to pass, and another test that fails immediately:

test('addition of 2 numbers', async () => {
  await new Promise(resolve => setTimeout(resolve, 1000));
  // succeeds
  expect(5 + 3).toBe(8);
});

test.concurrent('subtraction 2 numbers', async () => {
  // fails
  expect(5 - 3).toBe(3);
});

Jest reports that addition of 2 numbers failed due to an error in subtraction 2 numbers

(node:333) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
 FAIL  ./test.js
  โœ• addition of 2 numbers (1003 ms)
  โœ• subtraction 2 numbers (2 ms)

  โ— addition of 2 numbers

    expect(received).toBe(expected) // Object.is equality

    Expected: 3
    Received: 2

       7 | test.concurrent('subtraction 2 numbers', async () => {
       8 |   // fails
    >  9 |   expect(5 - 3).toBe(3);
         |                 ^
      10 | });

      at test.js:9:17
      at Object.<anonymous> (test.js:7:6)

  โ— subtraction 2 numbers

    expect(received).toBe(expected) // Object.is equality

    Expected: 3
    Received: 2

       7 | test.concurrent('subtraction 2 numbers', async () => {
       8 |   // fails
    >  9 |   expect(5 - 3).toBe(3);
         |                 ^
      10 | });

      at test.js:9:17
      at Object.<anonymous> (test.js:7:6)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 2 total
Snapshots:   0 total
Time:        2.079 s, estimated 3 s
Ran all test suites.

Even if only the addition test runs, it still fails due to an error in the skipped subtraction test:

> jest "--testNamePattern" "addition"

 FAIL  ./test.js
  โœ• addition of 2 numbers (1004 ms)
  โ—‹ skipped subtraction 2 numbers

  โ— addition of 2 numbers

    expect(received).toBe(expected) // Object.is equality

    Expected: 3
    Received: 2

       7 | test.concurrent('subtraction 2 numbers', async () => {
       8 |   // fails
    >  9 |   expect(5 - 3).toBe(3);
         |                 ^
      10 | });

      at test.js:9:17
      at Object.<anonymous> (test.js:7:6)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 skipped, 2 total
Snapshots:   0 total
Time:        1.94 s, estimated 2 s
Ran all test suites with tests matching "addition".

Expected behavior

The failure should only be associated with the specific test that returned the rejected promise. In the example above, only subtraction 2 numbers should fail.

Link to repl or repo (highly encouraged)

https://replit.com/@also/jest-concurrent-bug

envinfo

in the replit linked above:

  System:
    OS: Linux 5.8 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (4) x64 Intel(R) Xeon(R) CPU @ 2.30GHz
  Binaries:
    Node: 12.22.1 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.12 - /usr/local/bin/npm
  npmPackages:
    jest: 27.0.6 => 27.0.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      โšก