Skip to content

Commit

Permalink
feat: add tests workflow for bun and deno (#423)
Browse files Browse the repository at this point in the history
* Update the packages

* Update .gitignore

* Update the test configuration

* Update the workflow

* Update the tests

* Update the workflow

* Update the bun workflow

* Update workflow for deno

* Update workflow for bun

* Update workflow for bun

* Update the vitest configuraiton

* Use consistent test task

* Update bun tasks

* Update the vitest config

* Update the timeout

* Update the workflow for the Deno

* Update the workflow for the Deno

* Update the workflow for the Deno

* Update the workflow for the Deno
  • Loading branch information
nazarhussain authored Feb 27, 2025
1 parent 5041139 commit 089daed
Show file tree
Hide file tree
Showing 16 changed files with 662 additions and 172 deletions.
54 changes: 50 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Tests
on: [pull_request, push]

jobs:
test:
name: Tests
test-node:
name: Tests Node
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -31,7 +31,6 @@ jobs:
run: yarn test:unit
- name: Browsers Tests
run: yarn test:browsers

# Download spec tests with cache
- name: Restore spec tests cache
uses: actions/cache@master
Expand All @@ -41,7 +40,6 @@ jobs:
- name: Download spec tests
run: yarn download-spec-tests
working-directory: packages/ssz

# Run them in different steps to quickly identifying which command failed
# Otherwise just doing `yarn test:spec` you can't tell which specific suite failed
# many of the suites have identical names for minimal and mainnet
Expand All @@ -66,3 +64,51 @@ jobs:
- name: Spec tests bellatrix-mainnet
run: LODESTAR_FORK=bellatrix yarn test:spec-static-mainnet
working-directory: packages/ssz

test-bun:
name: Tests Bun
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Yarn
run: bun install -g npm:yarn
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Generate
run: bun run --filter '*' generate
- name: Unit Tests
run: bun run --bun --filter '*' test:unit

test-deno:
name: Tests Deno
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "22"
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
# Deno does not run task in workspaces if same task exists on root package.json
- name: Clean root scripts
run: cat package.json | jq 'del( .scripts )' > package.json.backup && mv package.json.backup package.json
- name: Generate
run: deno task --recursive generate
- name: Unit Tests
run: deno task --recursive test:unit
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ node_modules
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
!.yarn/versions

# Deno
deno.lock
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeModulesDir": "auto"
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"build": "yarn clean && lerna run build",
"lint": "lerna run lint",
"check-types": "lerna run check-types",
"test:unit": "lerna run test:unit",
"test:browsers": "lerna run test:browsers",
"test": "lerna run test",
"test:unit": "lerna run test:unit",
"benchmark:files": "NODE_OPTIONS='--max_old_space_size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml",
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
Expand All @@ -30,8 +29,8 @@
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^6",
"@vitest/browser": "^2.1.4",
"@vitest/coverage-v8": "^2.1.4",
"@vitest/browser": "^3.0.7",
"@vitest/coverage-v8": "^3.0.7",
"babel-loader": "^8.2.2",
"eslint": "^7.30.0",
"eslint-plugin-import": "^2.23.4",
Expand All @@ -43,8 +42,9 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "~5.4.2",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.1.4",
"vite-plugin-node-polyfills": "^0.23.0",
"vitest": "^3.0.7",
"vitest-in-process-pool": "^2.0.0",
"webdriverio": "^9.2.11",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
Expand Down
5 changes: 1 addition & 4 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
"build:lib": "tsc -p tsconfig.build.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"build": "yarn asbuild && yarn asbuild:simd && yarn generate && yarn build:lib",
"test": "yarn run test:unit",
"test:unit": "vitest run --dir test/unit/",
"test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox",
"test:browsers:chrome": "vitest run --browser chrome --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:firefox": "vitest run --browser firefox --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers": "vitest run --config ./vitest.browser.config.ts --dir test/unit",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test:ci": "yarn test:as-ci"
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/scripts/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// we preprocess the binary data into valid javascript code, a single exportable object.
// which can be statically imported.

import fs from "fs";
import fs from "node:fs";

interface BinaryMeta {
input: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"benchmark:files": "node --max-old-space-size=4096 --expose-gc --loader ts-node/esm ../../node_modules/.bin/benchmark",
"benchmark": "yarn benchmark:files 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test": "vitest run --dir test/unit"
"test:unit": "vitest run --dir test/unit"
},
"pre-push": [
"lint"
Expand Down
3 changes: 1 addition & 2 deletions packages/ssz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"prepublishOnly": "yarn build",
"test": "yarn test:unit",
"benchmark": "node --max-old-space-size=4096 --expose-gc ../../node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test:perf": "node --loader=ts-node/esm' benchmark 'test/perf/**/*.test.ts'",
"test:unit": "vitest run --dir test/unit --coverage --coverage.reporter text --coverage.reporter clover",
"test:unit": "vitest run --dir test/unit",
"test:spec": "yarn test:spec-generic && yarn test:spec-static test:spec-eip-4881",
"test:spec-generic": "vitest run --dir test/spec/generic",
"test:spec-static": "yarn test:spec-static-minimal && yarn test:spec-static-mainnet",
Expand Down
4 changes: 2 additions & 2 deletions packages/ssz/test/spec/generic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, it, expect} from "vitest";
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";
import {ethereumConsensusSpecsTests} from "../../specTestVersioning.js";
import {parseSszGenericValidTestcase, parseSszGenericInvalidTestcase} from "../testRunner.js";
import {runValidSszTest} from "../runValidTest.js";
Expand Down
4 changes: 2 additions & 2 deletions packages/ssz/test/spec/ssz_static.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import {describe, it, vi} from "vitest";
import {isCompositeType, Type} from "../../src/index.js";
import {ssz} from "../lodestarTypes/index.js";
Expand Down
4 changes: 2 additions & 2 deletions packages/ssz/test/spec/testRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";
import {uncompress} from "snappyjs";
import jsyaml from "js-yaml";
import {schema} from "./sszYamlSchema.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/ssz/test/specTestVersioning.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import url from "url";
import {DownloadTestsOptions} from "@lodestar/spec-test-util/downloadTests";

Expand Down
8 changes: 6 additions & 2 deletions packages/ssz/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {defineConfig, mergeConfig} from "vitest/config";
import baseConfig from "../../vitest.base.unit.config";
import baseConfig from "../../vitest.base.unit.config.js";
import {getRuntime} from "../../vitest.base.unit.config.js";

export default mergeConfig(baseConfig, defineConfig({}));
export default mergeConfig(
baseConfig,
defineConfig({test: {coverage: {enabled: getRuntime() === "node", reporter: ["text", "clover"]}}})
);
13 changes: 10 additions & 3 deletions vitest.base.browser.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig, mergeConfig } from "vitest/config";
import {nodePolyfills} from "vite-plugin-node-polyfills";
import { nodePolyfills } from "vite-plugin-node-polyfills";

