useAnvil()
useAnvil(container: AnvilStartable, settings?: UseAnvilSettings): StartedAnvilContainer
Registers beforeAll (start, setup, baseline), afterEach (restore) and
afterAll (stop); returns a StartedAnvilContainer
handle for tests and hooks.
| Setting | Default | Description |
|---|---|---|
setup(node) | – | runs once after start, before the baseline |
isolation | "test" | "none": state carries over between tests |
timeout | DEFAULT_USE_ANVIL_TIMEOUT_MS (120 000) | start/stop hook timeout in ms |
hooks | globals | AnvilTestHooks: { beforeAll, afterAll, afterEach? } |
AnvilStartable: anything withstart(), e.g.{ start: () => … }.- Hooks: globals of Jest, Vitest (
globals: true), Mocha, Jasmine, orhooks. - Errors:
NOT_STARTED(used outside tests),TEST_HOOKS_UNAVAILABLE,SNAPSHOT_NOT_FOUND(a test calledreset()/loadState()).
// Pass the hooks yourself when your runner has no Jest-style globals.
const anvil = useAnvil(new AnvilContainer(), {
hooks: { beforeAll, afterAll, afterEach },
timeout: 120_000, // start/stop hook timeout
});
Tested in examples/test/e2e/lifecycle.e2e.test.ts:37
Tasks: Share a node, Manage the lifecycle.