aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/bun.js/fs.test.js37
-rw-r--r--test/bun.js/process-args.test.js3
-rw-r--r--test/bun.js/spawn-streaming-stdin.test.ts7
-rw-r--r--test/bun.js/spawn-streaming-stdout-repro.js4
-rw-r--r--test/bun.js/spawn-streaming-stdout.test.ts15
-rw-r--r--test/bun.js/spawn.test.ts1
6 files changed, 36 insertions, 31 deletions
diff --git a/test/bun.js/fs.test.js b/test/bun.js/fs.test.js
index 5e4827672..9408a7e64 100644
--- a/test/bun.js/fs.test.js
+++ b/test/bun.js/fs.test.js
@@ -29,10 +29,7 @@ import fs, {
import { tmpdir } from "node:os";
import { join } from "node:path";
-import {
- ReadStream as ReadStream_,
- WriteStream as WriteStream_,
-} from "../fixtures/export-lazy-fs-streams/export-from";
+import { ReadStream as ReadStream_, WriteStream as WriteStream_ } from "../fixtures/export-lazy-fs-streams/export-from";
import {
ReadStream as ReadStreamStar_,
WriteStream as WriteStreamStar_,
@@ -44,6 +41,10 @@ if (!import.meta.dir) {
import.meta.dir = ".";
}
+function mkdirForce(path) {
+ if (!existsSync(path)) mkdirSync(path, { recursive: true });
+}
+
describe("copyFileSync", () => {
it("should work for files < 128 KB", () => {
const tempdir = `/tmp/fs.test.js/${Date.now()}/1234/hi`;
@@ -624,16 +625,16 @@ describe("fs.WriteStream", () => {
expect(stream instanceof fs.WriteStream).toBe(true);
});
- it("should be able to write to a file", (done) => {
+ it("should be able to write to a file", done => {
const pathToDir = `${tmpdir()}/${Date.now()}`;
- mkdirSync(pathToDir);
+ mkdirForce(pathToDir);
const path = `${pathToDir}/fs-writestream-test.txt`;
const stream = new fs.WriteStream(path, { flags: "w+" });
stream.write("Test file written successfully");
stream.end();
- stream.on("error", (e) => {
+ stream.on("error", e => {
done(e instanceof Error ? e : new Error(e));
});
@@ -671,16 +672,16 @@ describe("fs.WriteStream", () => {
expect(stream instanceof fs.WriteStream).toBe(true);
});
- it("should be able to write to a file with re-exported WriteStream", (done) => {
+ it("should be able to write to a file with re-exported WriteStream", done => {
const pathToDir = `${tmpdir()}/${Date.now()}`;
- mkdirSync(pathToDir);
+ mkdirForce(pathToDir);
const path = `${pathToDir}/fs-writestream-re-exported-test.txt`;
const stream = new WriteStream_(path, { flags: "w+" });
stream.write("Test file written successfully");
stream.end();
- stream.on("error", (e) => {
+ stream.on("error", e => {
done(e instanceof Error ? e : new Error(e));
});
@@ -701,9 +702,9 @@ describe("fs.ReadStream", () => {
expect(stream instanceof fs.ReadStream).toBe(true);
});
- it("should be able to read from a file", (done) => {
+ it("should be able to read from a file", done => {
const pathToDir = `${tmpdir()}/${Date.now()}`;
- mkdirSync(pathToDir);
+ mkdirForce(pathToDir);
const path = `${pathToDir}fs-readstream-test.txt`;
writeFileSync(path, "Test file written successfully", {
@@ -713,13 +714,13 @@ describe("fs.ReadStream", () => {
const stream = new fs.ReadStream(path);
stream.setEncoding("utf8");
- stream.on("error", (e) => {
+ stream.on("error", e => {
done(e instanceof Error ? e : new Error(e));
});
let data = "";
- stream.on("data", (chunk) => {
+ stream.on("data", chunk => {
data += chunk;
});
@@ -757,9 +758,9 @@ describe("fs.ReadStream", () => {
expect(stream instanceof fs.ReadStream).toBe(true);
});
- it("should be able to read from a file, with re-exported ReadStream", (done) => {
+ it("should be able to read from a file, with re-exported ReadStream", done => {
const pathToDir = `${tmpdir()}/${Date.now()}`;
- mkdirSync(pathToDir);
+ mkdirForce(pathToDir);
const path = `${pathToDir}fs-readstream-re-exported-test.txt`;
writeFileSync(path, "Test file written successfully", {
@@ -769,13 +770,13 @@ describe("fs.ReadStream", () => {
const stream = new ReadStream_(path);
stream.setEncoding("utf8");
- stream.on("error", (e) => {
+ stream.on("error", e => {
done(e instanceof Error ? e : new Error(e));
});
let data = "";
- stream.on("data", (chunk) => {
+ stream.on("data", chunk => {
data += chunk;
});
diff --git a/test/bun.js/process-args.test.js b/test/bun.js/process-args.test.js
index 96017266b..a2c79616f 100644
--- a/test/bun.js/process-args.test.js
+++ b/test/bun.js/process-args.test.js
@@ -1,10 +1,11 @@
import { spawn } from "bun";
import { test, expect } from "bun:test";
+import { bunExe } from "./bunExe";
test("args exclude run", async () => {
const arg0 = process.argv[0];
const arg1 = import.meta.dir + "/print-process-args.js";
- const exe = process.versions.bun.includes("debug") ? "bun-debug" : "bun";
+ const exe = bunExe();
const { stdout: s1 } = spawn([exe, "print-process-args.js"], {
cwd: import.meta.dir,
env: { BUN_DEBUG_QUIET_LOGS: "1" },
diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts
index 74bf3dbc9..02067b719 100644
--- a/test/bun.js/spawn-streaming-stdin.test.ts
+++ b/test/bun.js/spawn-streaming-stdin.test.ts
@@ -3,6 +3,7 @@ import { spawn } from "bun";
import { bunExe } from "./bunExe";
import { gcTick } from "gc";
import { closeSync, openSync } from "fs";
+import { bunEnv } from "./bunEnv";
const N = 100;
test("spawn can write to stdin multiple chunks", async () => {
@@ -11,13 +12,11 @@ test("spawn can write to stdin multiple chunks", async () => {
var exited;
await (async function () {
const proc = spawn({
- cmd: ["bun-debug", import.meta.dir + "/stdin-repro.js"],
+ cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"],
stdout: "pipe",
stdin: "pipe",
stderr: Bun.file("/tmp/out.log"),
- env: {
- BUN_DEBUG_QUIET_LOGS: 1,
- },
+ env: bunEnv,
});
exited = proc.exited;
var counter = 0;
diff --git a/test/bun.js/spawn-streaming-stdout-repro.js b/test/bun.js/spawn-streaming-stdout-repro.js
index 7279574bf..3976ff095 100644
--- a/test/bun.js/spawn-streaming-stdout-repro.js
+++ b/test/bun.js/spawn-streaming-stdout-repro.js
@@ -1,3 +1,5 @@
+var writer = Bun.stdout.writer();
setInterval(() => {
- console.log("Wrote to stdout");
+ writer.write("Wrote to stdout\n");
+ writer.flush();
}, 20);
diff --git a/test/bun.js/spawn-streaming-stdout.test.ts b/test/bun.js/spawn-streaming-stdout.test.ts
index fac696087..bda1031ad 100644
--- a/test/bun.js/spawn-streaming-stdout.test.ts
+++ b/test/bun.js/spawn-streaming-stdout.test.ts
@@ -3,6 +3,7 @@ import { spawn } from "bun";
import { bunExe } from "./bunExe";
import { gcTick } from "gc";
import { closeSync, openSync } from "fs";
+import { bunEnv } from "./bunEnv";
test("spawn can read from stdout multiple chunks", async () => {
gcTick(true);
@@ -14,19 +15,17 @@ test("spawn can read from stdout multiple chunks", async () => {
var exited;
const proc = spawn({
cmd: [bunExe(), import.meta.dir + "/spawn-streaming-stdout-repro.js"],
+ stdin: "ignore",
stdout: "pipe",
stderr: "ignore",
- env: {
- BUN_DEBUG_QUIET_LOGS: 1,
- },
+ env: bunEnv,
});
- exited = proc.exited;
+ var chunks = [];
let counter = 0;
try {
for await (var chunk of proc.stdout) {
- expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdout\n");
+ chunks.push(chunk);
counter++;
-
if (counter > 3) break;
}
} catch (e) {
@@ -34,7 +33,9 @@ test("spawn can read from stdout multiple chunks", async () => {
throw e;
}
expect(counter).toBe(4);
- await exited;
+ // TODO: fix bug with returning SIGHUP instead of exit code 1
+ proc.kill();
+ expect(Buffer.concat(chunks).toString()).toBe("Wrote to stdout\n".repeat(4));
})();
const newMaxFD = openSync("/dev/null", "w");
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts
index 84b0071ea..def0330ee 100644
--- a/test/bun.js/spawn.test.ts
+++ b/test/bun.js/spawn.test.ts
@@ -2,6 +2,7 @@ import { ArrayBufferSink, readableStreamToText, spawn, spawnSync, write } from "
import { describe, expect, it } from "bun:test";
import { gcTick as _gcTick } from "./gc";
import { rmdirSync, unlinkSync, rmSync, writeFileSync } from "node:fs";
+import { bunEnv } from "./bunEnv";
for (let [gcTick, label] of [
[_gcTick, "gcTick"],