You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test API: portable toMatchSnapshot (snapshots) across bun/node/browser #14
@b9g/libuild/test unifies expect across runtimes, but snapshot matching isn't portable. Under bun, expect is bun:test's (has toMatchSnapshot); under node it's the expect package, which has no snapshot support without a host runner. So expect(x).toMatchSnapshot() passes on -p bun and fails on -p node with:
TypeError: expect(...).toMatchSnapshot is not a function
It also doesn't typecheck: the unified expect type is the union of the two, and the union has no toMatchSnapshot.
Why it matters
Snapshots are the natural way to test large rendered-output blobs (for termdom, multi-line terminal renders). Right now a project has to either drop snapshots or keep them bun-only, which defeats the point of a cross-platform runner.
Proposed
Provide a portable snapshot matcher in the libuild test layer, independent of the underlying runner:
expect(value).toMatchSnapshot() serializes value, stores it in a .snap file next to the test (or a __snapshots__ dir), and compares on subsequent runs.
An update mode — env var (LIBUILD_UPDATE_SNAPSHOTS=1) and/or a CLI flag (--update-snapshots / -u).
Same behavior and same snapshot files across bun, node, and browser platforms, so a snapshot written on one platform verifies on the others.
Include toMatchSnapshot in the exported expect type so consumers typecheck.
This is the same "unify the runtimes at the libuild layer" shape as the externalize (#12) and setup-file (#13) fixes.
Filed from termdom: ~11 tests across ~7 files snapshot rendered terminal output and currently pass on bun, fail on node.
Activity