Skip to content

fix: fail check-coverage when there is no coverage data to check - #614

Open
haigou-web wants to merge 1 commit into
bcoe:mainfrom
haigou-web:fix/check-coverage-no-data
Open

haigou-web wants to merge 1 commit into
bcoe:mainfrom
haigou-web:fix/check-coverage-no-data

Conversation

@haigou-web

Copy link
Copy Markdown

Fixes #610

Problem

With no coverage data at all, --check-coverage exits 0:

c8 --check-coverage --lines 100 node -e "1"   # exits 0, should exit 1

Two separate gaps:

  1. istanbul reports pct as the string "Unknown" when there is no data, and "Unknown" < 100 is false — the threshold check silently passes.
  2. With --per-file, map.files() is empty, so the forEach never runs and nothing is checked at all.

Fix

  • Treat "Unknown" as failing any threshold above 0
  • With --per-file, fall back to the overall summary when there are no files
  • A threshold of 0 still passes (it does not require coverage)

Note on an existing test

exits with 0 if coverage within threshold used --exclude="test/fixtures/*.js", which excluded the only file the before hook had instrumented. That test was relying on the bug: it was asserting "no data → exit 0" while its name says "coverage within threshold → exit 0". I changed the exclude to test/fixtures/all/** so the test actually exercises its stated intent.

Verification

  • New tests: no data (exit 1), no data + --per-file (exit 1), no data + threshold 0 (exit 0)
  • Full suite: 99 passing/14 failing before → 105 passing/14 failing after; zero new failures, zero disappeared
  • The 14 pre-existing failures are monocart / --extension related and fail identically on an unmodified checkout

@haigou-web haigou-web changed the title Fail check-coverage when there is no coverage data to check fix: fail check-coverage when there is no coverage data to check Oct 8, 2026
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.

check-coverage passes when there is no coverage data to check

2 participants