jest: [Bug]: `jest --bail` doesn't call `globalTeardown` function if test fails.

Version

29.5.0

Steps to reproduce

  1. Clone my repo at https://github.com/broyde/jest-teardown-bug
  2. yarn install
  3. yarn test
  4. You should see result like this:
 FAIL  ./jest.test.js
  Should call `globalTeardown` function before exit
    ✓ without bail (806 ms)
    ✕ with bail (659 ms)

  ● Should call `globalTeardown` function before exit › with bail

Optional steps (if you don’t like jest.test.js - you could run fail.test.js directly):

  1. yarn jest fail.test.js
  2. You should see failed result followed by:
**************************
TEARDOWN
**************************
  1. yarn jest fail.test.js --bail
  2. You should see the same fail, but without TEARDOWN log.

Expected behavior

yarn jest fail.test.js --bail outputs the TEARDOWN message, so yarn test passes:

$ jest --config={} jest.test.js
 PASS  ./jest.test.js
  Should call `globalTeardown` function before exit
    ✓ without bail (743 ms)
    ✓ with bail (696 ms)

Actual behavior

yarn jest fail.test.js --bail does not output the TEARDOWN message, so with bail case of yarn test fails:

$ jest --config={} jest.test.js
 FAIL  ./jest.test.js
  Should call `globalTeardown` function before exit
    ✓ without bail (750 ms)
    ✕ with bail (676 ms)

  ● Should call `globalTeardown` function before exit › with bail

    expect(received).toMatch(expected)

    Expected pattern: /TEARDOWN/
    Received string:  ""

      15 |   it('with bail', () => {
      16 |     expect(exec(['jest', 'fail.test.js', '--bail']))
    > 17 |       .toMatch(/TEARDOWN/);
         |        ^
      18 |   })
      19 | });
      20 |

      at Object.toMatch (jest.test.js:17:8)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        1.612 s, estimated 2 s
Ran all test suites matching /jest.test.js/i

Additional context

This report is about the same bug as automatically closed https://github.com/jestjs/jest/issues/10607. Here I’ve created a hopefully better example with test which actually checks the jest behavior by running failing test without and with --bail option.

You could also run this example on Repl.

Reproduces on different environments and nodejs versions.

Environment

System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
  Binaries:
    Node: 16.17.1 - /usr/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 8.15.0 - /usr/bin/npm
  npmPackages:
    jest: ^29.5.0 => 29.5.0

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 4
  • Comments: 23 (11 by maintainers)

Most upvoted comments

🙄