Skip to content

Report and enforce code coverage - #10

Merged
MaximBelov merged 1 commit into
masterfrom
feat/coverage-report
Aug 13, 2026
Merged

MaximBelov merged 1 commit into
masterfrom
feat/coverage-report

Conversation

@MaximBelov

@MaximBelov MaximBelov commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

The suite covers a lot of ground now, and nothing measured it. This adds the measurement and turns it into a gate.

What it does

npm run coverage runs the suite under c8, which reads V8's own coverage counters — the source is measured as it runs, with no instrumentation step and nothing to keep in sync with the build.

Where it lands today:

Statements Branches Functions Lines
src/BarcodeParser.js 93.98% 77.06% 100% 93.98%

The thresholds in .c8rc.json are set just under those numbers and are enforced, so a change that adds a branch nothing exercises fails instead of passing quietly. They can only be raised from here.

Output is a console table, coverage/index.html for reading line by line, and coverage/lcov.info for editors and other tools. None of it is checked in.

In CI

Every run prints the table into the job summary, so the number is visible without downloading anything, and attaches the HTML report as an artifact for a fortnight.

publish.yaml gets the same gate. It does not depend on CI having passed — that is why it already repeats lint, test and build — so without this it could publish code that never met the threshold.

One thing worth not undoing

The coverage step sets shell: bash deliberately. The default shell for a run: step leaves pipefail off, so piping through tee to capture the log makes the step exit with tee's status rather than c8's. Verified both ways:

$ bash -eo pipefail -c 'npm run coverage 2>&1 | tee coverage.log'   # with shell: bash
exit 1
$ bash -e -c 'npm run coverage 2>&1 | tee coverage.log'             # the default
exit 0

Without that line the gate reports green on a coverage failure, which is worse than having no gate at all. There is a comment in the workflow saying so.

What is not covered, and why it is worth knowing

The report names two honest gaps:

  • the switch that turns an internal error code into its message — most arms are only reached when that specific error fires;
  • every symbology identifier other than ]C1 — it is the only one any spec uses.

Both are reachable and both deserve specs. That is a separate change, not this one — this PR is the instrument, not the fix. The thresholds are pinned at today's numbers so that work shows up as a rise rather than being quietly absorbed.

Notes

Adds c8, which reads V8's own coverage counters, so the source is measured as
it runs rather than instrumented first. "npm run coverage" writes a table to
the console, a browsable report to coverage/index.html and lcov.info for
editors; none of it is checked in.

The thresholds in .c8rc.json are set to what the suite reaches today - 93%
statements and lines, 76% branches, 100% functions - and are enforced, so a
change which adds a branch nothing exercises fails rather than passing quietly.
They can only be raised from here.

Every CI run prints the table in its job summary and keeps the HTML report as
an artifact for a fortnight. The publish workflow runs the same gate, since it
does not depend on CI having passed and would otherwise release code that
never met it.

The coverage step sets "shell: bash" on purpose. The default shell leaves
pipefail off, so the step would exit with tee's status instead of c8's and a
coverage failure would be reported green.
@MaximBelov
MaximBelov force-pushed the feat/coverage-report branch from e0854a4 to 77472f6 Compare August 13, 2026 05:44
@MaximBelov
MaximBelov merged commit 2926170 into master Aug 13, 2026
1 check passed
@MaximBelov
MaximBelov deleted the feat/coverage-report branch August 13, 2026 05:47
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.

1 participant