Skip to content

Coverage not working with vitest #852

@bkeepers

Description

@bkeepers

Describe the bug

Adding a CLI in openwatersio/neaps#182 and despite there being tests, the coverage report shows most of the command implementation is uncovered. I've tried both v8 and instanbul backends.

 % Coverage report from v8
-------------------------------------|---------|----------|---------|---------|-------------------
File                                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------|---------|----------|---------|---------|-------------------
All files                            |   91.78 |     80.6 |   95.86 |   92.56 |
 cli/src                             |       0 |      100 |       0 |       0 |
  command.ts                         |       0 |      100 |       0 |       0 | 5-8
 cli/src/commands                    |      35 |     9.09 |   83.33 |   38.88 |
  extremes.ts                        |   47.61 |       20 |     100 |      50 | 69-83
  stations.ts                        |   21.05 |        0 |      50 |      25 | 32-52
 cli/src/formatters                  |   57.14 |        0 |      70 |   57.14 |
  index.ts                           |       0 |        0 |       0 |       0 | 6-31
  json.ts                            |      80 |      100 |   66.66 |      80 | 12
  text.ts                            |      80 |        0 |   83.33 |      80 | 23-27

To Reproduce

openwatersio/neaps#182 is a pretty minimal reproduction example.

Noteworthy:

  • It's a monorepo, so had to set OCLIF_TEST_ROOT here.
  • The app is using TypeScript, sourcemaps are being generated (tsconfig)

Expected behavior

Test coverage would accurately reflect what is covered. It's almost acting like the commands are loaded in process, but the actual command invocations are run in a fork/subprocess and the v8 instrumentation can't track it.

Environment (please complete the following information):

  • OS & version: MacOS Tahoe and ubunto-latest (GitHub Actions)
  • Shell/terminal & version: N/A
  • node: 22.21.1 and 24.12.0
  • typescript: 5.9.3
  • vite: 4.0.17
  • @oclif/core: 4.8.0
  • @oclif/test: 4.1.15

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions