jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.05k stars 6.43k forks source link

stdout and stderr are written to console out of sync #6718

Open medikoo opened 6 years ago

medikoo commented 6 years ago

πŸ› 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 
thymikee commented 6 years ago

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

medikoo commented 6 years ago

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).

sunpietro commented 3 years ago

What is the status of this issue?

SimenB commented 2 years ago

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

CMCDragonkai commented 2 years ago

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.

github-actions[bot] commented 1 year ago

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.

medikoo commented 1 year ago

bump

github-actions[bot] commented 2 months ago

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.

medikoo commented 2 months ago

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