Skip to content

Imply --coverage when --coverage-reporter is used - #20736

Closed
Jarred-Sumner wants to merge 3 commits into
mainfrom
cursor/enable-coverage-reporting-and-test-bd15
Closed

Jarred-Sumner wants to merge 3 commits into
mainfrom
cursor/enable-coverage-reporting-and-test-bd15

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

This PR automatically enables --coverage when the --coverage-reporter flag is used. This simplifies the command for users, as they no longer need to explicitly specify both --coverage and --coverage-reporter to generate coverage reports.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works%3F

  • I included a test for the new code, or existing tests cover it
  • I ran my tests locally and they pass (bun-debug test test/cli/test/coverage.test.ts)

cursoragent and others added 2 commits June 30, 2025 22:15
@robobun

robobun commented Jun 30, 2025 •

Copy link
Copy Markdown
Collaborator

@robobun

robobun commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Closing as stale: this PR predates the Rust rewrite. Every src/ file it modifies has since been removed or relocated on main (Zig sources deleted; src/bun.js/ reorganized into src/jsc/), so it can no longer merge.

If the underlying change is still wanted, it will need to be redone against the current Rust/C++ tree. Apologies for the churn, and thank you for the contribution.

@robobun robobun closed this Jun 26, 2026
Jarred-Sumner pushed a commit that referenced this pull request Oct 3, 2026
Fixes #17502

### Problem
- `bun test --coverage-reporter=lcov` runs the tests, exits 0, and
writes no report. It prints no warning.
- The `--coverage-reporter` block of `parse_test_command_options`
(`src/runtime/cli/Arguments.rs:1798`) sets `coverage.reporters` and
never `coverage.enabled`.

### Fix
- That block now sets `coverage.enabled = true`. The help text and
`docs/snippets/cli/test.mdx` say `Implies --coverage`.
- `--coverage-dir` and the bunfig key `coverageReporter` do not change
(see Notes).
- Verified: `test/cli/test/coverage.test.ts`, 5 new tests (lcov, the
separate-argument form, text, both reporters, `--parallel=2`). The
released build fails 5 of 5. A debug build with the change passes them,
and the whole file passes (32 tests).

### Background
- `bun test` collects coverage only when `coverage.enabled` is true.
`--coverage` or `coverage = true` in `bunfig.toml` sets it.
- A `--parallel` coordinator starts its workers with `--coverage` when
`coverage.enabled` is true
(`src/runtime/cli/test/parallel/runner.rs:422`), so the same switch
covers that mode.
- No other place was weighed: one block parses the flag. #20736 and
#32420 made the same change, and a review of #32420 asked for the
reporter half only.

### Downsides
- A run with `--coverage-reporter` and no `--coverage` now collects
coverage. It is slower, it prints the table or writes
`coverage/lcov.info`, and a `coverageThreshold` in `bunfig.toml` can now
fail it.
- `--coverage-dir` with neither flag is still dropped with no message.
- Other runs pay nothing: one assignment at argument parsing, only when
the flag is present. The help text grows by 20 bytes.

<details><summary>Notes</summary>

**Rows, before and after.** A directory with `f.ts` and `f.test.ts`:

| command | released build | with the change |
| --- | --- | --- |
| `bun test --coverage` | text table | text table |
| `bun test --coverage --coverage-reporter=lcov` | `coverage/lcov.info`
| `coverage/lcov.info` |
| `bun test --coverage-reporter=lcov` | nothing | `coverage/lcov.info` |
| `bun test --coverage-reporter=text` | nothing | text table |
| `bun test --coverage-dir=cov2 --coverage-reporter=lcov` | nothing |
`cov2/lcov.info` |
| `bun test` | nothing | nothing |

**Why `--coverage-dir` stays.** Only the lcov writer reads the directory
(`src/runtime/cli/test_command.rs:1631-1681`). `bun test
--coverage-dir=out` alone would print the text table and never create
`out/`. The comparable flags `--cpu-prof-dir` and `--heap-prof-dir` do
not turn their switch on. They fail with `must be used with --cpu-prof`
(`Arguments.rs:1392`, `:1449`). Whether `--coverage-dir` alone must be
an error is an open question.

**Why the bunfig key stays.** A reporter that is set in `bunfig.toml`
must not turn coverage on for each `bun test` run. `coverage = true` is
the key for that.

**`bunfig.toml` wins over the flags today.** With `coverage = false` in
`bunfig.toml`, `--coverage` does not turn coverage on, and
`--coverage-reporter` does not either. With `coverageReporter = "lcov"`
there, `--coverage-reporter=text` writes `lcov.info`. #40348 (open)
changes that order and edits the same function.

**Threshold.** With `coverageThreshold = 1.0` and one function that no
test calls: `bun test` exits 0, `bun test --coverage` exits 1, and `bun
test --coverage-reporter=lcov` now exits 1 too.

**Earlier pull requests.** #17737, #20736, #32420. The last one was
closed by a cleanup of stale pull requests, with no objection to the
change.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants