Skip to content

Commit 51efa3d

Browse files
authored
chore: update the test runner (#7404)
**Motivation** Update vitest and browser engine. **Description** - Move root level shared configs to `configs` directory - Update to vitest 3.x - Migrate from `webdriverio` to `playwright` which is more stable and recommended by Vitest. **NOTE** Reverted the `playwright` upgrade. See the comments. https://github.com/ChainSafe/lodestar/blob/d2a7af03086730320860a98dd50979aeb9e5f7b8/configs/vitest.config.base.browser.ts#L41-L43 **Steps to test or reproduce** Run all tests
1 parent 2fc5490 commit 51efa3d

File tree

76 files changed

+1661
-1610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1661
-1610
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ If you observe following error running any of the test files that means you are
7171
- Before running the tests, make sure to switch to the package directory (e.g. `packages/beacon-node`) to speed up test execution
7272

7373
```sh
74-
LODESTAR_PRESET=minimal yarn vitest --run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing
74+
LODESTAR_PRESET=minimal yarn vitest run --bail 1 --config vitest.spec.config.ts test/spec/presets/sanity.test.ts -t attester_slashing
7575
```
7676

7777
## Docker

biome.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"useIgnoreFile": true
77
},
88
"files": {
9-
"include": ["packages/*/src/**/*.ts", "packages/*/test/**/*.ts"]
9+
"include": ["packages/*/src/**/*.ts", "packages/*/test/**/*.ts", "configs/**/*.ts"]
1010
},
1111
"formatter": {
1212
"enabled": true,

vite.base.config.ts renamed to configs/vite.config.base.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import {visualizer} from "rollup-plugin-visualizer";
12
import {UserConfig, defineConfig} from "vite";
23
import {nodePolyfills} from "vite-plugin-node-polyfills";
3-
import {visualizer} from "rollup-plugin-visualizer";
44
import topLevelAwait from "vite-plugin-top-level-await";
5-
import {blsBrowserPlugin} from "./scripts/vite/plugins/blsBrowserPlugin.js";
5+
import {blsBrowserPlugin} from "../scripts/vite/plugins/blsBrowserPlugin.js";
66

77
export function getBaseViteConfig(
88
pkgInfo: {
@@ -41,10 +41,12 @@ export function getBaseViteConfig(
4141
banner,
4242
legalComments: "none",
4343
sourcemap: "inline",
44+
supported: {
45+
"top-level-await": true,
46+
},
4447
},
4548
build: {
46-
// "modules" refer to ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14']
47-
target: "modules",
49+
target: "es2022",
4850
outDir: "dist",
4951
sourcemap: true,
5052
minify: true,
@@ -57,13 +59,10 @@ export function getBaseViteConfig(
5759
formats: ["es"],
5860
name: libName,
5961
fileName: (format) => {
60-
if (format === "esm" || format === "es") {
61-
return `${libName.toLowerCase()}.min.mjs`;
62-
} else if (format === "cjs") {
63-
return `${libName.toLowerCase()}.min.cjs`;
64-
} else {
65-
return `${libName.toLowerCase()}.min.${format}.js`;
66-
}
62+
if (format === "esm" || format === "es") return `${libName.toLowerCase()}.min.mjs`;
63+
if (format === "cjs") return `${libName.toLowerCase()}.min.cjs`;
64+
65+
return `${libName.toLowerCase()}.min.${format}.js`;
6766
},
6867
},
6968
rollupOptions: {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/// <reference types="@vitest/browser/providers/webdriverio" />
2+
3+
import path from "node:path";
4+
import {defineConfig} from "vitest/config";
5+
const __dirname = new URL(".", import.meta.url).pathname;
6+
import {nodePolyfills} from "vite-plugin-node-polyfills";
7+
import topLevelAwait from "vite-plugin-top-level-await";
8+
import {blsBrowserPlugin} from "../scripts/vite/plugins/blsBrowserPlugin.js";
9+
10+
export default defineConfig({
11+
plugins: [
12+
topLevelAwait(),
13+
blsBrowserPlugin(),
14+
nodePolyfills({
15+
include: ["buffer", "process", "util", "string_decoder", "url", "querystring", "events"],
16+
globals: {Buffer: true, process: true},
17+
protocolImports: true,
18+
}),
19+
],
20+
test: {
21+
include: ["**/*.test.ts"],
22+
exclude: [
23+
"**/*.node.test.ts",
24+
"**/node_modules/**",
25+
"**/dist/**",
26+
"**/lib/**",
27+
"**/cypress/**",
28+
"**/.{idea,git,cache,output,temp}/**",
29+
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
30+
],
31+
setupFiles: [path.join(__dirname, "../scripts/vitest/setupFiles/customMatchers.ts")],
32+
reporters: ["default", "hanging-process"],
33+
coverage: {
34+
enabled: false,
35+
},
36+
browser: {
37+
enabled: true,
38+
headless: true,
39+
ui: false,
40+
screenshotFailures: false,
41+
// Recommended provider is `playwright` but it's causing following error on CI
42+
// Error: Failed to connect to the browser session "af5be85a-7f29-4299-b680-b07f0cfc2520" within the timeout.
43+
// TODO: Debug the issue in later versions of playwright and vitest
44+
provider: "webdriverio",
45+
connectTimeout: 90_0000,
46+
instances: [
47+
// TODO: Add support for webkit when available
48+
// Invalid types from webdriverio for capabilities
49+
{
50+
browser: "firefox",
51+
maxConcurrency: 1,
52+
capabilities: {
53+
browserVersion: "stable",
54+
},
55+
} as never,
56+
// Invalid types from webdriverio for capabilities
57+
{
58+
browser: "chrome",
59+
maxConcurrency: 1,
60+
capabilities: {
61+
browserVersion: "stable",
62+
},
63+
} as never,
64+
],
65+
},
66+
},
67+
resolve: {
68+
alias: {
69+
"node:perf_hooks": path.join(__dirname, "../scripts/vitest/polyfills/perf_hooks.js"),
70+
},
71+
},
72+
optimizeDeps: {
73+
include: [
74+
"vite-plugin-node-polyfills/shims/buffer",
75+
"vite-plugin-node-polyfills/shims/global",
76+
"vite-plugin-node-polyfills/shims/process",
77+
],
78+
},
79+
});

vitest.base.e2e.config.ts renamed to configs/vitest.config.base.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {defineConfig, mergeConfig} from "vitest/config";
2-
import vitestConfig from "./vitest.base.unit.config.js";
2+
import vitestConfig from "./vitest.config.base.unit.js";
33

44
export default mergeConfig(
55
vitestConfig,

configs/vitest.config.base.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {defineConfig, mergeConfig} from "vitest/config";
2+
import vitestConfig from "./vitest.config.base.unit.js";
3+
4+
export default mergeConfig(
5+
vitestConfig,
6+
defineConfig({
7+
test: {
8+
coverage: {
9+
enabled: false,
10+
},
11+
// There are tests which is taking over 10 minutes.
12+
// ✓ test/spec/presets/epoch_processing.test.ts > electra/epoch_processing/rewards_and_penalties/pyspec_tests > electra/epoch_processing/rewards_and_penalties/pyspec_tests/full_attestations_one_validaor_one_gwei 572377ms
13+
// So I have to increase these values to such extreme
14+
testTimeout: 1000 * 60 * 15,
15+
hookTimeout: 1000 * 60 * 15,
16+
passWithNoTests: true,
17+
pool: "threads",
18+
poolOptions: {
19+
threads: {
20+
isolate: false,
21+
},
22+
},
23+
},
24+
})
25+
);

vitest.base.unit.config.ts renamed to configs/vitest.config.base.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,18 @@ export default defineConfig({
1717
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
1818
],
1919
setupFiles: [
20-
path.join(__dirname, "./scripts/vitest/setupFiles/customMatchers.ts"),
21-
path.join(__dirname, "./scripts/vitest/setupFiles/dotenv.ts"),
20+
path.join(__dirname, "../scripts/vitest/setupFiles/customMatchers.ts"),
21+
path.join(__dirname, "../scripts/vitest/setupFiles/dotenv.ts"),
2222
],
2323
reporters: process.env.GITHUB_ACTIONS
2424
? ["verbose", "hanging-process", "github-actions"]
2525
: [process.env.TEST_COMPACT_OUTPUT ? "basic" : "verbose", "hanging-process"],
2626
coverage: {
27-
enabled: process.env.CI === "true",
28-
clean: true,
29-
all: false,
30-
extension: [".ts"],
31-
provider: "v8",
32-
reporter: [["lcovonly", {file: "lcov.info"}], ["text"]],
33-
reportsDirectory: "./coverage",
34-
exclude: [
35-
"**/*.d.ts",
36-
"**/*.js",
37-
"**/lib/**",
38-
"**/coverage/**",
39-
"**/scripts/**",
40-
"**/test/**",
41-
"**/types/**",
42-
"**/bin/**",
43-
"**/node_modules/**",
44-
"**/spec-tests/**",
45-
"**/spec-tests-bls/**",
46-
],
27+
enabled: false,
4728
},
48-
diff: process.env.TEST_COMPACT_DIFF ? path.join(import.meta.dirname, "./scripts/vitest/vitest.diff.ts") : undefined,
29+
diff: process.env.TEST_COMPACT_DIFF
30+
? path.join(import.meta.dirname, "../scripts/vitest/vitest.diff.ts")
31+
: undefined,
4932
onConsoleLog: () => !process.env.TEST_QUIET_CONSOLE,
5033
},
5134
});

configs/vitest.config.base.unit.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import path from "node:path";
2+
import {defineConfig, mergeConfig} from "vitest/config";
3+
const __dirname = new URL(".", import.meta.url).pathname;
4+
import sharedConfig from "./vitest.config.base.js";
5+
6+
export default mergeConfig(
7+
sharedConfig,
8+
defineConfig({
9+
test: {
10+
coverage: {
11+
enabled: process.env.CI === "true",
12+
clean: true,
13+
all: false,
14+
extension: [".ts"],
15+
provider: "v8",
16+
reporter: [["lcovonly", {file: "lcov.info"}], ["text"]],
17+
reportsDirectory: "./coverage",
18+
exclude: [
19+
"**/*.d.ts",
20+
"**/*.js",
21+
"**/lib/**",
22+
"**/coverage/**",
23+
"**/scripts/**",
24+
"**/test/**",
25+
"**/types/**",
26+
"**/bin/**",
27+
"**/node_modules/**",
28+
"**/spec-tests/**",
29+
"**/spec-tests-bls/**",
30+
],
31+
},
32+
// There are some tests which are taking huge time
33+
// test/unit/chain/rewards/blockRewards.test.ts > chain / rewards / blockRewards > Normal case 73869ms
34+
// for now I tried to identify such tests an increase the limit a bit higher
35+
testTimeout: 20_000,
36+
hookTimeout: 20_000,
37+
},
38+
})
39+
);

package.json

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@
2929
"docs:lint:fix": "prettier '**/*.md' --write",
3030
"test": "lerna run test --concurrency 1",
3131
"test:unit": "lerna run test:unit --concurrency 1",
32-
"test:browsers": "lerna run test:browsers",
32+
"test:browsers": "lerna run test:browsers --concurrency 1",
3333
"test:e2e": "lerna run test:e2e --concurrency 1",
3434
"test:e2e:sim": "lerna run test:e2e:sim",
3535
"download-spec-tests": "lerna run download-spec-tests",
3636
"test:spec": "lerna run test:spec",
37-
"test-coverage:unit": "c8 --config .c8rc.json --report-dir coverage/unit/ --all npm run test:unit",
38-
"test-coverage:browsers": "c8 --config .c8rc.json --report-dir coverage/browsers/ --all npm run test:browsers",
39-
"test-coverage:e2e": "c8 --config .c8rc.json --report-dir coverage/e2e/ --all npm run test:e2e",
40-
"test-coverage:e2e-sim": "c8 --config .c8rc.json --report-dir coverage/e2e-sim/ --all npm run test:e2e:sim",
41-
"test-coverage:spec": "c8 --config .c8rc.json --report-dir coverage/spec/ --all npm run test:spec",
4237
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
4338
"benchmark:files": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable",
4439
"release:create-rc": "node scripts/release/create_rc.mjs",
@@ -51,8 +46,8 @@
5146
"@chainsafe/benchmark": "^1.2.3",
5247
"@biomejs/biome": "^1.9.3",
5348
"@types/node": "^20.12.8",
54-
"@vitest/browser": "^2.0.4",
55-
"@vitest/coverage-v8": "^2.0.4",
49+
"@vitest/browser": "^3.0.6",
50+
"@vitest/coverage-v8": "^3.0.6",
5651
"crypto-browserify": "^3.12.0",
5752
"dotenv": "^16.4.5",
5853
"electron": "^26.2.2",
@@ -72,20 +67,18 @@
7267
"ts-node": "^10.9.2",
7368
"typescript": "^5.7.3",
7469
"typescript-docs-verifier": "^2.5.3",
75-
"vite": "^5.3.4",
76-
"vite-plugin-dts": "^3.9.1",
77-
"vite-plugin-node-polyfills": "^0.22.0",
78-
"vite-plugin-top-level-await": "^1.4.2",
79-
"vitest": "^2.0.4",
80-
"vitest-when": "^0.4.1",
70+
"vite": "^6.0.11",
71+
"vite-plugin-dts": "^4.5.0",
72+
"vite-plugin-node-polyfills": "^0.23.0",
73+
"vite-plugin-top-level-await": "^1.5.0",
74+
"vitest": "^3.0.6",
75+
"vitest-when": "^0.6.0",
8176
"wait-port": "^1.1.0",
82-
"webdriverio": "^8.36.1"
77+
"webdriverio": "^9.7.2"
8378
},
8479
"resolutions": {
85-
"@puppeteer/browsers": "^2.1.0",
8680
"dns-over-http-resolver": "^2.1.1",
8781
"loupe": "^2.3.6",
88-
"vite": "^5.3.4",
8982
"testcontainers/**/nan": "^2.19.0"
9083
}
9184
}

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"lint": "biome check src/ test/",
6767
"lint:fix": "yarn run lint --write",
6868
"test": "yarn test:unit",
69-
"test:unit": "vitest --run --dir test/unit/",
69+
"test:unit": "vitest run --dir test/unit/",
7070
"check-readme": "typescript-docs-verifier"
7171
},
7272
"dependencies": {

0 commit comments

Comments
 (0)