Skip to content
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

Code coverage of spawned processes #3190

Closed
tivac opened this issue Mar 23, 2017 · 10 comments
Closed

Code coverage of spawned processes #3190

tivac opened this issue Mar 23, 2017 · 10 comments
Labels

Comments

@tivac
Copy link

tivac commented Mar 23, 2017

Do you want to request a feature or report a bug?

Unclear, hopefully just a bug?

What is the current behavior?

Any node.js code run via the child_process module doesn't display any coverage information. .spawn() vs .fork() doesn't seem to matter.

https://repl.it/G9jH/0

What is the expected behavior?

I'd like to see coverage numbers from spawned node processes assuming that they were part of the project.

@aaronabramov
Copy link
Contributor

unfortunately it's not possible now because that will be very very hard to implement.

the coverage is generated by instrumenting the code that's being run with runtime coverage checks + exporting the results after the process is finished. This process is not generic at all, and since pretty much anything can be run as a child process, there's no possible way we can collect coverage from these processes.

@tivac
Copy link
Author

tivac commented Mar 23, 2017

Interesting, I assumed jest used nyc for coverage and that's able to provide coverage of spawned processes.

@aaronabramov
Copy link
Contributor

yeah, it's definitely possible and nyc is very generic and independent to do this. But in Jest i think we're a little far from it.
Our transformation (and instrumentation) logic heavily depends on jest environment and test configuration. It provides a lot of benefits, but also makes it hard to work on things like this one

@cpojer
Copy link
Member

cpojer commented Apr 11, 2017

Closing this as wontfix for now, it is unlikely we'll get to this.

@sokra
Copy link
Contributor

sokra commented Jan 2, 2018

I found a workaround for this:

  • Instead of jest run nyc jest.
  • Configure jest to collect coverage but don't report it:
    "collectCoverage": true, "coverageReporters": [ "none" ]
  • When spawning child processes wrap them in a nyc call:
    like nyc --reporter none node child.js instead of node child.js
  • Configure nyc like you want to.

@tivac
Copy link
Author

tivac commented Jan 2, 2018

@sokra nice, that's really gross but better than nothing!

@silkentrance
Copy link

@aaronabramov see the tmp project where we use external process for integration testing. There, we use istanbul and mocha and collect the coverage data from the spawned child processes using https://github.com/raszi/node-tmp/blob/master/test/child-process.js#L40.
Later on we just run istanbul reports in https://github.com/raszi/node-tmp/blob/master/package.json#L41.
Perhaps this would be a possible solution for you?

@SimenB
Copy link
Member

SimenB commented Feb 24, 2019

Since this is still seeing some activity, this is the open issue tracking this: #5274 (we're not any closer to a solution, but that's where discussion should happen)

@felipecrs
Copy link

felipecrs commented Aug 9, 2020

I only had to run nyc jest instead of jest --coverage. No further changes were required.

felipecrs added a commit to felipecrs/megatar that referenced this issue Aug 9, 2020
Ghustavh97 added a commit to Ghustavh97/webfont that referenced this issue Oct 28, 2020
This will enable code coverage information to be displayed for
src/cli.js.

The `nyc` package will be required since `child_process` functions
such as `exec` will be used for testing and `nyc` can detect code
coverage for spawned processes and jest cannot at the moment, see
(jestjs/jest#3190).

The `esm` package will be used to load the `cli.js` module during
testing since it's written using ECMAScript and that is not
supported by node`child_process` executing a script.
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants