Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

New instance per request or per test worker? (Vitest) #16

Answered by fubhy
0xOlias asked this question in Q&A
Discussion options

You must be logged in to vote

It's per id. And since you'd use one id per test thread, it's per test essentially.

With this, you can completely drop the threads option (default is true) and simply let vitest 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 a vitest setup, you'd not hard-code that to

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by 0xOlias
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@fubhy
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants