Library public API snapshot testing for runtime exports and type declarations.
by antfuTypeScript
Last 12 weeks · 18 commits
5 of 6 standards met
Given: the DTS snapshot renders: The signature of is dropped (and nested namespaces lose everything below the first level), so changes to namespace member signatures don't invalidate the snapshot. Context: trying tsnapi in sveltejs/cli (sveltejs/cli#1162), where exposes most of its API through namespaces (, ...) - none of those signatures end up guarded.
Given: the DTS snapshot only shows - the shape of is absent, so changing it doesn't invalidate the snapshot even though it changes the public contract. Would you consider inlining (or additionally emitting) declarations reachable from exports, possibly behind an option? Context: trying tsnapi in sveltejs/cli (sveltejs/cli#1162). Related but separate from #31.
Summary Extends the breaking-changes guard from #33 to the Vitest integration. delegated entirely to Vitest's , which overwrites snapshot files unconditionally on . A removed or narrowed export would slip through silently — exactly what the guard the CLI and rolldown plugin already have is meant to prevent. Changes Guard in the Vitest integration: runs before each , detecting update mode via Vitest's snapshot state (). On a removed/narrowed export it throws — failing the test and leaving the snapshot file on disk untouched. option added to (inherited by ). New exported — a pure, Vitest-independent helper (caller supplies + existing content), reusable for custom snapshot flows. README: new "Breaking changes guard" subsection under Vitest. Note on the escape hatch Vitest's CLI (cac) rejects unknown flags, so cannot be passed through . For the Vitest integration the escape hatches are the env var or the option — documented explicitly. Verification Unit tests in (9 cases, both surfaces). Also verified end-to-end against live runs: Breaking change → tests fail with , snapshot on disk unchanged. Additive change → passes through and updates (this repo's own run confirms it). → breaking update allowed through. Full suite (145), typecheck, and lint all pass. 🤖 Generated with Claude Code
Repository: antfu/tsnapi. Description: Library public API snapshot testing for runtime exports and type declarations. Stars: 199, Forks: 3. Primary language: TypeScript. Languages: TypeScript (81.5%), Vue (16.7%), JavaScript (1.3%), CSS (0.4%), HTML (0.1%). License: MIT. Topics: snapshot, snapshot-testing. Latest release: v1.4.0 (20h ago). Open PRs: 0, open issues: 0. Last activity: 20h ago. Community health: 85%. Top contributors: antfu, antfubot, jycouet.