-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 some reporter / logging issues. Fixes #392 #415
Fix some reporter / logging issues. Fixes #392 #415
Conversation
Do we need visual tests? As I understand, those are supposed to be executed and completed manually. |
I think it's a good idea. I wouldn't make the part of the build. Just something we can run through before cutting a release to make sure things look right |
It's just I'm sure those tests will be forgotten often. Why can't we have automatic tests for comparing output? |
We will remember when we go to cut a release. Even so I don't think that's a big deal, these aren't mission critical tests.
Because what is output to the stream does not reflect what you actually see. Not every terminal emulator obeys the full set of ansi codes in the same way (here is just one example). A set of visual tests let us quickly check things look right locally and on whatever VM's we have available. |
This is how mini reporter looks now (lorem ipsum content is being generated as Terminal.app on OSX is problematic (I'm running Yosemite, there is reason to believe it's fixed on newer versions). I haven't tested on Windows. |
e2bffae
to
2969796
Compare
I'd appreciate some help figuring out the last of the kinks in this from anyone who knows something about terminal cursor manipulation. I'm not sure where things are going wrong. Here's what works:
To test, use The Note // @Qix- @vdemedes @floatdrop @sindresorhus |
@jamestalmage Why not use var logUpdate = require('log-update');
var text = '';
var i = 0;
setInterval(function () {
text += Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
}, 150);
setInterval(function () {
logUpdate(text + '\n\n ' + i++ + ' passed');
}, 50); |
@ecowden - darn. That's the same crap I get on Yosemite. I was really hoping to be able to blame that on an old OS. The Using logUpdate only works if you can clear the entire text. Right now the algorithm tries to do the following: A: New status update.
This is basically identical to B: New log output
A is pretty easy, a solved problem with B has proven difficult. Especially if what they write to the console does not end with a line terminator ( |
The latest push looks good on everything I've tried except
|
61b5b9f
to
f513f40
Compare
Finally figured out the bug. var ansiEscapes = require('ansi-escapes');
var str = '';
for(var i = 0; i < process.stdout.columns + 20; i++) {
str += String(i % 10);
}
process.stdout.write(str + ansiEscapes.cursorLeft);
setTimeout(function() {
// delay so you can see where the cursor is
}, 10000); In most terminal emulators the cursor ends up all the way to the left of the current (i.e. second) line: In |
I think I have found a decent cross platform solution. I'd like a number of people to pull this down and run:
|
@jamestalmage Awesome! All the visual tests passed perfectly now on Terminal.app OS X 10.11.2 (El Capitan). |
this._update(data); | ||
}; | ||
|
||
MiniReporter.prototype._update = function (data) { |
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.
Could you comment the code in this function?
Great research, @jamestalmage! |
22ed827
to
e594a2f
Compare
@vdemedes - updated with lots of code comments and clearer variable names. also, jamestalmage@328638d |
So, that last commit is maybe unnecessary: var through2 = require('through2');
var assert = require('assert');
var ct1 = 0;
var ct2 = 0;
var stream = through2(function (chunk, enc, cb) {
assert.strictEqual(ct1, ct2);
ct2++;
cb(null, chunk);
});
stream.pipe(process.stdout)
for (var i = 0; i < 160000; i++) {
stream.write(String(i % 10));
ct1++;
} It seems |
328638d
to
a5d5baa
Compare
All squashed up. What do you guys think, are we good to merge? |
This prevents interference between the mini logger and child processes that use `console.log`. The mini reporter previously used logUpdate which deletes lines previously written with the logUpdate API before writing a new one. This caused problems if lines from console.log were written inbetween logUpdate calls. It would delete the users log messages instead of the test status line. To fix this, we store the last written last log line, clear it, write the users log output, then restore the last log line. This keeps the miniReporter output always at the bottom of the log output. It also fixes an incorrect use of the `child_process` API. We were using the `stdio` option for `child_process.fork`, but that option is ignored (it is honored for just about every other method in that API). See: https://github.com/nodejs/node/blob/7b355c5bb30d7f9b38654fdb50e58dbd1dcd990a/lib/child_process.js#L49-L50 It also adds a set of visual tests which can be run via `npm run visual`. They must be run manually, and should be run as part of our pre-release process.
a5d5baa
to
3d7f036
Compare
Fix some reporter / logging issues. Fixes #392
Should we open a new issue about matching console.log output to the relevant test, discussed in #392? |
Done => #420 |
This is a partial fix for #392, and addresses a few other issues I found along the way.
stdio
option tochild_process.fork
. While that is a valid option for many methods in thechild_process
API, it is ignored forchild_process.fork
. Instead, we must pass thesilent: true
option and pipeps.stderr
andps.stdout
to console.process.stdout.isTTY
is now false in the child process. I modifiedtest-worker.js
to fake TTY support (but only if the parent process is a tty). I'm not sure that was necessary, however, without it, it might be difficult to test tty based libraries. Comments welcome.log-update
to address a bug inTerminal.app
. This should probably addressed upstream, but I want to verify this is a good fix before changingansi-escapes
/log-update
in ways that will affect lots of other applications.@sindresorhus @vdemedes - ready for review.