blob: 64c7fcd8f403135332f7ac564dad236e002a40d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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) .
|