DevelopQuality
@holtkeeper/quality-tests
Test framework detection and coverage collection for a checkout, the building blocks of the coverage analyzer (@holtkeeper/coverage); the testids analyzer uses its file listing.
import { collectCoverage, coverageCollectors } from '@holtkeeper/quality-tests'
const report = await collectCoverage(await coverageCollectors(dir), { dir, runner })coverageCollectors(dir, coverage = 'run', options?)— oneCoverageCollectorper language with its primary framework, or a reader of{ file }(an lcov tracefile or Go cover profile) when given.options.go(GoCoverageOptions { testTimeout?, tags?, timeoutMs? }) tunes the Go collector;goCoverageCollector(options)builds it directly andgoTestEnvis its environment.collectCoverage(collectors, { dir, runner, signal?, log? })— runs them one after another, skips failing ones and merges the reports (CoverageReport { format, languages, files, summary, notRun? }), withtoolsnaming the collectors that produced one. Throws only when none did, with every collector’s error.detectTestSetup(dir),frameworkFor(setup, language)— the detected frameworks and test conventions.- File helpers:
listFiles,languageOf,isTestFile,isExcludedByName,isComponentFile,isGeneratedSource; source helpers:codeLines,isTypeOnlySource,findFunctions. - Pure parsers:
parseLcov,parseGoCoverProfile,parseGoCoverFunc,goPackageDir,parseGoTestEvents(go test -jsonstdout: packages that ran, failed, had no test files or did not run, with the reason and Go’s first error line). - Go build constraints:
goBuildConstraint(source),evalGoBuildConstraint(expression, isSet)andgoTaggedTests(files, tags), the test files a linux/amd64 run withtagsleaves out only because of custom tags, counted per tag.
-
Detection —
detectTestSetup(dir)readspackage.jsondependencies and test scripts, config files (vitest.config.*,jest.config.*,.mocharc*,bunfig.toml [test],pytest.ini,conftest.py,pyproject.toml/setup.cfg/tox.inisections,go.mod) and the imports of existing tests. Frameworks:bun:test,vitest,jest,mocha,node:test,go test,pytest, ranked by evidence; imports weigh most. Per language it learnsTestConventions: layout (colocated,__tests__,test-dir), file name template, the usual framework import and the local import extension, and picks up to three sample tests (mid-sized, from different folders, using the primary framework). -
Coverage — one
CoverageCollectorper language, run through theCommandRunnerin.holtkeeper/coverage-*(removed afterwards). Failing tests are fine as long as a report is written. Go is stricter:- It runs once per module that
discoverGoModules(@holtkeeper/go-source) finds, up to four folders deep withGOWORK=off, or once at the root over every member of a rootgo.work. The env isGOTOOLCHAIN=localand, per module,GOFLAGS=-mod=mod(Go refuses-mod=modin workspace mode, so thego.workrun leaves it out), and Go’s-timeoutdefaults to5m. go testwrites a zero-count profile even when no package’s tests could run. So a module whose run exited non-zero without a single package running counts as failed. When every module failed, the collector throws with Go’s output. Otherwise the failed modules go tonotRunwithrecursive, andexceptlists the nested modules inside them that ran on their own.- Results come from
-jsonevents. Cached runs count as run, and packages without test files count as having no tests. Packages that did not build (FailedBuild,[build failed]), could not load dependencies ([setup failed]) or hit-timeoutgo tonotRunwith their folder and tolog, and so do packages with failing tests. - Before running,
_test.gofiles that need build tags the run does not set are counted per tag and logged. - With
tags, a second run per module adds-tags=…. Its profile is appended to the first, andparseGoCoverProfilekeeps the highest count per statement. Its failures are only logged, and packages that ran there are dropped fromnotRun.
Framework Command bun:testbun test --coverage --coverage-reporter=lcov --coverage-dir=…vitest<exec> vitest run --coverage.enabled --coverage.reporter=lcov …jest<exec> jest --coverage --coverageReporters=lcov --coverageDirectory=…mocha<exec> c8 --reporter=lcov --reports-dir=… mochanode:testnode --test --experimental-test-coverage --test-reporter=lcov …pytestpython3 -m pytest --cov=. --cov-report=lcov:…(needs pytest-cov)go testgo test -json -timeout=5m -coverprofile=… ./..., thengo tool cover -func=…<exec>putsnode_modules/.binfirst onPATHwhen it exists (yarn berry’syarn <bin>only finds binaries the root workspace declares), else it ispnpm exec,yarnornpx --no-installby lockfile; nothing is installed. A report the tool wrote below its own root (jest resolves--coverageDirectoryagainstrootDir) is found by the scratch folder’s name and removed too. Parsers are pure:parseLcov(SF,DA,FNincl. lcov 2 end lines,FNDA,BRDA,LF/LH/FNF/FNH; paths made relative),parseGoCoverProfile(blocks spread over lines; summary counts statements likego test -cover),parseGoCoverFunc. - It runs once per module that
Limitations
Section titled “Limitations”- Only the primary framework per language is run. Monorepos whose packages use different runners get the root runner only.
- Go profiles have no branch data.
- Without
tags, tests behind//go:build integration(or any other custom tag) are not compiled; the log names how many and which tags. CI-written profiles can still be read with{ file }.