diff --git a/package.json b/package.json index b3979b3..2f77b1e 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ }, "dependencies": { "@browserbasehq/sdk": "^2.6.0", - "@std/expect": "jsr:^1.0.17", "archiver": "^7.0.1", "chalk": "^5.6.2", "commander": "^14.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85f36db..4529f1e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,9 +10,6 @@ importers: "@browserbasehq/sdk": specifier: ^2.6.0 version: 2.6.0 - "@std/expect": - specifier: jsr:^1.0.17 - version: "@jsr/std__expect@1.0.17" archiver: specifier: ^7.0.1 version: 7.0.1 @@ -448,27 +445,6 @@ packages: integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==, } - "@jsr/std__assert@1.0.16": - resolution: - { - integrity: sha512-bX9ih0nR1kQ12/cnQRCQU0ppTCV7MFkP0qjyWxJRoDI8RC5cpTAmLFH/KcFgxmdN4flKkRbub8VtLuyKq+4OxA==, - tarball: https://npm.jsr.io/~/11/@jsr/std__assert/1.0.16.tgz, - } - - "@jsr/std__expect@1.0.17": - resolution: - { - integrity: sha512-+1wHqnotlmsLVrD9nAPTN0ITanwLCYmd9likMB7vn3/4vkTmotv/qUnzwtvegj7utgHrckR4Ksl1NDR8iaW3RQ==, - tarball: https://npm.jsr.io/~/11/@jsr/std__expect/1.0.17.tgz, - } - - "@jsr/std__internal@1.0.12": - resolution: - { - integrity: sha512-6xReMW9p+paJgqoFRpOE2nogJFvzPfaLHLIlyADYjKMUcwDyjKZxryIbgcU+gxiTygn8yCjld1HoI0ET4/iZeA==, - tarball: https://npm.jsr.io/~/11/@jsr/std__internal/1.0.12.tgz, - } - "@nodelib/fs.scandir@2.1.5": resolution: { @@ -2735,17 +2711,6 @@ snapshots: "@jridgewell/resolve-uri": 3.1.2 "@jridgewell/sourcemap-codec": 1.5.5 - "@jsr/std__assert@1.0.16": - dependencies: - "@jsr/std__internal": 1.0.12 - - "@jsr/std__expect@1.0.17": - dependencies: - "@jsr/std__assert": 1.0.16 - "@jsr/std__internal": 1.0.12 - - "@jsr/std__internal@1.0.12": {} - "@nodelib/fs.scandir@2.1.5": dependencies: "@nodelib/fs.stat": 2.0.5 diff --git a/src/cli/dev/server.test.ts b/src/cli/dev/server.test.ts index 5e9a495..ea20bcc 100644 --- a/src/cli/dev/server.test.ts +++ b/src/cli/dev/server.test.ts @@ -1,5 +1,5 @@ import { describe, it, beforeEach } from "node:test"; -import { expect } from "@std/expect"; +import assert from "node:assert"; import { IncomingMessage, ServerResponse } from "node:http"; import { Socket } from "node:net"; @@ -329,19 +329,34 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.setHeaderCalls.length).toBeGreaterThan(0); - expect(res.setHeaderCalls).toContainEqual([ - "Access-Control-Allow-Origin", - "*", - ]); - expect(res.setHeaderCalls).toContainEqual([ - "Access-Control-Allow-Methods", - "GET, POST, OPTIONS", - ]); - expect(res.setHeaderCalls).toContainEqual([ - "Access-Control-Allow-Headers", - "Content-Type", - ]); + assert.ok(res.setHeaderCalls.length > 0); + assert.ok( + res.setHeaderCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify(["Access-Control-Allow-Origin", "*"]), + ), + "Expected CORS origin header", + ); + assert.ok( + res.setHeaderCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + "Access-Control-Allow-Methods", + "GET, POST, OPTIONS", + ]), + ), + "Expected CORS methods header", + ); + assert.ok( + res.setHeaderCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify(["Access-Control-Allow-Headers", "Content-Type"]), + ), + "Expected CORS headers header", + ); }); it("should handle OPTIONS preflight requests", async () => { @@ -350,8 +365,18 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([200]); - expect(res.endCalls).toContainEqual([undefined]); + assert.ok( + res.writeHeadCalls.some( + (call) => JSON.stringify(call) === JSON.stringify([200]), + ), + "Expected 200 status code", + ); + assert.ok( + res.endCalls.some( + (call) => JSON.stringify(call) === JSON.stringify([undefined]), + ), + "Expected end call with undefined", + ); }); }); @@ -362,9 +387,9 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleInvocationNextCalls.length).toBe(1); - expect(mockHandlers.handleInvocationNextCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleInvocationNextCalls[0]?.[1]).toBe(res); + assert.strictEqual(mockHandlers.handleInvocationNextCalls.length, 1); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[0], req); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[1], res); }); }); @@ -375,10 +400,13 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleFunctionInvokeCalls.length).toBe(1); - expect(mockHandlers.handleFunctionInvokeCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleFunctionInvokeCalls[0]?.[1]).toBe(res); - expect(mockHandlers.handleFunctionInvokeCalls[0]?.[2]).toBe("myFunction"); + assert.strictEqual(mockHandlers.handleFunctionInvokeCalls.length, 1); + assert.strictEqual(mockHandlers.handleFunctionInvokeCalls[0]?.[0], req); + assert.strictEqual(mockHandlers.handleFunctionInvokeCalls[0]?.[1], res); + assert.strictEqual( + mockHandlers.handleFunctionInvokeCalls[0]?.[2], + "myFunction", + ); }); it("should handle function names with special characters", async () => { @@ -387,8 +415,9 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleFunctionInvokeCalls.length).toBe(1); - expect(mockHandlers.handleFunctionInvokeCalls[0]?.[2]).toBe( + assert.strictEqual(mockHandlers.handleFunctionInvokeCalls.length, 1); + assert.strictEqual( + mockHandlers.handleFunctionInvokeCalls[0]?.[2], "my-function_123", ); }); @@ -401,10 +430,17 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleInvocationResponseCalls.length).toBe(1); - expect(mockHandlers.handleInvocationResponseCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleInvocationResponseCalls[0]?.[1]).toBe(res); - expect(mockHandlers.handleInvocationResponseCalls[0]?.[2]).toBe( + assert.strictEqual(mockHandlers.handleInvocationResponseCalls.length, 1); + assert.strictEqual( + mockHandlers.handleInvocationResponseCalls[0]?.[0], + req, + ); + assert.strictEqual( + mockHandlers.handleInvocationResponseCalls[0]?.[1], + res, + ); + assert.strictEqual( + mockHandlers.handleInvocationResponseCalls[0]?.[2], "req-123", ); }); @@ -416,8 +452,11 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleInvocationResponseCalls.length).toBe(1); - expect(mockHandlers.handleInvocationResponseCalls[0]?.[2]).toBe(uuid); + assert.strictEqual(mockHandlers.handleInvocationResponseCalls.length, 1); + assert.strictEqual( + mockHandlers.handleInvocationResponseCalls[0]?.[2], + uuid, + ); }); }); @@ -428,10 +467,13 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleInvocationErrorCalls.length).toBe(1); - expect(mockHandlers.handleInvocationErrorCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleInvocationErrorCalls[0]?.[1]).toBe(res); - expect(mockHandlers.handleInvocationErrorCalls[0]?.[2]).toBe("req-456"); + assert.strictEqual(mockHandlers.handleInvocationErrorCalls.length, 1); + assert.strictEqual(mockHandlers.handleInvocationErrorCalls[0]?.[0], req); + assert.strictEqual(mockHandlers.handleInvocationErrorCalls[0]?.[1], res); + assert.strictEqual( + mockHandlers.handleInvocationErrorCalls[0]?.[2], + "req-456", + ); }); }); @@ -442,15 +484,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); it("should return 404 for unknown POST routes", async () => { @@ -459,15 +513,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); it("should return 404 for incorrect method on known routes", async () => { @@ -476,15 +542,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); }); @@ -500,15 +578,29 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 500, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Internal server error" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 500, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 500 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + JSON.stringify({ error: "Internal server error" }), + ]), + ), + "Expected Internal server error", + ); }); it("should handle malformed URLs gracefully", async () => { @@ -518,17 +610,28 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); // Should still set CORS headers - expect(res.setHeaderCalls).toContainEqual([ - "Access-Control-Allow-Origin", - "*", - ]); + assert.ok( + res.setHeaderCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify(["Access-Control-Allow-Origin", "*"]), + ), + "Expected CORS origin header even with malformed URL", + ); // Should return 404 as it doesn't match any route - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); }); it("should handle missing host header", async () => { @@ -539,9 +642,9 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); // Should still work without host header - expect(mockHandlers.handleInvocationNextCalls.length).toBe(1); - expect(mockHandlers.handleInvocationNextCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleInvocationNextCalls[0]?.[1]).toBe(res); + assert.strictEqual(mockHandlers.handleInvocationNextCalls.length, 1); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[0], req); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[1], res); }); }); @@ -552,15 +655,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); it("should handle undefined URL", async () => { @@ -569,15 +684,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); it("should handle undefined method (defaults to GET)", async () => { @@ -586,15 +713,27 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(res.writeHeadCalls).toContainEqual([ - 404, - { - "Content-Type": "application/json", - }, - ]); - expect(res.endCalls).toContainEqual([ - JSON.stringify({ error: "Not found" }), - ]); + assert.ok( + res.writeHeadCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([ + 404, + { + "Content-Type": "application/json", + }, + ]), + ), + "Expected 404 with JSON content type", + ); + assert.ok( + res.endCalls.some( + (call) => + JSON.stringify(call) === + JSON.stringify([JSON.stringify({ error: "Not found" })]), + ), + "Expected Not found error", + ); }); it("should handle URLs with query parameters", async () => { @@ -603,8 +742,11 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleFunctionInvokeCalls.length).toBe(1); - expect(mockHandlers.handleFunctionInvokeCalls[0]?.[2]).toBe("testFunc"); + assert.strictEqual(mockHandlers.handleFunctionInvokeCalls.length, 1); + assert.strictEqual( + mockHandlers.handleFunctionInvokeCalls[0]?.[2], + "testFunc", + ); }); it("should handle URLs with hash fragments", async () => { @@ -613,9 +755,9 @@ describe("handleRequest", () => { await handleRequest(req, res, deps); - expect(mockHandlers.handleInvocationNextCalls.length).toBe(1); - expect(mockHandlers.handleInvocationNextCalls[0]?.[0]).toBe(req); - expect(mockHandlers.handleInvocationNextCalls[0]?.[1]).toBe(res); + assert.strictEqual(mockHandlers.handleInvocationNextCalls.length, 1); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[0], req); + assert.strictEqual(mockHandlers.handleInvocationNextCalls[0]?.[1], res); }); }); });