aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/bun-linux-build.yml35
-rw-r--r--packages/bun-internal-test/src/runner.node.mjs91
-rw-r--r--packages/bun-internal-test/src/runner.ts2
-rw-r--r--test/bun.js/baz.js1
4 files changed, 76 insertions, 53 deletions
diff --git a/.github/workflows/bun-linux-build.yml b/.github/workflows/bun-linux-build.yml
index b099881ae..748c14c55 100644
--- a/.github/workflows/bun-linux-build.yml
+++ b/.github/workflows/bun-linux-build.yml
@@ -151,6 +151,7 @@ jobs:
name: Tests ${{matrix.tag}}
runs-on: ubuntu-latest
needs: [linux]
+ if: github.event_name == 'pull_request'
timeout-minutes: 10
outputs:
failing_tests: ${{ steps.test.outputs.failing_tests }}
@@ -182,45 +183,31 @@ jobs:
chmod +x bun
sudo mv bun /usr/local/bin/bun
bun --version
- - id: test-node-runner
+ - id: test
name: Test (node runner)
# if: ${{github.event.inputs.use_bun == 'false'}}
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 || true
- - id: write-failing-tests
- name: Check for failing tests
- # if: ${{github.event.inputs.use_bun == 'false'}}
- run: |
- if [ -f failing-tests.txt ]; then
- delimiter="$(openssl rand -hex 8)"
- echo "failing_tests<<${delimiter}" >> "${GITHUB_OUTPUT}"
- # prefix each non-empty line with a markdown bullet point
- cat failing-tests.txt | sed -e 's/^/- /' >> "${GITHUB_OUTPUT}"
- echo "${delimiter}" >> "${GITHUB_OUTPUT}"
-
- echo "failing_tests_count<<$(cat failing-tests.txt | wc -l)" >> "${GITHUB_OUTPUT}"
- fi
-
+ bun install --cwd test/bun.js/third-party/napi_create_external
+ bun install --cwd packages/bun-internal-test
+ node packages/bun-internal-test/src/runner.node.mjs || true
- name: Comment on PR
- if: steps.fmt.outputs.failing_tests != '' && github.event_name == "pull_request"
+ if: steps.test.outputs.failing_tests != '' && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: test-failures-${{matrix.tag}}
message: |
- ❌ @${{ github.actor }} ${{ steps.fmt.outputs.failing_tests_count }} failing tests on ${{ matrix.tag }}:
+ ❌ @${{ github.actor }} ${{ steps.test.outputs.failing_tests_count }} files with test failures on ${{ matrix.tag }}:
- ${{ steps.fmt.outputs.failing_tests }}
+ ${{ steps.test.outputs.failing_tests }}
- **[View test output](https://github.com/repos/${{github.owner}}/${{github.repo}}/actions/runs/${{github.run_id}}/jobs)**
+ **[View test output](https://github.com/oven-sh/bun/actions/runs/${{github.run_id}})**
<sup>[#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}})</sup>
- name: Uncomment on PR
- if: steps.fmt.outputs.failing_tests == '' && github.event_name == "pull_request"
+ if: steps.test.outputs.failing_tests == '' && github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: test-failures-${{matrix.tag}}
@@ -232,5 +219,5 @@ jobs:
<sup>[#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}})</sup>
- id: fail
name: Fail the build
- if: steps.fmt.outputs.failing_tests != ''
+ if: steps.test.outputs.failing_tests != ''
run: exit 1
diff --git a/packages/bun-internal-test/src/runner.node.mjs b/packages/bun-internal-test/src/runner.node.mjs
index 471e1cc41..135ee246e 100644
--- a/packages/bun-internal-test/src/runner.node.mjs
+++ b/packages/bun-internal-test/src/runner.node.mjs
@@ -1,17 +1,16 @@
import * as action from "@actions/core";
import { spawnSync } from "child_process";
-import { fsyncSync, rmSync, writeFileSync, writeSync } from "fs";
+import { fsyncSync, rmSync, statSync, writeFileSync, writeSync } from "fs";
import { readdirSync } from "node:fs";
import { resolve } from "node:path";
import { StringDecoder } from "node:string_decoder";
-import { basename } from "path";
+import { basename, relative } from "path";
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 })) {
@@ -64,28 +63,25 @@ async function runTest(path) {
FORCE_COLOR: "1",
},
});
- if (isAction) {
- const prefix = +exitCode === 0 ? "PASS" : `FAIL`;
- action.startGroup(`${prefix} - ${name}`);
- }
if (+exitCode !== 0) {
failingTests.push(name);
}
- dump(stdout);
-
- if (isAction) {
+ if (isAction && exitCode !== 0) {
findErrors(stdout);
- dump(stderr);
-
- findErrors(stderr);
- } else {
- dump(stderr);
findErrors(stderr);
}
if (isAction) {
+ const prefix = +exitCode === 0 ? "PASS" : `FAIL`;
+ action.startGroup(`${prefix} - ${name}`);
+ }
+
+ dump(stdout);
+ dump(stderr);
+
+ if (isAction) {
action.endGroup();
}
}
@@ -93,25 +89,64 @@ async function runTest(path) {
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 text = new StringDecoder().write(new Buffer(data.buffer)).replaceAll(/\u001b\[.*?m/g, "");
+ let index = 0;
+ do {
+ index = text.indexOf("error: ", index);
+ if (index === -1) {
+ break;
+ }
+
+ const messageEnd = text.indexOf("\n", index);
+ if (messageEnd === -1) {
+ break;
+ }
+ const message = text.slice(index + 7, messageEnd);
+ index = text.indexOf("at ", index);
+ if (index === -1) {
+ break;
+ }
+ const startAt = index;
+ index = text.indexOf("\n", index);
+ if (index === -1) {
+ break;
+ }
+ const at = text.slice(startAt + 3, index);
+ let file = at.slice(0, at.indexOf(":"));
+ if (file.length === 0) {
+ continue;
+ }
-const tests = [];
+ const startLine = at.slice(at.indexOf(":") + 1, at.indexOf(":") + 1 + at.slice(at.indexOf(":") + 1).indexOf(":"));
+ const startColumn = at.slice(at.indexOf(":") + 1 + at.slice(at.indexOf(":") + 1).indexOf(":") + 1);
+
+ if (file.startsWith("/")) {
+ file = relative(cwd, file);
+ }
+
+ action.error(message, { file, startLine, startColumn });
+ } while (index !== -1);
+}
+var tests = [];
+var testFileNames = [];
for (const path of findTests(resolve(cwd, "test/bun.js"))) {
+ testFileNames.push(path);
tests.push(runTest(path).catch(console.error));
}
await Promise.allSettled(tests);
rmSync("failing-tests.txt", { force: true });
-if (failingTests.length > 0) {
- writeFileSync("failing-tests.txt", failingTests.join("\n") + "\n", "utf-8");
+
+if (isAction) {
+ if (failingTests.length > 0) {
+ action.setFailed(`${failingTests.length} files with failing tests`);
+ }
+ action.setOutput("failing_tests", failingTests.map(a => `- \`${a}\``).join("\n"));
+ action.setOutput("failing_tests_count", failingTests.length);
+ action.summary.addHeading(`${tests.length} files with tests ran`).addList(testFileNames);
+ await action.summary.write();
+} else {
+ writeFileSync("failing-tests.txt", failingTests.join("\n"));
}
+
process.exit(failed ? 1 : 0);
diff --git a/packages/bun-internal-test/src/runner.ts b/packages/bun-internal-test/src/runner.ts
index e60057a41..4b660fe23 100644
--- a/packages/bun-internal-test/src/runner.ts
+++ b/packages/bun-internal-test/src/runner.ts
@@ -13,6 +13,8 @@ const errorPattern = /error: ([\S\s]*?)(?=\n.*?at (\/.*):(\d+):(\d+))/gim;
function* findTests(dir: string, query?: string): Generator<string> {
for (const entry of readdirSync(resolve(dir), { encoding: "utf-8", withFileTypes: true })) {
const path = resolve(dir, entry.name);
+ if (path.includes("node_modules")) continue;
+
if (entry.isDirectory()) {
yield* findTests(path, query);
} else if (entry.isFile() && entry.name.includes(".test.")) {
diff --git a/test/bun.js/baz.js b/test/bun.js/baz.js
index 58a9bb4b0..5837bb3bb 100644
--- a/test/bun.js/baz.js
+++ b/test/bun.js/baz.js
@@ -1,3 +1,2 @@
// this file is used in resolve.test.js
-//
export default {};