Skip to content

Add snapshot testing support #1100

@sirenkovladd

Description

@sirenkovladd

Poku currently has no snapshot assertion capability.

Motivation

Snapshot tests are one of the most requested features in test frameworks. They are especially useful for:

  • Large or complex outputs — API responses, rendered HTML, CLI output, deeply nested objects — where writing manual deepEqual assertions is tedious and fragile
  • Regression detection — catch unintended changes in output without having to spell out every expected field
  • Documentation — snapshot files serve as living documentation of what your code produces

Every major Node.js test runner (Jest, Vitest, Node.js built-in node:test) supports snapshots. Their absence is a gap for anyone migrating to poku.

Proposal

API

Mirror the familiar Jest/Vitest API:

import { assert } from 'poku';

assert.snapshot(value);                // creates or compares snapshot
assert.snapshot(value, 'named snapshot'); // named snapshots for multiple per file

Behavior

Scenario Behavior
Snapshot file doesn't exist Create it, test passes
Snapshot exists & matches Test passes
Snapshot exists & differs Test fails, show diff in output
--updateSnapshot / -u flag Overwrite snapshots instead of failing

Snapshot storage

Snapshots are stored in a __snapshots__/ directory adjacent to each test file, following the convention used by Jest and Vitest:

test/
  api.test.ts
  __snapshots__/
    api.test.ts.snap

Update flag

Add --updateSnapshot (short: -u) CLI flag and corresponding updateSnapshot config option. When set, mismatching snapshots are overwritten instead of causing test failures.

Diff output

When a snapshot mismatches, show a colored unified diff

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions