-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
useage with mocha --watch #310
Comments
The coverage data gets written on process exit, so basically it's not usable for Coverage of a watch session is fairly useless anyways. |
I figured that, but it works with karma with the coverage plugin because karma is managing the coverage status. Is it possible to create a JS API for getting and resetting coverage snapshots, I could then call it in my mocha (or other test framework) afterAll hooks |
I'm after a new coverage result each watch cycle, not the union of all the coverages |
Actually, it is because karma is managing the file watching and full test lifecycle. It knows when to delete coverage and start over at the beginning of a run, when to combine the collected coverage at the end of the run, etc. NYC doesn't have that kind of insight into the underlying test lifecycle of the bins it launches. |
Might make sense as another open source tool you run in parallel with karma and nyc. I think it might beyond our scope -- we try to be fairly tool agnostic. |
I think this goes back to splitting up NYC into reusable parts. Specifically, gathering reports and combining them should be separate from the spawn-wrap instrumentation/write-on-exit bit. With just those two things split out it would be pretty easy to write a |
@graingert I ran into this as well. I'm using Visual Studio Code, and I installed an extension called Save And Run with the following settings: "saveAndRun": {
"commands": [
{
"match": "\\.js$",
"cmd": "npm test"
}
]
} Maybe you can do the same on your IDE with a similar plugin (or a set of plugins). Actually this approach has one advantage since you can test specifically what you just modified relatively easily. With Atom, you can use |
curious if anyone has found a good work around / solution for this. Would love to have my coverage update in real-time via mocha --watch. |
I've been thinking about this in the context of AVA. I think the test runner needs to provide the coverage reports. In AVA's case, since each test file runs in a new process, and since nyc combines multiple coverage reports into the final report, AVA would have to remove reports for previous test runs. Mocha would have to do something similar to clean up previous runs, but that's probably harder since there's only a single process. |
I've written mochista that does exactly this. |
@laggingreflex this is really cool 👍 any interest in potentially merging this into the istanbuljs organization? Should this be part of |
@laggingreflex @graingert I think mochista outlines a pretty good approach -- @laggingreflex would happily add a tutorial to https://istanbul.js.org/ showing off your library, would love a pull request if you have the time. |
@laggingreflex Nice work on mochista, maybe I'll give it a try. For anyone else who's looking for any easy solution, the following is working well for me.
It's a full restart of nyc and mocha so it runs a little slower than |
@cklanac that's really slick 👍 if you have a few moments, and feel like making an OSS contribution to the Istanbul project, it would be awesome to add some documentation regarding this approach here: https://github.com/istanbuljs/istanbuljs.github.io Maybe a tutorial along the lines of "Watching for Test Coverage Changes with Nodemon"? |
How can I use nyc with mocha --watch?
When run under nyc, mocha --watch doesn't quit and so I don't ever get to see the coverage.
The text was updated successfully, but these errors were encountered: