Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
medikoo opened this issue Jul 19, 2018 · 7 comments
Open

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

medikoo opened this issue Jul 19, 2018 · 7 comments

Comments

@medikoo
Copy link

medikoo commented Jul 19, 2018

🐛 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 medikoo changed the title stdout and stderr logs are written out of order stdout and stderr are written to console out of sync Jul 19, 2018
@thymikee
Copy link
Collaborator

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

@medikoo
Copy link
Author

medikoo commented Jul 19, 2018

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
Copy link

What is the status of this issue?

@SimenB
Copy link
Member

SimenB commented Feb 27, 2022

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
Copy link

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
Copy link

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 github-actions bot added the Stale label Jun 28, 2023
@medikoo
Copy link
Author

medikoo commented Jun 28, 2023

bump

@github-actions github-actions bot removed the Stale label Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants