Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/commands/snapshot/snapshot-fallback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Hono } from 'hono'
import { describe, it, expect, vi } from 'vitest'
import { snapshotLines } from './snapshot.js'

// Hono v5 lists notFound and onError handlers like this
vi.mock('hono/dev', () => ({
inspectRoutes: () => [
{ path: '/health', method: 'GET', name: '[handler]', isMiddleware: false },
{ path: '/*', method: '@NOT_FOUND', name: '[handler]', isMiddleware: false },
{ path: '/*', method: '@ERROR', name: '[handler]', isMiddleware: false },
],
}))

describe('snapshotLines on Hono v5', () => {
it('skips the notFound and onError handlers', async () => {
const app = new Hono()
app.get('/health', (c) => c.text('ok'))
const lines = (await snapshotLines(app)).map((l) => JSON.parse(l))
expect(lines).toEqual([
{ path: '/health', expect: { status: 200, body: 'ok' } },
{ path: '/__no_such_path__', expect: { status: 404, body: '404 Not Found' } },
])
})
})
6 changes: 5 additions & 1 deletion src/commands/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const snapshotLines = async (
target: RequestTarget = app
): Promise<string[]> => {
const lines: string[] = []
const routes = inspectRoutes(app).filter((route) => !route.isMiddleware)
// Hono v5 lists notFound and onError handlers with a method like
// "@NOT_FOUND". They are not routes to request.
const routes = inspectRoutes(app).filter(
(route) => !route.isMiddleware && !route.method.startsWith('@')
)

for (const route of routes) {
const isParamless = !route.path.includes(':') && !route.path.includes('*')
Expand Down
Loading