Skip to main content

Run without Docker

Override AnvilContainer.startRuntime() to run anvil elsewhere. The examples' local runtime spawns the anvil binary on a free port:

/**
* An `AnvilContainer` that runs anvil as a local process. Same API, same
* validation and the same started node type, without Docker.
*/
export class LocalAnvilContainer<
TAccount extends Account | undefined = undefined,
> extends AnvilContainer<TAccount> {
protected override startRuntime(): Promise<StartedTestContainer> {
return startLocal(this.prepare(), this.startupTimeoutMs ?? 60_000);
}
}

Tested in examples/test/support/local-anvil.ts:308

Use new LocalAnvilContainer(options), or route every container to it from a setup file (the examples' --no-docker mode):

type WithRuntime = { startRuntime: unknown };

/** Routes `AnvilContainer.startRuntime()` to the local runtime. */
export function useLocalRuntime(): void {
(AnvilContainer.prototype as unknown as WithRuntime).startRuntime = (
LocalAnvilContainer.prototype as unknown as WithRuntime
).startRuntime;
}

if (E2E_MODE === "local") useLocalRuntime();

Tested in examples/test/support/setup-runtime.ts:16

Copy local-anvil.ts; get a binary from @foundry-rs/anvil or foundryup:

npm install -D @foundry-rs/anvil
Local testing only

It skips the container (image, ports, file copies): run CI in Docker. Files copied out (withDumpState(), withState(), withConfigOut()) aren't supported; use dumpStateToFile().

Concepts​