diff --git a/.changeset/funny-pumas-bathe.md b/.changeset/funny-pumas-bathe.md new file mode 100644 index 00000000000..8b9f81a97fb --- /dev/null +++ b/.changeset/funny-pumas-bathe.md @@ -0,0 +1,4 @@ +--- +--- + +chore: stop using `setupFiles` in tests diff --git a/vitest.env.ts b/vitest.env.ts deleted file mode 100644 index 5d994aa1248..00000000000 --- a/vitest.env.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { hexlify } from '@fuel-ts/utils'; - -import faucets from './.fuel-core/configs/faucets.json'; - -/** - * Gets the private key for the current Vitest worker. - * - * The PK is basically the current worker's ID. This allows us to - * have a unique faucet wallet for each file being tested and prevents - * tests from trying to access to the same coins and fail. - * - * Both `faucets.json` and `initial_state.coins` in `chainConfig.json` - * were manually generated to support at most 16 workers. - * - * For each wallet in `faucets.json`, there are three coins for each - * of the following Asset IDs: - * - 0x0000000000000000000000000000000000000000000000000000000000000000 - * - 0x0101010101010101010101010101010101010101010101010101010101010101 - * - 0x0202020202020202020202020202020202020202020202020202020202020202 - * - * See: https://vitest.dev/config/#setupfiles - */ -const getPrivateKeyForCurrentWorker = () => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const workerId = Number.parseInt(process.env.VITEST_POOL_ID!, 10) || 1; - - if (workerId > faucets.length) { - throw new Error(`At most ${faucets.length} workers are supported.`); - } - - const privateKey = hexlify(Uint8Array.from([workerId])); - return privateKey; -}; - -process.env.FUEL_CORE_PATH = 'fuels-core'; - -process.env.GENESIS_SECRET = - process.env.FUEL_NETWORK_GENESIS_KEY || getPrivateKeyForCurrentWorker(); diff --git a/vitest.global-setup.ts b/vitest.global-setup.ts new file mode 100644 index 00000000000..48593227974 --- /dev/null +++ b/vitest.global-setup.ts @@ -0,0 +1,3 @@ +export default function setup() { + process.env.FUEL_CORE_PATH = 'fuels-core'; +} diff --git a/vitest.shared.config.mts b/vitest.shared.config.mts index 72525696119..12acd3b8a2c 100644 --- a/vitest.shared.config.mts +++ b/vitest.shared.config.mts @@ -14,6 +14,7 @@ export default defineConfig({ ], esbuild: { target: "es2022" }, test: { + globalSetup: ["vitest.global-setup.ts"], coverage: { enabled: true, provider: "istanbul", @@ -40,7 +41,6 @@ export default defineConfig({ "/apps/demo-react-vite", ], globals: true, - setupFiles: ["./vitest.env.ts"], env: loadEnv(mode, process.cwd(), ""), poolOptions: { threads: {