Skip to content

test(coverage): enforce an 80% c8 floor and cover the CLI surface (#85) - #94

Open
robotlearning123 wants to merge 3 commits into
mainfrom
loop/20260930_214000-issue85
Open

robotlearning123 wants to merge 3 commits into
mainfrom
loop/20260930_214000-issue85

Conversation

@robotlearning123

Copy link
Copy Markdown
Member

What

Closes #85. test:coverage had no threshold, so it always exited 0. src/commands/* and src/index.ts never appeared in the report because no test loaded them.

  • New .c8rc.json:
    • all: true, so unloaded src files show as 0% instead of disappearing.
    • check-coverage with lines: 80 and functions: 80.
    • It excludes only files with no runtime logic: src/types.ts (interfaces), src/lib.ts, the pure re-export barrels src/engine/index.ts and src/utils/index.ts, and *.d.ts.
    • src/index.ts (CLI entry) and src/templates/index.ts (template loader) stay inside the gate.
  • New test/commands.test.ts:
    • In-process tests for checkCommand and initCommand, with console and process.exit stubbed. They cover human and --json output, --strict exit 1, the error branch, --dry-run, --check, --force, template substitution, an invalid package.json, and a write failure.
    • tsx-spawned tests for src/index.ts routing.
    • Config tests pin that src/index.ts and src/templates/index.ts are never excluded.
  • package.json is not modified. The threshold lives in .c8rc.json, so it does not collide with deps: bump c8 from 10.1.3 to 11.0.0 #55 (c8 10->11) or fix(test): include test/e2e in test globs and build before tests #90 (e2e test globs).

Evidence (this branch)

Run Result
main before npm run test:coverage exits 0, with no src/commands / src/index.ts rows
config only, no new tests ERROR: Coverage for lines (65.74%) does not meet global threshold (80%), exit 1
after 77/77 tests pass; All files 84.04% lines / 84.12% funcs; exit 0; npm run check green
regression probe removing test/commands.test.ts gives exit 1

Sequencing

Review

  • An independent reviewer found a major issue: the original exclude glob src/**/index.ts also matched src/index.ts. It was fixed in e608f76, and the delta re-review said SHIP.
  • A follow-up minor finding said src/*/index.ts still hid src/templates/index.ts. That was fixed in 72f4634, with a test that fails first.
  • Known minor: the config test uses path.matchesGlob, which needs Node >= 20.17 / 22.5. CI's 20.x / 22.x resolve to recent releases.

… point

Add .c8rc.json with all:true so unloaded modules appear in the report, and
fail test:coverage below 80% lines/functions. Add in-process tests for
src/commands/{check,init}.ts and a tsx-spawned test for src/index.ts so the
CLI surface is measured without requiring a build.
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.

no coverage threshold: src/commands and src/index.ts invisible to test:coverage

1 participant