c8 icon indicating copy to clipboard operation
c8 copied to clipboard

Watching child process

Open buksy90 opened this issue 3 years ago • 1 comments

Hi guys,

I have a project with Vue.js + Typescript + Mocha that I need to generate code coverage from. I was using nyc + istanbul before, but had the issue with ESM modules, so I switched to c8 but I have an issue that when running tests, there are several child processes started and c8 lost track of it.

Vue-cli is triggering new process with mochapack which triggers new process with webpack which triggers new process with typescript and mocha (at least this is how I understand it :)).

I tried to exclude as many process from this chain as possible and ended with following command:

cross-env MODE=test NODE_ENV=test c8 ./node_modules/.bin/mochapack --recursive --require ./node_modules/@vue/cli-plugin-unit-mocha/setup.js --webpack-config ./node_modules/@vue/cli-service/webpack.confi
g.js 'src/**/analytics.spec.ts'

This runs c8 that runs mochapack that runs webpack that runs typescript and then mocha. In the coverage output generated by c8 I can see my config files that are used by webpack being stated with coverage included but no test files. Clearly test files are run by child process and therefore not shown in output.

TLDR: Is there any way to watch for child processes with c8 too? Or are you aware of any other solution (i.e command webpack to run c8 before running typescript & mocha)?

Thanks :)

  • C8 Version: 7.12.0
  • Node Version: 14.19.0
  • Platform: Windows 11 64bit

buksy90 avatar Oct 14 '22 14:10 buksy90

Answering the questions:

Is there any way to watch for child processes with c8 too?

c8 will automatically pass the NODE_V8_COVERAGE flag to subprocesses, which is what is used to collect coverage:

https://nodejs.org/api/cli.html#node_v8_coveragedir

This is in turn passed to subprocesses.

Or are you aware of any other solution (i.e command webpack to run c8 before running typescript & mocha)?

I would suggest trying to set NODE_V8_COVERAGE in your test environment, and eliminate c8 form the equation. It will then write coverage output to a directory. You can confirm whether or not it's been set by checking process.env in your test environment.

bcoe avatar Nov 03 '22 19:11 bcoe