-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Fix missing console log output in verbose mode #6871
Conversation
Exciting! Thank you so much for tackling it. I don't get why we have to mess with force color? |
@SimenB when the child streams switch from 'inherit' to 'pipe', process.stdout.isTTY / process.stderr.isTTY are no longer Another approach would be to have something like BufferedConsole ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the tests aren't passing in CI, locally I get
|
Can you run |
Codecov Report
@@ Coverage Diff @@
## master #6871 +/- ##
==========================================
+ Coverage 67.71% 67.72% +0.01%
==========================================
Files 247 247
Lines 9501 9504 +3
Branches 5 6 +1
==========================================
+ Hits 6434 6437 +3
Misses 3065 3065
Partials 2 2
Continue to review full report at Codecov.
|
Jest is presenting a bug when running in verbose mode that's impossible to use `console.log` outside a test file. Use logs inside the source modules is one of the main debugging actions to understand what is going on. References: jestjs/jest#2441 (comment) jestjs/jest#6871
@mjesun could you take a look? |
Maybe @rafeca has an opinion? :D |
A few things I forgot to mention, in case it helps:
|
@spion mind rebasing? 🙂 |
bd90227
to
e99bb25
Compare
e99bb25
to
7c83449
Compare
Rebased - the patch is now quite tiny because color stripping for snapshots has already been implemented... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the changelog as well 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love the feedback of some FB peeps, but this LGTM
cc @cpojer |
Bump. Would love to get this merged (and released). Super annoying :) |
Thanks so much for your work @spion! It's been years of this being a consistent issue. |
First of all, we don't need them. And secondly, this reduces the webpack output when running the tests. I would have liked to also reduce the stats that are printed, but because of the following bug, only the one of the two bundled files is printed: jestjs/jest#2441 Jest PR with a fix: jestjs/jest#6871 When the PR is merged, we could use this stats config for example: ```json { all: false, assets: true, colors: true, timings: true } ```
…160) First of all, we don't need them. And secondly, this reduces the webpack output when running the tests. I would have liked to also reduce the stats that are printed, but because of the following bug, only the one of the two bundled files is printed: jestjs/jest#2441 Jest PR with a fix: jestjs/jest#6871 When the PR is merged, we could use this stats config for example: ```json { all: false, assets: true, colors: true, timings: true } ```
* master: (24 commits) Add `jest.isolateModules` for scoped module initialization (jestjs#6701) Migrate to Babel 7 (jestjs#7016) docs: changed "Great Scott!" link (jestjs#7524) Use reduce instead of filter+map in dependency_resolver (jestjs#7522) Update Configuration.md (jestjs#7455) Support dashed args (jestjs#7497) Allow % based configuration of max workers (jestjs#7494) chore: Standardize filenames: jest-runner pkg (jestjs#7464) allow `bail` setting to control when to bail out of a failing test run (jestjs#7335) Add issue template labels (jestjs#7470) chore: standardize filenames in e2e/babel-plugin-jest-hoist (jestjs#7467) Add node worker-thread support to jest-worker (jestjs#7408) Add `testPathIgnorePatterns` to CLI documentation (jestjs#7440) pretty-format: Omit non-enumerable symbol properties (jestjs#7448) Add Jest Architecture overview to docs. (jestjs#7449) chore: run appveyor tests on node 10 chore: fix failures e2e test for node 8 (jestjs#7446) chore: update docusaurus to v1.6.0 (jestjs#7445) Enhancement/expect-to-be-close-to-with-infinity (jestjs#7444) Update CHANGELOG formatting (jestjs#7429) ...
I think we hit this bug yarnpkg/yarn#6042 :( |
Removing |
Thanks @spion, appreciated! |
released as alpha.9 ( |
@spion this seems to work really well, thank you so much! While looking at some other code, I noticed that #7408 (which introduced worker support) does not include this - do you think it needs to? |
I'm not sure if its needed - I guess I should have added a proper test to the PR 😞 - but it seems to be like after the refactor the pipe option no longer gets passed all the way to the process based workers. |
* fix missing logs * calculate FORCE_COLOR * always force_color=0 from runJest * strip ansi codes from buggy version of supportsColor * jest-worker test: add FORCE_COLOR env var * address style issues * update changelog * Update CHANGELOG.md * nohoist seems unnecessary
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This PR fixes missing / overwritten console.log output in verbose mode.
The monkey-patch of stderr and stdout streams' write methods that clears and rewrites the status report at the bottom is not used when streams are in "inherit" mode. Because of that, live unbuffered output from the child workers gets overwritten by subsequent write instructions.
The multi-worker (parallel) runner is used in watch mode, which force-sets runInBand to false when there are 2 or more tests to run. Additionally, its combined with a regular streaming console (not a buffered one) when verbose is set to true.
Therefore the test case that can be used to reproduce the issue is configured with
{verbose: true}
, runs in watch mode and contains two tests:https://github.com/spion/jest-logging-repro
To make sure the patched version receives those stdout/stderr writes, its necessary to switch the child processes streams from "inherit" mode to "pipe" mode. This way the process outputs are available as streams in the child process instead of directly going to the main stdout/stderr. The streams are then piped manually to the parent process, which ensures the right
write
instruction gets called.In most cases, the right test behavior is preserved by passing FORCE_COLOR with the right value as an environment variable to the child process, and setting it to 0 in runJest.
However,This has been done in the mean time since I submitted this PR.istanbul-lib-reporter
uses an old version ofsupports-color
which incorrectly implements support for the FORCE_COLOR environment variable. Therefore I updated a few of the snapshot tests to strip ansi codes manually themselves from the coverage reports.Fixes #2441
Test plan
WIP: I will try to add my repro case (except with runInBand = false) to the e2e test suite. Any other thoughts on tests welcome. Would like some feedback before I proceed further.