-
-
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(reporters): verbose reporter should not buffer writes #11054
Conversation
198d87c
to
044bdeb
Compare
I notice I'm also skipping a block of code that deals with printing and clearing status. I think the test I'm doing doesn't cover this situation. I'm using the verbose reporter with the in-band runner, but it is also possible for the verbose reporter to be used with the parallel runner. I'm guessing I can just leave that block while eliminating the buffering. Probably need to change the factoring around a bit though so I don't duplicate code. |
044bdeb
to
e8528eb
Compare
OK I put that block back. I didn't refactor for DRYness as the amount of code duplicated is relatively minimal. |
e8528eb
to
582331c
Compare
Maybe remove the |
Also, I think adding a test would be great. |
A rebase should fix CI. A test would be great, yeah 👍 |
@silverwind @conartist6 Can you rebase ? |
582331c
to
e18af6c
Compare
OK I've rebased. A test would be great, but it's not exactly an easy test to write... |
The nasty thing is that I don't think it's safe to spy on Long story short, I don't have the energy or will to get as involved as writing a test would be. If it breaks again it can be fixed again. Goodness knows it's been broken for long enough right now... |
We won't be merging PRs without tests associated, so if someone wants to see this fixed, please take this branch and add a test case. |
@cpojer That somebody would be me. Any thoughts on the difficulties I mention in writing a test that really verifies this functionality?
|
02de105
to
afc282e
Compare
OK, there's a test. I was wrong in saying the test couldn't monkey patch, it just has to monkey patch the monkey patch... |
@cpojer If you say there's formal requirements around testing could you share what they are so that I can update |
6ca944f
to
a2d0348
Compare
7223305
to
d8b8d66
Compare
d8b8d66
to
16c7118
Compare
@SimenB This branch is up to date again, tests are passing and can be verified failing by disabling the fix. Also there is not longer any need to modify the package to an |
I pushed up 2 commits - the first fixing a broken
Binding the function fixes it to actually fail because of missing output 🙂 The second commit just adds missing copyright headers |
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.
thanks!
@@ -2,8 +2,6 @@ | |||
"editor.rulers": [80], | |||
"files.exclude": { | |||
"**/.git": true, | |||
"**/node_modules": true, |
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.
what does this do? (I don't use vs code)
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.
ah, just saw
As a side note hiding all the build output from VScode is a pain, and again falls into the category of things I consider lying to developers. It wasted a bunch of my time because I couldn't tell that typescript watching was not working.
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.
Yeah it just makes the directory invisible. If your IDE is your primary way to see what's going on in the filesystem you might assume the directories really just don't exist, which they do. It's unnecessarily confusing.
Hmm, 2 thing.
|
E2E runner runs without tty, so I was fooled by running the test directly - original test approach works (and I added an assertion that the stream is not tty). So, altogether the diff I've pushed is diff --git c/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap w/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap
index f5bfd36dfb..9b6414ff5b 100644
--- c/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap
+++ w/e2e/__tests__/__snapshots__/consoleDebugging.test.ts.snap
@@ -1,6 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`console debugging with --verbose 1`] = ``;
+exports[`console debugging with --verbose 1`] = `
+ console.log
+ test
+
+ at Object.log (__tests__/console-debugging.test.js:17:11)
+
+`;
exports[`console debugging with --verbose 2`] = `
PASS __tests__/console-debugging.test.js
diff --git c/e2e/console-debugging/__tests__/console-debugging.test.js w/e2e/console-debugging/__tests__/console-debugging.test.js
index fbeff2a651..9d801e87b6 100644
--- c/e2e/console-debugging/__tests__/console-debugging.test.js
+++ w/e2e/console-debugging/__tests__/console-debugging.test.js
@@ -11,14 +11,17 @@ const stdoutWrite = require('../stdout-spy');
process.stdout.write = jest.fn(process.stdout.write);
test('verbose mode prints console output synchronously', () => {
+ // test only works consistently without tty
+ expect(process.stdout.isTTY).not.toBe(true);
+
console.log('test');
expect(stdoutWrite.text).toMatchInlineSnapshot(`
-" console.log
- test
+ " console.log
+ test
- at Object.log (__tests__/console-debugging.test.js:14:11)
+ at Object.log (__tests__/console-debugging.test.js:17:11)
-"
-`);
+ "
+ `);
});
diff --git c/e2e/console-debugging/jest.config.js w/e2e/console-debugging/jest.config.js
index 7e74c7cc61..87ce2c8889 100644
--- c/e2e/console-debugging/jest.config.js
+++ w/e2e/console-debugging/jest.config.js
@@ -1,3 +1,11 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+'use strict';
+
require('./stdout-spy');
module.exports = {
diff --git c/e2e/console-debugging/stdout-spy.js w/e2e/console-debugging/stdout-spy.js
index 6369652476..737acf1f46 100644
--- c/e2e/console-debugging/stdout-spy.js
+++ w/e2e/console-debugging/stdout-spy.js
@@ -1,4 +1,12 @@
-const originalStdoutWrite = process.stdout.write;
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+'use strict';
+
+const originalStdoutWrite = process.stdout.write.bind(process.stdout);
global.process.__stdoutWriteMock = global.process.__stdoutWriteMock || null;
diff --git c/packages/jest-reporters/package.json w/packages/jest-reporters/package.json
index dd0886f9dd..ee4bf4712b 100644
--- c/packages/jest-reporters/package.json
+++ w/packages/jest-reporters/package.json
@@ -14,6 +14,7 @@
"@jest/test-result": "^27.2.4",
"@jest/transform": "^27.2.4",
"@jest/types": "^27.2.4",
+ "@types/node": "*",
"chalk": "^4.0.0",
"collect-v8-coverage": "^1.0.0",
"exit": "^0.1.2",
diff --git c/yarn.lock w/yarn.lock
index 94e28baf81..7996e76ba4 100644
--- c/yarn.lock
+++ w/yarn.lock
@@ -2654,6 +2654,7 @@ __metadata:
"@types/istanbul-lib-report": ^3.0.0
"@types/istanbul-lib-source-maps": ^4.0.0
"@types/istanbul-reports": ^3.0.0
+ "@types/node": "*"
"@types/node-notifier": ^8.0.0
chalk: ^4.0.0
collect-v8-coverage: ^1.0.0 Somewhat surprised |
@conartist6 would love your thoughts on the final point above (extra output in e2e test). I think it might just be because I fixed the bug which made it explode, but not sure |
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'm not 100% on the terminology, by TTY you mean an interactive terminal with support for ansi control characters right? The alternative to a TTY then just a non-interactive terminal which just records/prints every character that goes by it. I don't know why that would be relevant though, as my code should deal entirely with what happens before the real output stream code happens anyway, which you noticed in noticing that the test was not doing any real output though it was still passing. So looking over the updated output I agree with you that the current snapshot is correct. And the lack of bind in my spy definitely was creating undefined behavior, so it certainly looks to me like you identified and fixed an issue. As to what you may have seen that contradicted that theory, I can't say. I certainly confused myself a lot as I was trying to come up with this. Once the bug is fixed I'm wiling to work on changing things so that the code doesn't rely on monkey patching at all.
@@ -2,8 +2,6 @@ | |||
"editor.rulers": [80], | |||
"files.exclude": { | |||
"**/.git": true, | |||
"**/node_modules": true, |
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.
Yeah it just makes the directory invisible. If your IDE is your primary way to see what's going on in the filesystem you might assume the directories really just don't exist, which they do. It's unnecessarily confusing.
global.process.__stdoutWriteMock = global.process.__stdoutWriteMock || null; | ||
|
||
/* | ||
This is a terrible hack to ensure that we monkeyPath stdoutWrite before |
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.
oops I misspelled this
yup 👍
Right, or piped to a file etc But cool, let's |
Thanks for your patience with us (me)! ❤️ |
Hooray! Thanks! |
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. |
Fixes #8208
See my investigation of that issue for more details.