diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-31 13:57:40 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-31 13:57:40 -0500 |
| commit | ee903e4b63257573773e93d10612250e3634cae9 (patch) | |
| tree | 89cc6199b53f445a4c32252c6b982a6c86964e3b /languages/typescript/coverage-makefile.txt | |
| parent | 47ca509e69b6a1472a735a4b9521a952e7434491 (diff) | |
| download | rulesets-ee903e4b63257573773e93d10612250e3634cae9.tar.gz rulesets-ee903e4b63257573773e93d10612250e3634cae9.zip | |
feat(typescript): add coverage-summary to the TypeScript bundle
Last language in the coverage-summary fan-out, after Elisp, Python, and Go. Same kernel: count every source file on disk that's absent from the coverage report as 0% and weight the project number by file, so an untested file stays visible instead of being averaged away.
The script at languages/typescript/claude/scripts/coverage-summary.js parses an Istanbul json-summary report (the coverage-summary.json that c8, Vitest, and Jest all emit), takes per-file statements covered over total, and reports a file-weighted number plus the missing files. It walks the source dir for .ts/.js, skipping test files, declarations, and node_modules. Node built-ins only, so it runs via node with no install, and it doesn't reimplement the per-file table nyc already prints.
Tests are black-box, run with node's own test runner: a temp tree plus a json-summary report, the script invoked via node, output asserted. They cover missing-file detection, all-tracked, test-file and node_modules exclusion, and the missing-report error. make test gained a node --test discovery path for languages/*/tests, guarded so environments without Node skip it cleanly. As with Python, the TypeScript bundle had no gitignore-add.txt, which would have left the script un-gitignored on install, so I added one.
This finishes the fan-out: coverage-summary now ships in all four bundles, each parsing its own tool's report behind the same file-weighted, missing-as-0% kernel. I proved the Go and TypeScript scripts by running them (Go against a live profile, TS against a synthetic report and the CLI). Python and TypeScript weren't run against a live coverage tool, since neither coverage.py nor nyc is installed here, so the first adopter of each should check against a real report.
Diffstat (limited to 'languages/typescript/coverage-makefile.txt')
| -rw-r--r-- | languages/typescript/coverage-makefile.txt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/languages/typescript/coverage-makefile.txt b/languages/typescript/coverage-makefile.txt new file mode 100644 index 0000000..64c7fcd --- /dev/null +++ b/languages/typescript/coverage-makefile.txt @@ -0,0 +1,45 @@ +# TypeScript / JavaScript coverage — Makefile fragment + setup recommendation +# +# This file is owned by the project, not the rulesets bundle. The bundle never +# edits your Makefile. Copy the two targets below into your own Makefile (and +# adjust the variables at the top), then delete this file or keep it as a note. +# +# What you get: +# make coverage runs the suite under c8 and writes an Istanbul +# json-summary report plus c8's own text table +# make coverage-summary prints a file-weighted project number and every +# source file on disk absent from the report, at 0%. +# +# Why the summary matters: a module no test imports never appears in the +# Istanbul report, so a statement-weighted total silently skips it. The summary +# weights by file and counts a missing file as 0%, so untested files stay +# visible. It does not reimplement the per-file table — nyc/c8 already print it. +# +# --------------------------------------------------------------------------- +# Prerequisite: an Istanbul json-summary report. +# +# c8: npx c8 --reporter=json-summary --reporter=text npm test +# vitest: vitest run --coverage --coverage.reporter=json-summary +# jest: jest --coverage --coverageReporters=json-summary +# +# All three write coverage/coverage-summary.json. The summary script needs +# nothing beyond Node's standard library — it parses the JSON. +# --------------------------------------------------------------------------- + +# Variables — adjust to your layout. +NODE ?= node +SOURCE_DIR ?= src +COVERAGE_FILE ?= coverage/coverage-summary.json +# The summary script ships with the bundle under .claude/scripts/ (gitignored). +COVERAGE_SUMMARY ?= .claude/scripts/coverage-summary.js + +coverage: + @npx c8 --reporter=json-summary --reporter=text npm test + @$(MAKE) coverage-summary + +coverage-summary: + @if [ ! -f $(COVERAGE_FILE) ]; then \ + echo "[!] No coverage file at $(COVERAGE_FILE). Run 'make coverage' first."; \ + exit 1; \ + fi + @$(NODE) $(COVERAGE_SUMMARY) $(COVERAGE_FILE) $(SOURCE_DIR) . |
