Skip to main content

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.

SettingDefaultDescription
setup(node)–runs once after start, before the baseline
isolation"test""none": state carries over between tests
timeoutDEFAULT_USE_ANVIL_TIMEOUT_MS (120 000)start/stop hook timeout in ms
hooksglobalsAnvilTestHooks: { beforeAll, afterAll, afterEach? }
  • AnvilStartable: anything with start(), e.g. { start: () => … }.
  • Hooks: globals of Jest, Vitest (globals: true), Mocha, Jasmine, or hooks.
  • Errors: NOT_STARTED (used outside tests), TEST_HOOKS_UNAVAILABLE, SNAPSHOT_NOT_FOUND (a test called reset() / 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.