Repo of the Day
chsotelo/testcache
Published: Dec 3, 2026
Open repository ↗Per-file test result cache for Vitest: skip test files whose inputs did not change, like go test
Summary
testcache is a single Go binary (tc) that caches the result of each passing Vitest test file on disk. For every test file it computes a key from that file, the project files it actually executed and read, the Vitest config, lockfile, Node and Vitest versions, and the environment variables used; when the key matches, the pass is replayed without starting Node or Vitest. After a one-time install, commands such as pnpm test or npx vitest run are routed through tc with no repository changes.
What it is useful for
The cache is per test file, not per task. Nx and Turborepo re-run the whole test task when any package input changes; tc re-runs only the files whose recorded inputs changed, so editing one module leaves the rest of the suite replayed from disk. The README reports a 1,248-file suite dropping from about five minutes cold to 19 seconds after a few modules changed, with 1,208 files replayed and 40 run.
It also differs from vitest related/--changed, which select tests from static import paths: tc derives dependencies from V8 coverage plus files read at runtime, so a barrel file or an unexecuted branch does not invalidate every importer.
For CI, the cache directory ~/.cache/testcache can be restored between jobs, so a push that touches shared components only executes the affected files. The README's React example went from 3m38s cold to 1m08s on the next push, with 465 of 568 files replayed.
How engineers can use it
Requirements: macOS or Linux (x64 or arm64), zsh or bash, Node, and Vitest 3, 4, or 5.
curl -fsSL https://raw.githubusercontent.com/chsotelo/testcache/main/scripts/get.sh | sh
# open a new shell, then:
tc doctor
Then run your tests as usual. tc log shows recent runs, tc explain <file> reports why a file was not cached without starting Node, and TC_DISABLE=1 disables the cache for one command. In CI, install the binary only (curl ... | sh -s -- --no-integrations) and run ~/.local/bin/tc vitest run with ~/.cache/testcache cached by the CI provider; tc verify re-runs files uncached and flags stale entries before a merge.
Documented limits: a file that spawns a process, opens a network connection, reads a file modified during the run, or runs with isolate: false is never cached. A small sample of hits (default 2%) is re-run, and files that fail on re-run with identical inputs are quarantined. --changed uses git rather than a custom Vitest vcsProvider. On Linux, tc also names the iproute2 tool in /usr/sbin, so keep ~/.local/bin earlier in PATH.