-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
🐛 Bug Report
#10728 sets the exit code to 1 when tests log after teardown. This correctly terminates the process if run in non-watch mode. However, if you do jest --watch
then all tests are reported as passing, despite there being a warning:
Cannot log after tests are done. Did you forget to wait for something async in your test?
Additionally, I noticed that console.warn
and console.error
don't cause failures - is that intended? I'm also happy to open a dedicated issue if you prefer keeping things isolated.
To Reproduce
Steps to reproduce the behavior:
-
Given this test:
// sum.test.js const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); test('should fail in watch mode', () => { async function foo() { await delay(100); console.log('this should fail tests in watch mode too'); } foo(); expect(true).toBe(true); });
-
Run
yarn jest --watchAll
(or--watch
if running inside a git repo) -
Observe that Jest reports a passing test, although it does log a warning:
-
Now if you just run
yarn jest
, you'll see the process exits with exit code 1.
Expected behavior
Jest should report a test failure.
Link to repl or repo (highly encouraged)
https://repl.it/@NMinhNguyen/jest-playground#sum.test.js
Note: you'll need to run it in watch mode: yarn jest --watchAll
(--watchAll
since it's not inside a git repo).
envinfo
npx envinfo --preset jest
npx: installed 1 in 3.502s
System:
OS: Linux 5.4 Debian GNU/Linux 9 (stretch) 9 (stretch)
CPU: (4) x64 Intel(R) Xeon(R) CPU @ 2.30GHz
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
npmPackages:
jest: 27.0.0-next.3 => 27.0.0-next.3