-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Output gets cut off if piped into another application #333
Comments
well we do write to both std{err,out}, so some of that is expected |
Why would it be expected that the output doesn't all get written? |
each stream should definitely finish writing, which version of node is this? there have been a few issues |
I'm using Node v0.6.12. If the tests all pass, then Mocha doesn't write anything to stderr, and the output is still cut off when I run it through a pipe. So I'm not sure being able to use both streams has anything to do with it. The docs for |
guess we need to add those callbacks back, we used to have them but I removed them after isaac mentioned stdout was sync now (must have missed the pipe thing), seems kinda weird to do both. |
I'm not sure when you removed these callbacks, but if it helps, I tried snagging older versions of Mocha, and this problem has existed since the oldest version available in npm (0.0.1-alpha1). |
i'll mark it as a bug |
On Ubuntu 11.10 and OSX 10.7.2 pipes worked fine. On windows7, node 0.6.10, powershell and command prompt we could reproduce the bug. When output was piped to more there was either no output or just the a period nondeterministically.
|
This issue has been inactive for over 1 month so I'm closing it. If you think it's still an issue re-open. - tjbot |
Did you test this before you closed it? The problem is still trivially reproducible with the steps described, with the latest version of Mocha in npm (1.1.0). I'd be happy to reopen the issue, but my "Reopen" button is grayed out, and when I hover over it, GitHub tells me "You don't have permission to reopen this issue". |
my bot closed it, but yeah everything looks fine for me |
shwaydogg already commented that it seems to work correctly on Ubuntu 11.10 and OSX 10.7.2. What OS and Node version are you using? I get the problem behavior every time on Windows 7 64-bit with Node 0.6.12 (and shwaydogg confirmed with Windows 7 and Node 0.6.10). I'd be happy to upgrade my Node if you're seeing no problems with a newer version. |
i doubt it has anything to do with node/mocha, just terminals / shells, unicode blah blah |
Seems likely, but I've tried reproducing the problem in a standalone app (without Mocha), and so far I haven't been able to. So there's probably some Node feature Mocha is using that behaves badly with pipes, but it's not obvious to me what that feature might be (and it's also not obvious whether it would be easier to fix it in Node, or work around it in Mocha). Here's what I know so far from my experiments:
Here's my test app, in case it's helpful:
Any thoughts on what sorts of things Mocha might be doing with its I/O that I'm not covering? It'd be good to narrow down where the problem is. |
i have this with a mocha fresh from npm on new node 0.8 64bit on Vista64 (yesyes :) where i fixed the path.existsSync warning, seems to work fine but im on windows for now and have no make to run tests (jake! :) mocha runs ok from cmd, nice colors etc but when calling mocha with node's child_process .exec or .spawn directly (and also through jake's .exec and using procstreams), then i get the warbled and unstable output mentioned above. it's same with the calling mocha js api from jake. i get this in standard cmd, in some third party Console2 and also in SublimeText's console (when cli calling a jake build task). i tried hacking/bypassing with my own reporter but ran into #323 (add arbitrary reporter) and so far failed in enabeling my reporter (index and needs a make/build?) |
In my case (Windows7 64) everything works fine in console, but when I invoke the same command via Node's exec or spawn, only part of message is displayed (e.g. all error messages are missing). This problem makes it impossible for me to run mocha from my coffee script's Cake file. |
Any solutions? Same problem here with node 0.8.4 and mocha 1.3.0 on Windows 7 64Bit, it's not possible to use mocha from cakefile or in combination with nodemon (as workaround for failing --watch on Windows) |
The problem is because mocha calls I believe that when std{out,err} are connected to a console, they are a There is a process.stdout.flush && process.stdout.flush();
process.stderr.flush && process.stderr.flush(); I don't have Node.js installed on Windows to try, but if @Honigbaum, @velesin, @Bartvds, or @joewhite want to see if this is a fix that works under Windows, they can edit the mocha.loadFiles(function(){
mocha.run(function(){
process.stdout.flush && process.stdout.flush();
process.stderr.flush && process.stderr.flush();
process.exit();
});
}); |
@dougwilson |
@Honigbaum you have pushed me to actually install node on Windows and figure it out :) I have inspected It's too bad that the pipes are a mocha.loadFiles(function(){
mocha.run(function(){
var draining = 0;
var exit = function(){ if (!draining--) process.exit(); };
if (process.stdout.bufferSize) {
draining += 1;
process.stdout.once('drain', exit);
}
if (process.stderr.bufferSize) {
draining += 1;
process.stderr.once('drain', exit);
}
exit();
});
}); Other solutions are to not actually call |
As of mocha version 1.3.2, the workaround above now replaces the code in bin/_mocha line 322 with the following: mocha.run(function(){
var draining = 0;
var exit = function(){ if (!draining--) process.exit(); };
if (process.stdout.bufferSize) {
draining += 1;
process.stdout.once('drain', exit);
}
if (process.stderr.bufferSize) {
draining += 1;
process.stderr.once('drain', exit);
}
exit();
}); |
I have version 1.4.2 and am just now beginning to experience this issue... :/ |
i'll have a closer look at this soonish, kinda silly that we have to do this at the user level but hey |
And if it helps, replacing the above mentioned lines does solve the problem. |
keep in mind this needs to work for 0.4.x 0.6.x and 0.8.x |
0.4.x i imagine we can phase out soon though |
Same problem with 1.6 ... Would be happy if there is a solution in one of the next versions |
@stevenvachon |
@dougwilson Yep, but if your solution were implemented, |
In 0.11, you can actually still exit with an exit code without the need to call |
@dougwilson OK, so is @travisjeffery's patch good? With caveats? Can you summarize? :D |
The patch just changes the issue instead of resolving it. The patch just needs to be changed to look like #333 (comment) . Let me know if you want me to send a PR and I can do it pretty quickly. |
@dougwilson Sure, thanks. |
Done at #1440 . I'm just waiting to see if Travis CI says green, since the test suite doesn't actually work on Windows. |
Hello guys, over at node-sass, we are also experiencing the same issue. Any updates? Related: sass/node-sass#506 and http://help.appveyor.com/discussions/problems/1091-npm-test-always-fails. Note: we tried @stephenmathieson's suggestion and used |
@am11 solution's code: https://github.com/mochajs/mocha/pull/1440/files |
@am11 it was merged here, but just hasn't yet been released to npm. |
@dougwilson, thanks for fixing this issue in mocha. 👍 Over at node.js, they have fixed it in 0.12 branch, but yet to backport to 0.10.x branch: nodejs/node-v0.x-archive#7196 (see the late comments). Not sure if/ever it will land in 0.10.x branch. |
I doubt they'll ever backport it to 0.10. |
Fix has been shipped ^^ |
Looks like this is failing now on node 7.2.1. The |
Use similar method as in mochajs/mocha#333
If I run my Mocha tests directly from the command line, they run fine, and the output displays with no problems. But if I try to pipe Mocha's output to another program, the output doesn't all get there; only the beginning of the output ever makes it into the pipe.
I've seen this in several manifestations, but it's easy to reproduce just from the command line. I've reproduced this on two different computers, both running 64-bit Windows 7, the latest version of Node.js installed from the Web site, and the latest Mocha installed with
npm install -g mocha
.If I create a file with just one test in it:
and run it from the command line, I see the expected output:
But if I pipe its output into any other tool, even something as simple as
more
, then Mocha's output is cut off. I only see the line of dots -- sometimes not even that. The summary line isn't shown.If there are failing tests, and you run STDERR through a pipe, then the test-failure information will be cut off:
I've also seen this behavior when running Mocha from my text editor (Sublime Text 2) and capturing the output into an output window (the output doesn't all appear); and when writing Node.js code that shells out to Mocha (using
child_process.exec
) and captures its STDOUT and STDERR (the output doesn't all get sent). I haven't seen any other app cutting off its output like this in any of these circumstances, but Mocha does it every time its output is a pipe.The text was updated successfully, but these errors were encountered: