Node.js collection
Possible solutions:
NODE_V8_COVERAGE=
dir- Sets Node.js env
NODE_V8_COVERAGE=dirbefore the program running, the coverage data will be saved to thedirafter the program exits gracefully. - Read the JSON file(s) from the
dirand generate coverage report. - Example:
cross-env NODE_V8_COVERAGE=
.temp/v8-coverage-envnode ./test/test-node-env.js && node ./test/generate-report.js- Sets Node.js env
V8 API + NODE_V8_COVERAGE
- Writing the coverage started by NODE_V8_COVERAGE to disk on demand with
v8.takeCoverage(), it does not require waiting until the program exits gracefully. - Example:
cross-env NODE_V8_COVERAGE=
.temp/v8-coverage-apinode ./test/test-node-api.js- Writing the coverage started by NODE_V8_COVERAGE to disk on demand with
Inspector API
- Connecting to the V8 inspector and enable V8 coverage.
- Taking coverage data and adding it to the report.
- Example:
- vm Example (scriptOffset):
CDP API
- Enabling Node Debugging.
- Collecting coverage data with CDP API.
- Example:
node --inspect=9229 ./test/test-node-cdp.js
Node Debugging + CDP + NODE_V8_COVERAGE + V8 API
- When the program starts a server, it will not exit on its own, thus requiring a manual invocation of the
v8.takeCoverage()interface to manually collect coverage data. Remote invocation of thev8.takeCoverage()interface can be accomplished through theRuntime.evaluateof the CDP. - Example for koa web server:
- When the program starts a server, it will not exit on its own, thus requiring a manual invocation of the
Child Process + NODE_V8_COVERAGE
- see Command Line