Add --coverage option to build scripts for tests#54499
Conversation
|
|
jakebailey
left a comment
There was a problem hiding this comment.
I've been wanting this officially for a while, thanks!
(c8 hereby runtests-parallel was an ok thing up until now)
scripts/build/tests.mjs
Outdated
| // enable code coverage using 'c8' | ||
| let execPath = process.execPath; | ||
| if (coverage) { | ||
| args.push("exec", "c8", "--clean", execPath); |
There was a problem hiding this comment.
Can we dev dep on c8 and run it directly instead of using npm exec?
There was a problem hiding this comment.
It's easier to continue using npm exec to avoid having to deal with trying to spawn a local package bin and deal with multiple platforms myself, though I can add --prefer-offline or --offline to have it prefer the local version.
There was a problem hiding this comment.
To clarify, I am both continuing to use npm exec for convenience and also adding c8 to devDependencies.
There was a problem hiding this comment.
It's easier to continue using
npm execto avoid having to deal with trying to spawn a local package bin and deal with multiple platforms myself, though I can add--prefer-offlineor--offlineto have it prefer the local version.
What do you mean by platforms? It should be at node_modules/c8/bin/c8.js; we execute eslint and mocha using similar methods.
This adds a
--coverageoption to our build scripts for use withruntests,runtests-parallel, andruntests-watch. When--coverageis specified, tests will be run throughc8and dump anlcovformat file tocoverage/lcov.infofor use with a code coverage extension for VS Code or other tooling.