diff options
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/http/bun-server.test.ts | 48 | ||||
-rw-r--r-- | test/js/bun/net/tcp-server.test.ts | 38 | ||||
-rw-r--r-- | test/js/node/process/process.test.js | 10 |
3 files changed, 96 insertions, 0 deletions
diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index 7d0915b89..37675c25d 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -1,6 +1,54 @@ import { describe, expect, test } from "bun:test"; describe("Server", () => { + test("should not allow Bun.serve without first argument being a object", () => { + expect(() => { + //@ts-ignore + const server = Bun.serve(); + server.stop(true); + }).toThrow("Bun.serve expects an object"); + + [undefined, null, 1, "string", true, false, Symbol("symbol")].forEach(value => { + expect(() => { + //@ts-ignore + const server = Bun.serve(value); + server.stop(true); + }).toThrow("Bun.serve expects an object"); + }); + }); + + test("should not allow Bun.serve with invalid tls option", () => { + [1, "string", true, Symbol("symbol"), false].forEach(value => { + expect(() => { + const server = Bun.serve({ + //@ts-ignore + tls: value, + fetch() { + return new Response("Hello"); + }, + port: 0, + }); + server.stop(true); + }).toThrow("tls option expects an object"); + }); + }); + + test("should allow Bun.serve using null or undefined tls option", () => { + [null, undefined].forEach(value => { + expect(() => { + const server = Bun.serve({ + //@ts-ignore + tls: value, + fetch() { + return new Response("Hello"); + }, + port: 0, + }); + server.stop(true); + }).not.toThrow("tls option expects an object"); + }); + }); + test("returns active port when initializing server with 0 port", () => { const server = Bun.serve({ fetch() { diff --git a/test/js/bun/net/tcp-server.test.ts b/test/js/bun/net/tcp-server.test.ts index d029d9273..18fa29231 100644 --- a/test/js/bun/net/tcp-server.test.ts +++ b/test/js/bun/net/tcp-server.test.ts @@ -58,6 +58,44 @@ it("remoteAddress works", async () => { await prom; }); +it("should not allow invalid tls option", () => { + [1, "string", Symbol("symbol")].forEach(value => { + expect(() => { + // @ts-ignore + const server = Bun.listen({ + socket: { + open(ws) {}, + close() {}, + data() {}, + }, + port: 0, + hostname: "localhost", + tls: value, + }); + server.stop(true); + }).toThrow("tls option expects an object"); + }); +}); + +it("should allow using false, null or undefined tls option", () => { + [false, null, undefined].forEach(value => { + expect(() => { + // @ts-ignore + const server = Bun.listen({ + socket: { + open(ws) {}, + close() {}, + data() {}, + }, + port: 0, + hostname: "localhost", + tls: value, + }); + server.stop(true); + }).not.toThrow("tls option expects an object"); + }); +}); + it("echo server 1 on 1", async () => { // wrap it in a separate closure so the GC knows to clean it up // the sockets & listener don't escape the closure diff --git a/test/js/node/process/process.test.js b/test/js/node/process/process.test.js index f701be1b3..ee181e70c 100644 --- a/test/js/node/process/process.test.js +++ b/test/js/node/process/process.test.js @@ -1,6 +1,7 @@ import { resolveSync, which } from "bun"; import { describe, expect, it } from "bun:test"; import { existsSync, readFileSync, realpathSync } from "fs"; +import { bunExe } from "harness"; import { basename, resolve } from "path"; it("process", () => { @@ -224,3 +225,12 @@ it("process.execArgv", () => { it("process.binding", () => { expect(() => process.binding("buffer")).toThrow(); }); + +it("process.argv", () => { + expect(process.argv).toBeInstanceOf(Array); + expect(process.argv[0]).toBe(bunExe()); + expect(process.argv).toEqual(Bun.argv); + + // assert we aren't creating a new process.argv each call + expect(process.argv).toBe(process.argv); +}); |