deno
2ac9a901 - feat(test): built-in snapshot testing via t.assertSnapshot (#35139)

Commit
27 days ago
feat(test): built-in snapshot testing via t.assertSnapshot (#35139) Adds snapshot testing to the built-in test runner: a new `t.assertSnapshot(actual, options?)` method on `Deno.TestContext` and an `--update-snapshots` (`-u`) flag for `deno test`. Snapshots are stored in the same `__snapshots__/<test file>.snap` format as `@std/testing/snapshot` (same serializer settings), so existing snapshot files keep working after switching to the built-in API. Compared to the userland implementation, update mode is a proper CLI flag instead of `deno test -- --update`, and no read or write permissions are needed for snapshot files in the default location since the runner manages them itself (custom `dir`/`path` locations still require permissions, and snapshot writes are only authorized when `--update-snapshots` is passed). Updated and removed snapshot counts are reported through the test reporters in the run summary. Stale snapshots are only removed when every test in a module ran all of its assertions, so filtered, ignored, `only` and failed runs never delete snapshots they didn't see. Out of scope for this PR, noted as follow-ups: inline snapshots (`assertInlineSnapshot`), `expect(...).toMatchSnapshot()` on top of the same machinery, Jest-style CI behavior (failing on newly written snapshots in CI), and a deprecation pointer in `@std/testing/snapshot` once this ships.
Author
Parents
Loading