diff options
author | 2023-03-04 18:11:54 -0800 | |
---|---|---|
committer | 2023-03-04 18:11:54 -0800 | |
commit | 571ba8ef3ffc595ce2914948cfd5b2ff28837816 (patch) | |
tree | f9e73670420cc5debc9a0882df526425b54a5520 | |
parent | 9963e1c3d8f062829ec104843f0b140819796b42 (diff) | |
download | bun-571ba8ef3ffc595ce2914948cfd5b2ff28837816.tar.gz bun-571ba8ef3ffc595ce2914948cfd5b2ff28837816.tar.zst bun-571ba8ef3ffc595ce2914948cfd5b2ff28837816.zip |
Add node runner
-rw-r--r-- | .github/workflows/run-test-manually.yml | 16 | ||||
-rw-r--r-- | packages/bun-internal-test/src/runner.node.mjs | 80 |
2 files changed, 96 insertions, 0 deletions
diff --git a/.github/workflows/run-test-manually.yml b/.github/workflows/run-test-manually.yml index 9cd2155e7..31c34c6b9 100644 --- a/.github/workflows/run-test-manually.yml +++ b/.github/workflows/run-test-manually.yml @@ -9,6 +9,11 @@ on: required: true default: "canary" type: string + use_bun: + description: "Bun or Node?" + required: true + default: true + type: boolean jobs: linux-test: name: Tests ${{matrix.tag}} ${{github.event.inputs.version}} @@ -34,6 +39,7 @@ jobs: sudo cp node_modules/@oven/bun-${{matrix.tag}}/bin/bun /usr/bin/bun - id: test name: Test + if: ${{github.event.inputs.use_bun}} run: | bun install bun install --cwd test/bun.js @@ -41,3 +47,13 @@ jobs: cd packages/bun-internal-test bun install bun run test + - id: test-node-runner + name: Test (node runner) + if: ${{!github.event.inputs.use_bun}} + run: | + bun install + bun install --cwd test/bun.js + bun install --cwd test/bun.js/third-party/body-parser-test + cd packages/bun-internal-test + bun install + node src/runner.node.mjs diff --git a/packages/bun-internal-test/src/runner.node.mjs b/packages/bun-internal-test/src/runner.node.mjs new file mode 100644 index 000000000..540c90a37 --- /dev/null +++ b/packages/bun-internal-test/src/runner.node.mjs @@ -0,0 +1,80 @@ +import * as action from "@actions/core"; +import { spawnSync } from "child_process"; +import { readdirSync } from "node:fs"; +import { resolve } from "node:path"; +import { StringDecoder } from "node:string_decoder"; +import { fileURLToPath } from "url"; + +const cwd = resolve(fileURLToPath(import.meta.url), "../../../../"); +process.chdir(cwd); + +const isAction = !!process.env["GITHUB_ACTION"]; +const errorPattern = /error: ([\S\s]*?)(?=\n.*?at (\/.*):(\d+):(\d+))/gim; + +function* findTests(dir, query) { + for (const entry of readdirSync(resolve(dir), { encoding: "utf-8", withFileTypes: true })) { + const path = resolve(dir, entry.name); + if (entry.isDirectory()) { + yield* findTests(path, query); + } else if (entry.isFile() && entry.name.includes(".test.")) { + yield path; + } + } +} + +async function runTest(path) { + const name = path.replace(cwd, "").slice(1); + const { + stdout, + stderr, + status: exitCode, + } = spawnSync("bun", ["test", path], { + stdio: ["ignore", "pipe", "pipe"], + timeout: 10_000, + env: { + ...process.env, + FORCE_COLOR: "1", + }, + }); + + if (isAction) { + const prefix = +exitCode === 0 ? "PASS" : `FAIL`; + action.startGroup(`${prefix} - ${name}`); + } + + process.stdout.write(stdout); + + if (isAction) { + findErrors(stdout); + process.stderr.write(stderr); + findErrors(stderr); + } else { + process.stderr.write(stderr); + findErrors(stderr); + } + + if (isAction) { + action.endGroup(); + } +} + +let failed = false; + +function findErrors(data) { + const text = new StringDecoder().write(new Buffer(data.buffer)); + for (const [message, _, path, line, col] of text.matchAll(errorPattern)) { + failed = true; + action.error(message, { + file: path.replace(cwd, "").slice(1), + startLine: parseInt(line), + startColumn: parseInt(col), + }); + } +} + +const tests = []; +for (const path of findTests(resolve(cwd, "test/bun.js"))) { + tests.push(runTest(path).catch(console.error)); +} +await Promise.allSettled(tests); +process.exit(failed ? 1 : 0); |