jest icon indicating copy to clipboard operation
jest copied to clipboard

stdout and stderr are written to console out of sync

Open medikoo opened this issue 7 years ago • 9 comments

🐛 Bug Report

data streamed to process.stdout and process.stderr does not appear in sync.

It makes debugging in some cases difficult and very confusing e.g. I work with application where some parts, rely on console.log (so propagate debug logs to stdout) while some app dependencies output debug logs via popular debug library (which propagates logs to stderr)

Logs from both sources appear out of sync, which makes reliable debugging quite difficult.

To Reproduce

In empty project create some.test.js:

process.stdout.write("1\n");
process.stderr.write("2\n");
process.stdout.write("3\n");

After running jest output is as follows:

2
 FAIL  ./some.test.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/jest/node_modules/jest-cli/build/test_scheduler.js:256:22

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

Expected behavior

Output as:

1
2
3
 FAIL  ./some.test.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/jest/node_modules/jest-cli/build/test_scheduler.js:256:22

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.489s
Ran all test suites.

Env info

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i7-2760QM CPU @ 2.40GHz
  Binaries:
    Node: 10.7.0 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.1.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.4.1 => 23.4.1 

medikoo avatar Jul 19 '18 14:07 medikoo

Could you setup a repro so it's easier to approach this case?

thymikee avatar Jul 19 '18 15:07 thymikee

Could you setup a repro so it's easier to approach this case?

https://repl.it/@medikoo/stderr-stdout-sync-issue

Still it's not perfectly reliable, as behaves differently than in system terminal (but bug remains visible, as still output is out of sync). Also it runs Jest v22 and not latest 23 (not sure how I can bump it over there).

To reproduce locally is as easy as creating some.test.js file (with content as listed above) within some empty project folder, and running jest in it (no config or any other files are needed and assuming jest is installed globally).

medikoo avatar Jul 19 '18 15:07 medikoo

What is the status of this issue?

sunpietro avatar Mar 12 '21 09:03 sunpietro

Solution to this is probably for Jest to intercept process.stdout in the same way it does console.*. That way we can send the output to a reporter who can print it in a controlled fashion instead of every line of code being able to intercept

SimenB avatar Feb 27 '22 12:02 SimenB

Is it on the roadmap to also intercept process.stderr? That's what is the standard for most logging libraries, is to use stderr for logs.

CMCDragonkai avatar Jun 28 '22 02:06 CMCDragonkai

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 28 '23 03:06 github-actions[bot]

bump

medikoo avatar Jun 28 '23 07:06 medikoo

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 27 '24 08:06 github-actions[bot]

How can such terrible bug, be not handled for 6 years, phew..

medikoo avatar Jun 27 '24 08:06 medikoo