aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-02-02 11:57:24 -0800
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-02-02 11:57:36 -0800
commit440a21eb1d4d75eb23f2d53ed665fec44e7eab8e (patch)
tree3c2ba99c69623f7ce9b3e6af8ba1ff3f00dfacb9
parent2bc4858346087b987321236b2caf0331e6175d94 (diff)
downloadbun-440a21eb1d4d75eb23f2d53ed665fec44e7eab8e.tar.gz
bun-440a21eb1d4d75eb23f2d53ed665fec44e7eab8e.tar.zst
bun-440a21eb1d4d75eb23f2d53ed665fec44e7eab8e.zip
Add bun-test to run `bun wiptest`
-rw-r--r--packages/bun-test/.gitignore3
-rw-r--r--packages/bun-test/README.md3
-rwxr-xr-xpackages/bun-test/bun.lockbbin0 -> 1575 bytes
-rw-r--r--packages/bun-test/package.json11
-rw-r--r--packages/bun-test/src/runner.ts79
-rw-r--r--packages/bun-test/tsconfig.json16
6 files changed, 112 insertions, 0 deletions
diff --git a/packages/bun-test/.gitignore b/packages/bun-test/.gitignore
new file mode 100644
index 000000000..e8034cc5f
--- /dev/null
+++ b/packages/bun-test/.gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+.env
+node_modules
diff --git a/packages/bun-test/README.md b/packages/bun-test/README.md
new file mode 100644
index 000000000..5d5471101
--- /dev/null
+++ b/packages/bun-test/README.md
@@ -0,0 +1,3 @@
+# bun-test
+
+Scripts to run Bun's tests using `bun wiptest`.
diff --git a/packages/bun-test/bun.lockb b/packages/bun-test/bun.lockb
new file mode 100755
index 000000000..ac8b84c5f
--- /dev/null
+++ b/packages/bun-test/bun.lockb
Binary files differ
diff --git a/packages/bun-test/package.json b/packages/bun-test/package.json
new file mode 100644
index 000000000..531b93ec8
--- /dev/null
+++ b/packages/bun-test/package.json
@@ -0,0 +1,11 @@
+{
+ "private": true,
+ "dependencies": {},
+ "devDependencies": {
+ "bun-types": "canary",
+ "prettier": "^2.8.2"
+ },
+ "scripts": {
+ "test": "bun run src/runner.ts"
+ }
+}
diff --git a/packages/bun-test/src/runner.ts b/packages/bun-test/src/runner.ts
new file mode 100644
index 000000000..37ae1ed05
--- /dev/null
+++ b/packages/bun-test/src/runner.ts
@@ -0,0 +1,79 @@
+import { spawn } from "bun";
+import { readdirSync } from "node:fs";
+import { resolve } from "node:path";
+
+const cwd = resolve("../..");
+const isAction = !!process.env["GITHUB_ACTION"];
+const errorPattern = /error: ([\S\s]*?)(?=\n.*?at (\/.*):(\d+):(\d+))/mgi;
+
+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 (entry.isDirectory()) {
+ yield* findTests(path, query);
+ } else if (entry.isFile() && entry.name.includes(".test.")) {
+ yield path;
+ }
+ }
+}
+
+async function runTest(path: string): Promise<void> {
+ const name = path.replace(cwd, "").slice(1);
+ const runner = await spawn({
+ cwd,
+ cmd: ["bun", "wiptest", path],
+ stdout: "pipe",
+ stderr: "pipe",
+ });
+ const exitCode = await Promise.race([
+ new Promise((resolve) => {
+ setTimeout(() => {
+ runner.kill();
+ resolve(124); // Timed Out
+ }, 60_000);
+ }),
+ runner.exited,
+ ]);
+ if (isAction) {
+ const prefix = exitCode === 0
+ ? "PASS"
+ : `FAIL (exit code ${exitCode})`;
+ console.log(`::group::${prefix} - ${name}`);
+ }
+ for (const stdout of [runner.stdout, runner.stderr]) {
+ if (!stdout) {
+ continue;
+ }
+ const reader = stdout.getReader();
+ while (true) {
+ const { value, done } = await reader.read();
+ if (value) {
+ write(value);
+ }
+ if (done) {
+ break;
+ }
+ }
+ }
+ if (isAction) {
+ console.log("::endgroup::");
+ }
+}
+
+function write(data: Uint8Array): void {
+ console.write(data);
+ if (!isAction) {
+ return;
+ }
+ const text = new TextDecoder().decode(data);
+ for (const [message, _, path, line, col] of text.matchAll(errorPattern)) {
+ const name = path.replace(cwd, "").slice(1);
+ console.log(`::error file=${name},line=${line},col=${col},title=${message}::`);
+ }
+}
+
+const tests = [];
+for (const path of findTests(resolve(cwd, "test/bun.js"))) {
+ tests.push(runTest(path).catch(console.error));
+}
+await Promise.allSettled(tests);
diff --git a/packages/bun-test/tsconfig.json b/packages/bun-test/tsconfig.json
new file mode 100644
index 000000000..1b2f41220
--- /dev/null
+++ b/packages/bun-test/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "compilerOptions": {
+ "lib": ["ESNext"],
+ "module": "ESNext",
+ "target": "ESNext",
+ "moduleResolution": "node",
+ "types": ["bun-types"],
+ "esModuleInterop": true,
+ "allowJs": true,
+ "strict": true,
+ "resolveJsonModule": true
+ },
+ "include": [
+ "src"
+ ]
+}