Skip to content

CDP-5980: replace nyc with c8 for code coverage#209

Merged
senechko merged 2 commits into
worktree-cdp-5980-typescript-6from
worktree-cdp-5980-replace-nyc-with-c8
May 29, 2026
Merged

CDP-5980: replace nyc with c8 for code coverage#209
senechko merged 2 commits into
worktree-cdp-5980-typescript-6from
worktree-cdp-5980-replace-nyc-with-c8

Conversation

@senechko
Copy link
Copy Markdown
Member

@senechko senechko commented May 28, 2026

Stacked on #207 — merge that first.

Summary

  • Replace nyc with c8 for code coverage — c8 uses V8's native coverage engine instead of Istanbul instrumentation
  • Keep ts-node (not switching to tsx) — tsx/esbuild injects helper functions (__name, __export, __copyProps, etc.) that create phantom uncovered branches in V8 coverage, dropping branch coverage to 93% on identical tests
  • One c8 ignore pragma on an empty catch body that V8 cannot instrument (the catch is executed by tests, but V8 has no statements to mark as covered)
  • New test exercising the redirect-with-unparseable-URL catch path

What changed

File Change
package.json nycc8 in devDeps and test script; "nyc" config → "c8" config with all: true, src: ["lib"]
lib/request.ts /* c8 ignore next 2 */ on empty catch block; dropped unused err binding
test/request.ts Added test for redirect with malformed Location URL

Why not tsx?

The original plan was to pair c8+tsx (replacing nyc+ts-node). Testing showed tsx is the root cause of the phantom branches reported during the TS6 upgrade attempt:

Setup Branches Lines Functions
nyc + ts-node 100% 100% 100%
c8 + tsx 93.4% 99.8% 99.2%
c8 + ts-node 100% 100% 100%

tsx uses esbuild to transpile, which injects runtime helpers and compiles enums to IIFEs with different branch structure than tsc. V8 coverage counts those as uncovered branches.

Test plan

  • npm test — 163 tests pass, 100% coverage (statements, branches, functions, lines)
  • npm run lint — clean
  • CI passes

🤖 Generated with Claude Code


Note

Low Risk
Dev-only coverage tooling and a test plus empty-catch annotation; redirect auth-stripping behavior is unchanged.

Overview
Swaps nyc for c8 (V8-native coverage) while keeping ts-node for tests so coverage stays at 100% branches. The test script runs c8 ava; package.json adds a c8 block (all, lib as source) and drops nyc. Lockfile churn reflects removing Istanbul/nyc’s dependency tree and adding c8; an overrides entry bumps yargs for transitive CLI deps.

In lib/request.ts, redirect header handling is unchanged except the malformed-URL path uses an empty catch {} with a c8 ignore comment (V8 can’t mark an empty catch as covered). A new test asserts a redirect with a relative Location rejects with TypeError.

Reviewed by Cursor Bugbot for commit cd569af. Bugbot is set up for automated code reviews on this repo. Configure here.

c8 uses V8's native coverage engine instead of Istanbul instrumentation.
Keeping ts-node (not switching to tsx) because tsx/esbuild injects helper
functions that create phantom uncovered branches in V8 coverage.

One c8-ignore pragma on an empty catch body that V8 cannot instrument,
plus a new test that exercises the catch path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 28, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedc8@​11.0.09910010083100

View full report

@senechko senechko requested a review from mike-engel May 28, 2026 21:40
c8 and ava depend on yargs@17, which uses require() inside an ESM
package. Node 26 rejects this with "ReferenceError: require is not
defined in ES module scope". yargs@18 is pure ESM and works on all
supported Node versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@senechko senechko merged commit a708967 into worktree-cdp-5980-typescript-6 May 29, 2026
9 checks passed
@senechko senechko deleted the worktree-cdp-5980-replace-nyc-with-c8 branch May 29, 2026 13:58
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.

2 participants