Do you want to request a _feature_ or report a _bug_?
Bug
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.
When a tests is not running in parallel, stdout messages printed by the test are not shown until the test body is finished and the event loop can be processed further.
https://repl.it/@sergey_simonchik/delayed-output-from-tests
test('test', () => {
process.stdout.write('Hello\n');
compute(5000);
});
function compute(millis) {
const start = Date.now();
while (Date.now() < start + millis) {}
}
What is the expected behavior?
Hello message is shown in console right away.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
jest: 22.0.5
node: 9.2.1
Use --verbose to avoid the buffering.
Nope, --verbose doesn't help:
$ ./node_modules/jest/bin/jest.js --verbose __tests__/test.js
PASS __tests__/test.js (5.291s)
✓ test (5001ms)
Hello
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.703s, estimated 6s
Ran all test suites matching /__tests__\/test.js/i.
Looks like it's caused by using setTimeout in https://github.com/facebook/jest/blob/v22.0.5/packages/jest-cli/src/reporters/default_reporter.js#L83
I wonder if https://github.com/facebook/jest/blob/4bcfe19b89b445bec793ba0a2ac815d117fa8098/packages/jest-cli/src/reporters/verbose_reporter.js should override stream.write?
Any news about this? Facing the very same problem
I'm finding it impossible to debug an infinite loop in my code because I can't get incremental console output.
Node: v10.8.0
Jest: 23.5.0
Okay, after trying _wayy_ too many things, I found a workaround for my issue: jest --useStderr.
Same problem here, this is quite the issue because if something is causing Jest to hang and you want to debug it, adding some logs before it doesn't work as they don't get printed.
Struggling with this. Hitting backend and yet my tests are saying they only took 1ms and console logs are outputting at the very end.
Most helpful comment
Okay, after trying _wayy_ too many things, I found a workaround for my issue:
jest --useStderr.