bcoe / c8

output coverage reports using Node.js' built in coverage
ISC License
2k stars 91 forks source link

Clarify config #342

Open JakobJingleheimer opened 2 years ago

JakobJingleheimer commented 2 years ago

Configuration options for "include" and "src" are very unclear. Without specifying either, several extraneous files are included in the report and some are actually not included at all (despite their tests running).

package.json ```json { "scripts": { "test": "NODE_ENV=test NODE_OPTIONS='--no-warnings --loader=./loader.mjs' mocha './lib'", "test:coverage": "c8 --check-coverage npm test" }, "c8": { "branches": 100, "exclude": [ "**/*.fixture.js", "**/*.spec.{js,cjs,mjs,ts,tsx,jsx}" // c8 is expecting .test.* ] }, } ```
file directory ``` ./lib ├ compose.js ├ compose.spec.js ├ diff.js ├ diff.spec.js ├ Form.jsx ├ Form.spec.js ```
c8 coverage report ``` // passing mocha spec output for compose.spec.js, diff.spec.js, and Form.spec.js -----------------|---------|----------|---------|---------|------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -----------------|---------|----------|---------|---------|------------------ All files | 92.57 | 95.31 | 66.66 | 92.57 | PACKAGE | 100 | 84.61 | 54.54 | 100 | loader.mjs | 100 | 87.5 | 100 | 100 | 33 mocha.setup.js | 100 | 80 | 28.57 | 100 | 13 PACKAGE/lib | 88.94 | 98.03 | 85.71 | 88.94 | | 73.41 | 85.71 | 80 | 73.41 | 51-71 compose.js | 100 | 100 | 100 | 100 | diff.js | 100 | 100 | 100 | 100 | -----------------|---------|----------|---------|---------|------------------ ```

Unexpectedly, ./loader.mjs and ./mocha.setup.js are included, yet Form.spec.js is not.

Specifying anything for "include" seems to cause the coverage report to be empty, and "src" seems to have no affect whatsoever.

ihavenonickname commented 2 years ago

yeah I'm struggling to understand how I'm supposed to use --src and --include.

Specifying anything for "include" seems to cause the coverage report to be empty, and "src" seems to have no affect whatsoever.

That's exactly the behavior I found as well.

ihavenonickname commented 2 years ago

Okay I think I figured it out.

So I was able to make it work specifying --include multiple times. Example:

npx c8 --include "src/handlers/*/handler.ts" --include "src/stubs/*.ts" ava

The coverage report correctly shows the files I expected to see.

Hope it helps!