import baseConfig from "./vitest.base.unit.config";

Expand All @@ -9,17 +9,24 @@ export default mergeConfig(
plugins: [
nodePolyfills({
include: ["buffer", "crypto", "util", "stream"],
globals: {Buffer: true},
globals: { Buffer: true },
protocolImports: true,
}),
],
test: {
browser: {
name: "chrome",
headless: true,
provider: "webdriverio",
screenshotFailures: false,
instances: [{ browser: "chrome" }, { browser: "firefox" }],
},
},
optimizeDeps: {
include: [
"vite-plugin-node-polyfills/shims/buffer",
"vite-plugin-node-polyfills/shims/global",
"vite-plugin-node-polyfills/shims/process",
],
},
})
);
55 changes: 48 additions & 7 deletions vitest.base.unit.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
import path from "node:path";
import {defineConfig} from "vitest/config";
import { defineConfig, ViteUserConfig } from "vitest/config";
const __dirname = new URL(".", import.meta.url).pathname;

export type Runtime = "node" | "deno" | "bun";

export function getRuntime(): Runtime {
if ("bun" in process.versions) return "bun";
if ("deno" in process.versions) return "deno";

return "node";
}

export function getPoolOptions(runtime: Runtime): ViteUserConfig["test"] {
if (runtime === "node") {
return {
pool: "threads",
poolOptions: {
threads: {
singleThread: true,
minThreads: 2,
maxThreads: 10,
},
},
coverage: {
enabled: true,
},
reporters: process.env.GITHUB_ACTIONS
? ["verbose", "hanging-process", "github-actions"]
: [
process.env.TEST_COMPACT_OUTPUT ? "basic" : "verbose",
"hanging-process",
],
};
}

return {
pool: "vitest-in-process-pool",
reporters: [["default", { summary: false }]],
coverage: {
enabled: false,
},
};
}

export default defineConfig({
test: {
...getPoolOptions(getRuntime()),
include: ["**/*.test.ts"],
exclude: [
"**/spec-tests/**",
Expand All @@ -16,12 +58,11 @@ export default defineConfig({
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
],
setupFiles: [path.join(__dirname, "./vitest/setupFiles/customMatchers.ts")],
reporters: process.env.GITHUB_ACTIONS
? ["verbose", "hanging-process", "github-actions"]
: [
process.env.TEST_COMPACT_OUTPUT ? "basic" : "verbose",
"hanging-process",
],
coverage: {
reporter: ["clover", "text"],
},
testTimeout: 15000,
hookTimeout: 15000,
onConsoleLog: () => !process.env.TEST_QUIET_CONSOLE,
},
});
Loading

0 comments on commit 089daed

Please sign in to comment.