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

Clarify config #342

Open
JakobJingleheimer opened this issue Dec 26, 2021 · 4 comments · May be fixed by #555
Open

Clarify config #342

JakobJingleheimer opened this issue Dec 26, 2021 · 4 comments · May be fixed by #555
Labels

Comments

@JakobJingleheimer
Copy link

  • Version: 7.10.0
  • Platform: macOS 12.1
  • Node: 17.1

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
{
  "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 |
  <stdin>        |   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.

@bcoe bcoe added the docs label Dec 30, 2021
@ihavenonickname
Copy link

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
Copy link

ihavenonickname commented Jan 19, 2022

Okay I think I figured it out.

  • In the report.js file we see that the cli arguments are passed directly to test-exclude
  • In test-exclude docs it's said that the include and exclude parameters should be an array of strings
  • Again in the report.js file we see that they're using a package called yargs to parse the cli arguments
  • In yargs docs it's said that a parameter is converted to array when it's specified multiple times

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!

@vassudanagunta
Copy link

In addition, it should be documented that --exclude overrides --include.

@JakobJingleheimer
Copy link
Author

JakobJingleheimer commented Jan 6, 2025

It's been years, but in case it's still relevant:

In yargs docs it's said that a parameter is converted to array when it's specified multiple times

In the yargs setup, you can explicitly set an arg to be an array regardless of how many times it occurs in CLI (array: true, type: 'string'). This was true then and now.

vassudanagunta added a commit to vassudanagunta/c8 that referenced this issue Jan 6, 2025
vassudanagunta added a commit to vassudanagunta/c8 that referenced this issue Jan 6, 2025
@vassudanagunta vassudanagunta linked a pull request Jan 6, 2025 that will close this issue
3 tasks
vassudanagunta added a commit to vassudanagunta/c8 that referenced this issue Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants