diff --git a/packages/hono/jest.config.js b/packages/hono/jest.config.js new file mode 100644 index 00000000..3657af42 --- /dev/null +++ b/packages/hono/jest.config.js @@ -0,0 +1,23 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + transform: { + "^.+\\.tsx?$": [ + "ts-jest", + { + diagnostics: false, + isolatedModules: true, + }, + ], + }, + testEnvironment: "node", + modulePathIgnorePatterns: ["/node_modules/", "/dist/"], + testPathIgnorePatterns: ["/node_modules/", "/dist/"], + testMatch: ["**/__tests__/**/*.test.[jt]s?(x)"], + setupFilesAfterEnv: [], + watchPathIgnorePatterns: ["/node_modules/"], + watchPlugins: [ + "jest-watch-typeahead/filename", + "jest-watch-typeahead/testname", + ], + verbose: false, +}; diff --git a/packages/hono/package.json b/packages/hono/package.json index 4ecf33b8..e19acda5 100644 --- a/packages/hono/package.json +++ b/packages/hono/package.json @@ -22,13 +22,16 @@ "main": "dist/honoPlugin.js", "types": "dist/honoPlugin.d.ts", "scripts": { - "clean": "rimraf dist *.tsbuildinfo" + "clean": "rimraf dist *.tsbuildinfo", + "test": "jest" }, "devDependencies": { + "@types/jest": "^29.5.10", "@types/node": "^20.10.3", "@types/qs": "^6.9.10", - "typescript": "^5.3.2", - "vitest": "^1.3.1" + "jest": "^29.7.0", + "ts-jest": "^29.1.1", + "typescript": "^5.3.2" }, "dependencies": { "hono": "^4.0.0", diff --git a/packages/hono/src/honoPlugin.test.ts b/packages/hono/src/__tests__/honoPlugin.test.ts similarity index 94% rename from packages/hono/src/honoPlugin.test.ts rename to packages/hono/src/__tests__/honoPlugin.test.ts index a37388af..657c737b 100644 --- a/packages/hono/src/honoPlugin.test.ts +++ b/packages/hono/src/__tests__/honoPlugin.test.ts @@ -1,7 +1,6 @@ import { Hono } from "hono"; import { Stl, UnauthorizedError, z } from "stainless"; -import { describe, expect, test } from "vitest"; -import { stlApi } from "./honoPlugin"; +import { stlApi } from "../honoPlugin"; const stl = new Stl({ plugins: {} }); @@ -63,9 +62,7 @@ describe("basic routing", () => { test("list posts", async () => { const response = await app.request("/api/posts"); expect(response).toHaveProperty("status", 200); - expect(await response.json()).toMatchInlineSnapshot(` - [] - `); + expect(await response.json()).toMatchInlineSnapshot("[]"); }); test("retrieve posts", async () => { @@ -85,11 +82,19 @@ describe("basic routing", () => { expect(response).toHaveProperty("status", 405); expect(await response.json()).toMatchInlineSnapshot(` { - "message": "No handler for PUT; only GET, POST.", + "message": "No handler for PUT; only GET, HEAD, POST.", } `); }); + test("head posts", async () => { + const response = await app.request("/api/posts/5", { + method: "HEAD", + }); + expect(response).toHaveProperty("status", 200); + expect(await response.text()).toBe(""); + }); + test("update posts", async () => { const response = await app.request("/api/posts/5", { method: "POST", @@ -159,7 +164,7 @@ describe("basic routing", () => { "received": "undefined", }, ], - "message": "Validation error: Required at ".content"", + "message": "Required at ".content"", } `); }); diff --git a/packages/hono/src/routeMatcher.ts b/packages/hono/src/routeMatcher.ts index 701ff87b..ab9cb089 100644 --- a/packages/hono/src/routeMatcher.ts +++ b/packages/hono/src/routeMatcher.ts @@ -34,6 +34,11 @@ export function makeRouteMatcher(endpoints: AnyEndpoint[]) { for (const endpoint of endpoints) { const [method, path] = endpointToHono(endpoint.endpoint); routeMatcher.add(method, path, endpoint); + if (method === "GET") { + // Hono route matching is method-specific, so also add a + // HEAD route for GET endpoints + routeMatcher.add("HEAD", path, endpoint); + } } return routeMatcher; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bdaef614..99170bbe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -393,18 +393,24 @@ importers: specifier: workspace:* version: link:../stainless devDependencies: + '@types/jest': + specifier: ^29.5.10 + version: 29.5.10 '@types/node': specifier: ^20.10.3 version: 20.16.5 '@types/qs': specifier: ^6.9.10 version: 6.9.15 + jest: + specifier: ^29.7.0 + version: 29.7.0(@types/node@20.16.5) + ts-jest: + specifier: ^29.1.1 + version: 29.1.1(@babel/core@7.25.2)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.25.2))(jest@29.7.0(@types/node@20.16.5))(typescript@5.3.2) typescript: specifier: ^5.3.2 version: 5.3.2 - vitest: - specifier: ^1.3.1 - version: 1.6.0(@types/node@20.16.5)(jsdom@20.0.3)(terser@5.32.0) packages/next: dependencies: