-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve testing coverage for the Jade CLI application #1805
Conversation
Current coverage:
|
|
This is excellent work. Thanks for this. To make this work on Windows, we should use the rimraf npm module in place of the |
@ForbesLindesay said:
A separate dep just for
I intentionally changed that because I would want my coverage to run even if my test failed.
This is understandable, but then there are platforms like Debian where you have to use |
👍 One of the best PRs I have come across here. |
Generally the coverage will fail if the tests fail, so I prefer only running coverage if tests pass. Yes, sadly we need a separate dep for |
This allows testing coverage for watching mode with istanbul.
@ForbesLindesay actually rimraf is already in devdeps so I don't need to add it. |
@ForbesLindesay rebased and changed. |
* coverage HTML that covers all the individual results. | ||
* | ||
* E.g. | ||
* $ cov-combine.js cov-pt[0-9]/coverage.json |
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.
BTW, I wanted to write
cov-combine.js cov-pt*/coverage.json
here but then JS recognized */
as end of comment block so...
We should see if we can get something useful merged in to Istanbul upstream to make this easier for other people to do (and reduce the amount of code we have to maintain as part of jade) Other than that one small point, this looks good. |
Unfortunately, istanbul is not as flexible as I would like it to be: 1. It does not support tracking JavaScript scripts spawned by `child_process.spawn()` or `child_process.exec()`. Therefore, it is necessary to execute separate istanbul instances for every command spawned. This leads to the second problem: 2. Istanbul does not support "concatenating" or appending coverage data. This means that, unlike gcov for C programs, when you run a new `istanbul cover` it overwrites the earlier data. To work around this, I made istanbul output data to cov-pt* directories with the initial `istanbul cover mocha` outputting to cov-pt0, and added a script to concatenate all the data together (with the istanbul API) and produce coverage/. It's not ideal, and if you have a better solution please file a ticket.
@ForbesLindesay thanks for the review. Merged. |
Improve testing coverage for the Jade CLI application
This PR can be understood to have two parts:
Improving test coverage
For the first part, I have added tests for:
--obj
option ofbin/jade.js
stdin
and thestdin()
functionreplace()
call ingetNameFromFileName()
Test coverage report
For the second part I had to use some "hacks" and workarounds, because, unfortunately, istanbul is not as flexible as I would like it to be:
It does not support tracking JavaScript scripts spawned by
child_process.spawn()
or child_process.exec()`. Therefore, it is necessary to execute separate istanbul instances for every command spawned. This leads to the second problem:Istanbul does not support "concatenating" or appending coverage data. This means that, unlike gcov for C programs, when you run a new
istanbul cover
it overwrites the earlier data.To work around this, I made istanbul output data to
cov-pt*/
directories with the--dir
option, and made the initial parent process output tocov-pt0/
rather thancoverage/
. Then, I added a script to concatenate all the data together (with the istanbul API) and producecoverage/
. It's not ideal, and if you have a better solution please point out the solution.There is also the problem for the watching mode test: when passing
SIGINT
(or^C
) to jade when it is still watching the file, the exit handler is not called, therefore terminating istanbul as well. There is not another way of cleanly kill the process while it is watching I can think of, so I have added commit b079489 which makesSIGINT
go through the exit handler. I do not expect it to change the behavior ofbin/jade.js
else than the return code, which callers would not depend on any way.To-do
With the changes applied, one can see that the coverage for
bin/jade.js
is not nearly as green aslib/
. This is a to-do list for future improvements of test coverage:Easier:
--obj
to a file with JSON data--obj
(not just locals)--out
Harder:
--help
works properly--path
SIGINT
when reading fromstdin