aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/http/error-response.js8
-rw-r--r--test/js/bun/http/serve.test.ts15
-rw-r--r--test/js/node/process/call-raise.js15
-rw-r--r--test/js/node/process/process-signal-handler.fixture.js63
-rw-r--r--test/js/node/process/process.test.js26
-rw-r--r--test/js/web/console/console-log.expected.txt8
-rw-r--r--test/js/web/console/console-log.js6
7 files changed, 138 insertions, 3 deletions
diff --git a/test/js/bun/http/error-response.js b/test/js/bun/http/error-response.js
new file mode 100644
index 000000000..3284c146b
--- /dev/null
+++ b/test/js/bun/http/error-response.js
@@ -0,0 +1,8 @@
+const s = Bun.serve({
+ fetch(req, res) {
+ s.stop(true);
+ throw new Error("1");
+ },
+ port: 0,
+});
+fetch(`http://${s.hostname}:${s.port}`).then(res => console.log(res.status));
diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts
index 7182ba68d..bba35c085 100644
--- a/test/js/bun/http/serve.test.ts
+++ b/test/js/bun/http/serve.test.ts
@@ -2,8 +2,10 @@ import { file, gc, Serve, serve, Server } from "bun";
import { afterEach, describe, it, expect, afterAll } from "bun:test";
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";
+import { bunExe, bunEnv } from "harness";
import { renderToReadableStream } from "react-dom/server";
import app_jsx from "./app.jsx";
+import { spawn } from "child_process";
type Handler = (req: Request) => Response;
afterEach(() => gc(true));
@@ -980,6 +982,19 @@ describe("should support Content-Range with Bun.file()", () => {
}
});
+it("formats error responses correctly", async () => {
+ const c = spawn(bunExe(), ["./error-response.js"], { cwd: import.meta.dir, env: bunEnv });
+
+ var output = "";
+ c.stderr.on("data", chunk => {
+ output += chunk.toString();
+ });
+ c.stderr.on("end", () => {
+ expect(output).toContain('throw new Error("1");');
+ c.kill();
+ });
+});
+
it("request body and signal life cycle", async () => {
{
const headers = {
diff --git a/test/js/node/process/call-raise.js b/test/js/node/process/call-raise.js
new file mode 100644
index 000000000..898906759
--- /dev/null
+++ b/test/js/node/process/call-raise.js
@@ -0,0 +1,15 @@
+import { dlopen } from "bun:ffi";
+
+var lazyRaise;
+export function raise(signal) {
+ if (!lazyRaise) {
+ const suffix = process.platform === "darwin" ? "dylib" : "so.6";
+ lazyRaise = dlopen(`libc.${suffix}`, {
+ raise: {
+ args: ["int"],
+ returns: "int",
+ },
+ }).symbols.raise;
+ }
+ lazyRaise(signal);
+}
diff --git a/test/js/node/process/process-signal-handler.fixture.js b/test/js/node/process/process-signal-handler.fixture.js
new file mode 100644
index 000000000..de5a78bda
--- /dev/null
+++ b/test/js/node/process/process-signal-handler.fixture.js
@@ -0,0 +1,63 @@
+import os from "os";
+import { raise } from "./call-raise";
+
+var counter = 0;
+function done() {
+ counter++;
+ if (counter === 2) {
+ setTimeout(() => {
+ if (counter !== 2) {
+ console.log(counter);
+ console.log("FAIL");
+ process.exit(1);
+ }
+
+ console.log("PASS");
+ process.exit(0);
+ }, 1);
+ }
+}
+
+var counter2 = 0;
+function done2() {
+ counter2++;
+ if (counter2 === 2) {
+ setTimeout(() => {
+ if (counter2 !== 2) {
+ console.log(counter2);
+ console.log("FAIL");
+ process.exit(1);
+ }
+
+ console.log("PASS");
+ process.exit(0);
+ }, 1);
+ }
+}
+
+const SIGUSR1 = os.constants.signals.SIGUSR1;
+const SIGUSR2 = os.constants.signals.SIGUSR2;
+
+switch (process.argv.at(-1)) {
+ case "SIGUSR1": {
+ process.on("SIGUSR1", () => {
+ done();
+ });
+ process.on("SIGUSR1", () => {
+ done();
+ });
+ raise(SIGUSR1);
+ break;
+ }
+ case "SIGUSR2": {
+ process.on("SIGUSR2", () => {
+ done2();
+ });
+ process.emit("SIGUSR2");
+ raise(SIGUSR2);
+ break;
+ }
+ default: {
+ throw new Error("Unknown argument: " + process.argv.at(-1));
+ }
+}
diff --git a/test/js/node/process/process.test.js b/test/js/node/process/process.test.js
index e038383de..51825b2b4 100644
--- a/test/js/node/process/process.test.js
+++ b/test/js/node/process/process.test.js
@@ -1,6 +1,6 @@
-import { resolveSync, spawnSync, which } from "bun";
+import { spawnSync, which } from "bun";
import { describe, expect, it } from "bun:test";
-import { existsSync, readFileSync, realpathSync } from "fs";
+import { existsSync, readFileSync } from "fs";
import { bunEnv, bunExe } from "harness";
import { basename, join, resolve } from "path";
@@ -381,6 +381,28 @@ it("process.getuid", () => {
expect(typeof process.getuid()).toBe("number");
});
+describe("signal", () => {
+ const fixture = join(import.meta.dir, "./process-signal-handler.fixture.js");
+ it("simple case works", async () => {
+ const child = Bun.spawn({
+ cmd: [bunExe(), fixture, "SIGUSR1"],
+ env: bunEnv,
+ });
+
+ expect(await child.exited).toBe(0);
+ expect(await new Response(child.stdout).text()).toBe("PASS\n");
+ });
+ it("process.emit will call signal events", async () => {
+ const child = Bun.spawn({
+ cmd: [bunExe(), fixture, "SIGUSR2"],
+ env: bunEnv,
+ });
+
+ expect(await child.exited).toBe(0);
+ expect(await new Response(child.stdout).text()).toBe("PASS\n");
+ });
+});
+
const undefinedStubs = [
"_debugEnd",
"_debugProcess",
diff --git a/test/js/web/console/console-log.expected.txt b/test/js/web/console/console-log.expected.txt
index 97191c8be..332322665 100644
--- a/test/js/web/console/console-log.expected.txt
+++ b/test/js/web/console/console-log.expected.txt
@@ -1,4 +1,6 @@
Hello World!
+0
+-0
123
-123
123.567
@@ -7,6 +9,8 @@ true
false
null
undefined
+Infinity
+-Infinity
Symbol(Symbol Description)
2000-06-27T02:24:34.304Z
[ 123, 456, 789 ]
@@ -29,7 +33,9 @@ Symbol(Symbol Description)
}
Promise { <pending> }
[Function]
-[Function: Foo]
+[Function]
+[class Foo]
+[class]
{}
[Function: foooo]
/FooRegex/
diff --git a/test/js/web/console/console-log.js b/test/js/web/console/console-log.js
index e23a3e9cb..4db40aaac 100644
--- a/test/js/web/console/console-log.js
+++ b/test/js/web/console/console-log.js
@@ -1,4 +1,6 @@
console.log("Hello World!");
+console.log(0);
+console.log(-0);
console.log(123);
console.log(-123);
console.log(123.567);
@@ -7,6 +9,8 @@ console.log(true);
console.log(false);
console.log(null);
console.log(undefined);
+console.log(Infinity);
+console.log(-Infinity);
console.log(Symbol("Symbol Description"));
console.log(new Date(Math.pow(2, 34) * 56));
console.log([123, 456, 789]);
@@ -27,7 +31,9 @@ console.log(new Promise(() => {}));
class Foo {}
console.log(() => {});
+console.log(function () {});
console.log(Foo);
+console.log(class {});
console.log(new Foo());
console.log(function foooo() {});