-
I'm planning to adopt anvil.js with Vitest, but it's not clear to me how new Anvil instances are spawned when using Seems like there are several possible ways that this might behave:
I also imagine this depends on the Vitest threads config. Appreciate any additional info - thanks for building this! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
It's per With this, you can completely drop the Check out the example here: This sets up globalSetup.ts (see vitest.config.ts). It starts a global proxy for the entire test suite: Then, you would configure your rpc clients (e.g. with And then, you can optionally reset your You can also print the anvil logs if a test failed: |
Beta Was this translation helpful? Give feedback.
-
We should probably link directly to this example from the readme! |
Beta Was this translation helpful? Give feedback.
-
I fixed the wording in the readme file. |
Beta Was this translation helpful? Give feedback.
-
Viem already has this setup integrated btw. Logs are printed here for instance: https://github.com/wagmi-dev/viem/actions/runs/4810645056/jobs/8563603002#step:4:926 |
Beta Was this translation helpful? Give feedback.
-
Thanks, this is very helpful. Just noticed an added benefit of using anvil.js - no longer need to remember to run |
Beta Was this translation helpful? Give feedback.
It's per
id
. And since you'd use oneid
per test thread, it's per test essentially.With this, you can completely drop the
threads
option (default istrue
) and simply letvitest
decide how many cores to utilize for your test runs in parallel.Check out the example here:
This sets up globalSetup.ts (see vitest.config.ts). It starts a global proxy for the entire test suite:
https://github.com/wagmi-dev/anvil.js/blob/b09bd0ec8013a674dcc5dbe6885e12425bd1f823/examples/example-vitest/tests/globalSetup.ts#L1-L14
Then, you would configure your rpc clients (e.g. with
viem
) to use http / ws rpc urls like this:http://127.0.0.1:8545/1
. Note the/1
suffix. In avitest
setup, you'd not hard-code that to