feat: add named state snapshots for reproducible test scenarios#60
Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
Open
feat: add named state snapshots for reproducible test scenarios#60mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
Conversation
Add snapshot() and restore() methods to the Emulator interface so tests can save and restore emulator state. Each service also exposes HTTP control endpoints at /_emulate/snapshot (POST to save, PUT to restore) and /_emulate/health (GET for readiness checks). This extends the existing Store.snapshot()/restore() primitives that were already used internally by the Next.js adapter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
snapshot()andrestore()methods to theEmulatorinterface so tests can save and restore emulator state at any point. Each running service also gets HTTP control endpoints at/_emulate/snapshotand/_emulate/health.Why this matters
Integration tests often need to start from a specific state (e.g., "user has completed checkout"). Currently
reset()wipes everything back to seed. There's no way to save a mid-test state and restore it later without re-running the setup.LocalStack solves this with
localstack state export/import. The coreStoreclass already hassnapshot()/restore()methods, and@emulators/adapter-nextalready implements cross-service snapshots internally. This PR exposes those primitives through the public API.Changes
packages/@emulators/core/src/server.ts: Added/_emulate/snapshot(POST to save, PUT to restore) and/_emulate/health(GET) endpoints before plugin registration so they don't conflict with emulated routespackages/emulate/src/api.ts: ExtendedEmulatorinterface withsnapshot()andrestore()methods that delegate toStore.snapshot()/restore()packages/emulate/src/__tests__/api.test.ts: 3 new tests covering programmatic snapshots, HTTP control endpoints, and health checkREADME.mdandskills/emulate/SKILL.md: documented the new API and endpointsDemo
Creates a repo, saves a snapshot, creates a second repo, restores the snapshot, and verifies only the first repo remains.
Testing
All 7 tests pass (4 existing + 3 new):
snapshot saves and restore recovers state- programmatic APIhealth endpoint returns service status- health checksnapshot via HTTP control endpoint- HTTP save/restore flowThis contribution was developed with AI assistance (Claude Code).