Open MitMaro opened 8 years ago
Some more information. The reports are written on the process exit event but the docs state that
you must only perform synchronous operations in this handler. (source).
Since "the console functions are asynchronous unless the destination is a file" (source) this causes the problem with the truncated output. The node process will exit early before the console output is completely written.
this is such a pain in the ass! at first I thought that something was wrong with my tests that caused istanbul to die silently in the middle, but then, after investigating what was actually going on I came to the same conclusion as @MitMaro (although, he obviously did a much more thorough investigation)
This is probably a better issue to watch. Looks like a lot of CLI tools are breaking in Node 6 without a viable workaround. Guess we all need to wait for a solution to land in Node.
Another note, although I didn't test the new alpha, I did pick through the code and it looks like the issue would still be present.
@MitMaro I think that if Node.js fixes a long standing bug and that causes a lot of tools, that do what they shouldn't, to break I do not think that it's Node that needs to come up with a solution, but those tools need to adapt. If you must not do anything asynchronous in the exit handler (which makes perfect sense to me), then don't, deal with it, think of a better way to structure your app. Istanbul needs to be fixed, not Node.js, imho.
I agree, it should be up to the various tools that use the broken behaviour to fix the problem. However, from reading the issues on the Node project, there doesn't seem to be a viable way to fix the problem at the moment as Node doesn't currently have a way to wait for (or force) stdout
and stderr
to flush on exit. There is some talk of adding another exit function (os.exit
or similar) that would flush stdout and stderr.
There is a beforeExit
event on process that does work with Istanbul (I tested locally) however it breaks some of the other functionality that depends on process.exit
being called. This would require a fair bit of refactoring of the code base to not use process.exit
. I think this is something that should be taken into account for the current alpha branch.
As an aside isaacs has stated in a comment that perhaps this is something that Node may need to fix as there are many tools have used this broken behaviour for some time.
Unfortunately the Node docs say nothing about the exact behavior of `process.exit (all they say is "Ends the process with the specified code."), so users had no choice but to assume the observed behavior was expected. Since that behavior remained consistent for several years, it's hard to blame the users. On the other hand, I'm wondering how such a huge breaking change made it past the Node test suite.
In any case, there is a temporary fix.
Thought I already posted this, but this has been mostly fixed in Node v6.2.1. There is an outstanding issue that is tracking the overall problem.
Problem
The text reporter has truncated output in Node 6.
Minimal Test Case
Test case repo
Expected Output
Result of running with Node v4.4.4 and v5.11.1
Actual Output
Result from running in Node 6.1.0
Investigation
I drilled down to
lib/report/text.js:228
andtext
at this point contains the complete expected output. So it seems there is an issue with Node 6 andconsole.log
. After some research I came across this issue. If you read through the comments it comes down to a change in libuv around non-blocking I/O with stdout.On a suggestion found in the linked issue above, I changed
lib/report/text.js:228
to instead be the following, which apparent forces stdout to be blocking and Istanbul works as expected. I am not sure if this is the correct way to fix the issue, but it does show that stdout not blocking, to be the issue.System
Notes
It is possible that the above test case will pass if there isn't enough output.