Skip to content

Commit 2290982

Browse files
authored
test: migrate unit tests to vitest (#637)
* test: migrate unit tests to vitest * fix: downgrade vitest to 3.x for Node 18 CI compatibility * fix: pin vite to 5.x for Node 18 CI compatibility * fix: use vitest 2.x and pin vite 5.x for Node 18 compatibility vitest 3.x/4.x pulls in vite 7.x which requires Node >=20. Also allowlists esbuild CORS advisory (GHSA-67mh-4wv8-2f99) from vitest>vite>esbuild — dev-only, does not affect SDK runtime. * chore: upgrade vitest to 4.x for Node 24 Now that CI targets Node 24, use latest vitest without Node 18 workarounds. Removes vite 5.x resolution pin and esbuild advisory allowlist entry. Scopes vitest to unit tests only via include pattern. * fix: use glob patterns in vitest include for workspace compatibility * fix: increase vitest timeout to 30s for RPC-dependent tests
1 parent 2e6a5b5 commit 2290982

5 files changed

Lines changed: 458 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"typechain": "7.0.0",
5151
"typescript": "^5.7.2",
5252
"viem": "^2.0.0",
53+
"vitest": "^4.1.1",
5354
"yargs": "^17.3.1"
5455
},
5556
"resolutions": {

packages/ethers-viem-compat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
"scripts": {
2626
"build": "rm -rf dist && tsc -p tsconfig.json",
27-
"test:unit": "mocha -r ts-node/register 'tests/**/*.test.ts'",
27+
"test:unit": "vitest run --config ../../vitest.config.ts tests",
2828
"lint": "eslint .",
2929
"format": "prettier './**/*.{js,json,md,ts,yml}' '!./src/lib/abi' --write && yarn run lint --fix"
3030
},

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"test:coverage": "nyc mocha",
3737
"test:fork": "SHOULD_FORK=1 hardhat test tests/fork/*.test.ts",
3838
"test:integration": "mocha tests/integration/ --timeout 30000000 --bail",
39-
"test:unit": "mocha --parallel tests/unit/ --timeout 30000 --bail",
39+
"test:unit": "vitest run --config ../../vitest.config.ts tests/unit",
4040
"test:ci": "nyc --reporter=lcovonly mocha --reporter xunit",
4141
"lint": "eslint .",
4242
"format": "prettier './**/*.{js,json,md,ts,yml}' '!./src/lib/abi' --write && yarn run lint --fix",

vitest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
environment: 'node',
6+
globals: true,
7+
include: ['**/tests/unit/**/*.test.ts', '**/tests/*.test.ts'],
8+
exclude: ['**/node_modules/**', '**/dist/**'],
9+
testTimeout: 30_000,
10+
},
11+
})

0 commit comments

Comments
 (0)