mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Add node runner
This commit is contained in:
16
.github/workflows/run-test-manually.yml
vendored
16
.github/workflows/run-test-manually.yml
vendored
@@ -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
|
||||
|
||||
80
packages/bun-internal-test/src/runner.node.mjs
Normal file
80
packages/bun-internal-test/src/runner.node.mjs
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user