mirror of
https://github.com/hanzoai/viem.git
synced 2026-10-30 19:36:39 +00:00
* feat: tempo * chore: fmt * wip * chore: up * chore: u * chore: u * chore: u * chore: up * refactor: defineChain; rm assignKeyAuthorization * fmt * refactor: test config; nonce key store * chore: fmt * chore: fmt * chore: up * chore: fmt * wip: tests * chore: knip; up tests * chore: knip; up tests * wip: require account on walletNamespaceCompat * ci: fix * ci: up * ci: up * ci: up * tests: up * tests: up * chore: up vocs * tests: up * fix: inference * chore: up nonce * chore: up * chore: up * chore: up * chore: submodule + agents * chore: up biome * chore: up * chore: up * ci: up * chore: up * chore: up * chore: up * feat: enshrine signature envelope verification * docs * chore: up * chore: up * chore: changeset * docs: chain * chore: bump size
31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
import * as executionInstances from './src/anvil.js'
|
|
import * as bundlerInstances from './src/bundler.js'
|
|
|
|
export default async function () {
|
|
if (process.env.SKIP_GLOBAL_SETUP) return
|
|
|
|
// Using this proxy, we can parallelize our test suite by spawning multiple "on demand" anvil
|
|
// instances and proxying requests to them. Especially for local development, this is much faster
|
|
// than running the tests serially.
|
|
//
|
|
// In vitest, each thread is assigned a unique, numerical id (`process.env.VITEST_POOL_ID`). We
|
|
// append this id to the local rpc url (e.g. `http://127.0.0.1:8545/<ID>`).
|
|
//
|
|
// Whenever a request hits the proxy server at this url, it spawns (or reuses) an anvil instance
|
|
// at a randomly assigned port and proxies the request to it. The anvil instance is added to a
|
|
// [id:port] mapping for future request and is kept alive until the test suite finishes.
|
|
//
|
|
// Since each thread processes one test file after the other, we don't have to worry about
|
|
// non-deterministic behavior caused by multiple tests hitting the same anvil instance concurrently
|
|
// as long as we avoid `test.concurrent()`.
|
|
//
|
|
// We still need to remember to reset the anvil instance between test files. This is generally
|
|
// handled in `setup.ts` but may require additional resetting (e.g. via `afterAll`), in case of
|
|
// any custom per-test adjustments that persist beyond `anvil_reset`.
|
|
const shutdown = await Promise.all([
|
|
...Object.values(executionInstances).map((instance) => instance.start()),
|
|
...Object.values(bundlerInstances).map((instance) => instance.start()),
|
|
])
|
|
return () => Promise.all(shutdown.map((fn) => fn()))
|
|
}
|