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

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

Closed
also opened this issue Jul 24, 2021 · 2 comments · Fixed by #11987
Closed

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

also opened this issue Jul 24, 2021 · 2 comments · Fixed by #11987

Comments

@also
Copy link

also commented Jul 24, 2021

🐛 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
@chadoh
Copy link

chadoh commented Sep 23, 2021

I came here to report the same error. This is the test I came up with to reproduce this:

test.concurrent('has a promise', async () => {
  await new Promise(r => setTimeout(() => r(true)))
})
test.concurrent('fails', () => {
  expect(true).toBe(false)
})

@also why is this labeled "Needs Repro"? Do you want me to send a PR with a failing test?

I'm not totally sure how to write a test for this, since we want one of the tests to fail (instead of two). Which means we want to write a test where "one test failing" means the test passes.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants