ProdSens.live

Tuesday, 1 December 2026Eight desks, updated through the day

testcache replays unchanged Vitest tests to cut repeat runs

A Go-based wrapper for Vitest records each test file’s actual inputs and reuses passing results when those inputs remain unchanged.

testcache replays unchanged Vitest tests to cut repeat runs — illustration

Key takeaways

  • testcache records each passing test file’s content and observed inputs.

  • It can track loaded modules, files read and environment variables read.

  • Process-spawning and network-connected tests are excluded from storage.

  • A reported 1,248-file repeat run fell from about five minutes to 19 seconds, with 1,208 results replayed.

A new tool called testcache aims to reduce repeated Vitest work by remembering which inputs each test file actually used. In a reported 1,248-file suite, a cold run took about five minutes; after a few modules were edited, the next full run completed in 19 seconds, with 1,208 files replayed and 40 executed.

testcache is distributed as a single Go binary that wraps an existing Vitest command. Rather than treating every test as changed whenever the broader project changes, it builds a separate cache key for each file from the file’s contents and the inputs loaded during its most recent passing run.

Tracking more than imports

The recorded inputs can include modules executed according to V8 coverage data, files read during the test, and environment variables accessed by it. A cached result can therefore be replayed only while those observed inputs remain unchanged.

The tool applies safeguards around cases that are difficult to reproduce safely. It does not store a result for a file that starts a process or opens a network connection. It also discards results when an input changes during the run.

Checks against stale results

Cache hits are not accepted blindly. testcache re-runs 2% of them, and places a file in quarantine if the fresh execution disagrees with the replayed result. For a final check before merging, the tool provides tc verify, which runs the complete test set again.

Reported CI impact

The author also tested the approach with a React application containing 563 test files on self-hosted GitHub Actions runners. Test steps took 3 minutes 38 seconds on a cold run and 1 minute 08 seconds on the next push, which included seven commits. The reported breakdown was 465 replayed files and 103 executed files.

The repository includes installation instructions, details of the key calculation and known limitations. The approach is most relevant where test behavior is driven by observable file, module and environment inputs, while the process and network restrictions define important boundaries for adoption.

Why it matters for your role

Pick the building you work in.

For software engineers

Engineers can place testcache around an existing Vitest command without replacing the test runner. Its input-based keying provides a way to avoid rerunning files whose observed dependencies have not changed.

For QA engineers

The 2% verification sampling, quarantine behavior and tc verify command provide explicit controls for checking whether replayed results remain trustworthy.

Based on reporting by DEV Community (source article).

Written with AI assistance and reviewed under our editorial standards. Spotted an error? Tell the desk.

Comments

Join the discussion

Your email address will not be published. Required fields are marked *

Follow the city on Telegram

Every new story from all eight desks, as it lands. No inbox, no sign-up form, just open the channel and read.

@prodsens

Product, project, software, QA, AI, analytics, marketing and planning news in one feed.

Open in Telegram (opens in a new tab)