Golden-file testing / approval testing
Compare current output with a checked-in reference file, then reject the difference or bless it as the new expected result.
What it is
Golden-file testing saves an accepted output as a reference file and compares future output against it byte for byte or through a structured diff. Approval testing names the human step: inspect an unexpected diff and either reject it as a bug or approve it as the new reference. Llewellyn Falco's ApprovalTests libraries formalized that workflow, while Jest snapshots made a close relative familiar to JavaScript teams.
Reach for it when the full output is easier to review than to describe with dozens of assertions: generated code, compiler diagnostics, CLI help, formatted documents, or large serialized responses. Commit the reference beside the test and make updates produce an ordinary code review diff.
Gotcha: approving without reading turns the test into a change detector with no opinion about correctness. Normalize timestamps, random IDs, paths, and ordering before comparison, and keep references small enough to review. For binary output, add a readable semantic diff or the reviewer is left approving an opaque blob.
Ask AI for it
Add golden-file tests for <generator> with Vitest's toMatchFileSnapshot API. Store each approved UTF-8 reference beside the test, freeze Date.now, replace UUIDs and absolute paths with stable tokens, sort unordered collections, and emit a unified text diff on failure. Require an explicit local update command, make CI read-only, and split any reference too large to review comfortably into focused cases.