diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bundler/esbuild/default.test.ts | 42 | ||||
-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 |
4 files changed, 138 insertions, 0 deletions
diff --git a/test/bundler/esbuild/default.test.ts b/test/bundler/esbuild/default.test.ts index 215276139..0d1775606 100644 --- a/test/bundler/esbuild/default.test.ts +++ b/test/bundler/esbuild/default.test.ts @@ -6520,4 +6520,46 @@ describe("bundler", () => { `, }, }); + itBundled("default/ConstDeclNotRemovedIfReferencedBeforeDecl", { + files: { + "/entry.js": ` + { + const foo = () => { + return data; + } + const data = 123; + + console.log(foo()); + } + `, + }, + minifySyntax: true, + run: { + stdout: "123", + }, + onAfterBundle(api) { + api.expectFile("/out.js").toContain("data = 123"); + }, + }); + itBundled("default/ConstDeclRemovedIfReferencedBeforeAllUses", { + files: { + "/entry.js": ` + { + const data = 123; + const foo = () => { + return data; + } + + console.log(foo()); + } + `, + }, + minifySyntax: true, + run: { + stdout: "123", + }, + onAfterBundle(api) { + api.expectFile("/out.js").not.toContain("data = 123"); + }, + }); }); 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); +}); |