-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(hono): Add E2E test for Hono on Cloudflare, Node and Bun #20406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
485877e
add minimal hono starter
s1gr1d 4450bb6
test(hono): Add E2E test for Hono on Cloudflare
s1gr1d 3cd89a4
Merge branch 'develop' into sig/hono-e2e-cf
s1gr1d 02d982e
add test variants (cf, node, bun)
s1gr1d 5e1629e
Merge branch 'develop' into sig/hono-e2e-cf
s1gr1d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
dev-packages/e2e-tests/test-applications/hono-4/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # prod | ||
| dist/ | ||
|
|
||
| # dev | ||
| .yarn/ | ||
| !.yarn/releases | ||
| .vscode/* | ||
| !.vscode/launch.json | ||
| !.vscode/*.code-snippets | ||
| .idea/workspace.xml | ||
| .idea/usage.statistics.xml | ||
| .idea/shelf | ||
|
|
||
| # deps | ||
| node_modules/ | ||
| .wrangler | ||
|
|
||
| # env | ||
| .env | ||
| .env.production | ||
| .dev.vars | ||
|
|
||
| # logs | ||
| logs/ | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
|
|
||
| # test | ||
| test-results | ||
|
|
||
| # misc | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @sentry:registry=http://127.0.0.1:4873 | ||
| @sentry-internal:registry=http://127.0.0.1:4873 |
43 changes: 43 additions & 0 deletions
43
dev-packages/e2e-tests/test-applications/hono-4/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| "name": "hono-4", | ||
| "type": "module", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev:cf": "wrangler dev --var \"E2E_TEST_DSN:$E2E_TEST_DSN\" --log-level=$(test $CI && echo 'none' || echo 'log')", | ||
| "dev:node": "node --import tsx/esm --import @sentry/node/preload src/entry.node.ts", | ||
| "dev:bun": "bun src/entry.bun.ts", | ||
| "build": "wrangler deploy --dry-run", | ||
| "test:build": "pnpm install && pnpm build", | ||
| "test:assert": "TEST_ENV=production playwright test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/hono": "latest || *", | ||
| "@sentry/node": "latest || *", | ||
| "@hono/node-server": "^1.19.10", | ||
| "hono": "^4.12.14" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "~1.56.0", | ||
| "@cloudflare/workers-types": "^4.20240725.0", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils", | ||
| "tsx": "^4.20.3", | ||
| "typescript": "^5.5.2", | ||
| "wrangler": "^4.61.0" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| }, | ||
| "sentryTest": { | ||
| "variants": [ | ||
| { | ||
| "assert-command": "RUNTIME=node pnpm test:assert", | ||
| "label": "hono-4 (node)" | ||
| }, | ||
| { | ||
| "assert-command": "RUNTIME=bun pnpm test:assert", | ||
| "label": "hono-4 (bun)" | ||
| } | ||
| ] | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
dev-packages/e2e-tests/test-applications/hono-4/playwright.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| type Runtime = 'cloudflare' | 'node' | 'bun'; | ||
|
|
||
| const RUNTIME = (process.env.RUNTIME || 'cloudflare') as Runtime; | ||
|
|
||
| const testEnv = process.env.TEST_ENV; | ||
|
|
||
| if (!testEnv) { | ||
| throw new Error('No test env defined'); | ||
| } | ||
|
|
||
| const APP_PORT = 38787; | ||
|
|
||
| const startCommands: Record<Runtime, string> = { | ||
| cloudflare: `pnpm dev:cf --port ${APP_PORT}`, | ||
| node: `pnpm dev:node`, | ||
| bun: `pnpm dev:bun`, | ||
| }; | ||
|
|
||
| const config = getPlaywrightConfig( | ||
| { | ||
| startCommand: startCommands[RUNTIME], | ||
| port: APP_PORT, | ||
| }, | ||
| { | ||
| workers: '100%', | ||
| retries: 0, | ||
| }, | ||
| ); | ||
|
|
||
| export default config; |
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/hono-4/src/entry.bun.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Hono } from 'hono'; | ||
| import { sentry } from '@sentry/hono/bun'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono<{ Bindings: { E2E_TEST_DSN: string } }>(); | ||
|
|
||
| app.use( | ||
| // @ts-expect-error - Env is not yet in type | ||
| sentry(app, { | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }), | ||
| ); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| const port = Number(process.env.PORT || 38787); | ||
|
|
||
| export default { | ||
| port, | ||
| fetch: app.fetch, | ||
| }; |
18 changes: 18 additions & 0 deletions
18
dev-packages/e2e-tests/test-applications/hono-4/src/entry.cloudflare.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Hono } from 'hono'; | ||
| import { sentry } from '@sentry/hono/cloudflare'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono<{ Bindings: { E2E_TEST_DSN: string } }>(); | ||
|
|
||
| app.use( | ||
| sentry(app, env => ({ | ||
| dsn: env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| })), | ||
| ); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| export default app; |
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/hono-4/src/entry.node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Hono } from 'hono'; | ||
| import { sentry } from '@sentry/hono/node'; | ||
| import { serve } from '@hono/node-server'; | ||
| import { addRoutes } from './routes'; | ||
|
|
||
| const app = new Hono<{ Bindings: { E2E_TEST_DSN: string } }>(); | ||
|
|
||
| app.use( | ||
| // @ts-expect-error - Env is not yet in type | ||
| sentry(app, { | ||
| dsn: process.env.E2E_TEST_DSN, | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }), | ||
| ); | ||
|
|
||
| addRoutes(app); | ||
|
|
||
| const port = Number(process.env.PORT || 38787); | ||
|
|
||
| serve({ fetch: app.fetch, port }, () => { | ||
| console.log(`Hono (Node) listening on port ${port}`); | ||
| }); |
24 changes: 24 additions & 0 deletions
24
dev-packages/e2e-tests/test-applications/hono-4/src/routes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { Hono } from 'hono'; | ||
| import { HTTPException } from 'hono/http-exception'; | ||
|
|
||
| export function addRoutes(app: Hono<{ Bindings: { E2E_TEST_DSN: string } }>): void { | ||
| app.get('/', c => { | ||
| return c.text('Hello Hono!'); | ||
| }); | ||
|
|
||
| app.get('/test-param/:paramId', c => { | ||
| return c.json({ paramId: c.req.param('paramId') }); | ||
| }); | ||
|
|
||
| app.get('/error/:cause', c => { | ||
| throw new Error('This is a test error for Sentry!', { | ||
| cause: c.req.param('cause'), | ||
| }); | ||
| }); | ||
|
|
||
| app.get('/http-exception/:code', c => { | ||
| // oxlint-disable-next-line typescript/no-explicit-any | ||
| const code = Number(c.req.param('code')) as any; | ||
| throw new HTTPException(code, { message: `HTTPException ${code}` }); | ||
| }); | ||
| } |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/hono-4/start-event-proxy.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
|
||
| startEventProxyServer({ | ||
| port: 3031, | ||
| proxyServerName: 'hono-4', | ||
| }); |
54 changes: 54 additions & 0 deletions
54
dev-packages/e2e-tests/test-applications/hono-4/tests/errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| const APP_NAME = 'hono-4'; | ||
|
|
||
| test('captures error thrown in route handler', async ({ baseURL }) => { | ||
| const errorWaiter = waitForError(APP_NAME, event => { | ||
| return event.exception?.values?.[0]?.value === 'This is a test error for Sentry!'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/error/test-cause`); | ||
| expect(response.status).toBe(500); | ||
|
|
||
| const event = await errorWaiter; | ||
| expect(event.exception?.values?.[0]?.value).toBe('This is a test error for Sentry!'); | ||
| }); | ||
|
|
||
| test('captures HTTPException with 502 status', async ({ baseURL }) => { | ||
| const errorWaiter = waitForError(APP_NAME, event => { | ||
| return event.exception?.values?.[0]?.value === 'HTTPException 502'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/http-exception/502`); | ||
| expect(response.status).toBe(502); | ||
|
|
||
| const event = await errorWaiter; | ||
| expect(event.exception?.values?.[0]?.value).toBe('HTTPException 502'); | ||
| }); | ||
|
|
||
| // TODO: 401 and 404 HTTPExceptions should not be captured by Sentry by default, | ||
| // but currently they are. Fix the filtering and update these tests accordingly. | ||
| test('captures HTTPException with 401 status', async ({ baseURL }) => { | ||
| const errorWaiter = waitForError(APP_NAME, event => { | ||
| return event.exception?.values?.[0]?.value === 'HTTPException 401'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/http-exception/401`); | ||
| expect(response.status).toBe(401); | ||
|
|
||
| const event = await errorWaiter; | ||
| expect(event.exception?.values?.[0]?.value).toBe('HTTPException 401'); | ||
| }); | ||
|
|
||
| test('captures HTTPException with 404 status', async ({ baseURL }) => { | ||
| const errorWaiter = waitForError(APP_NAME, event => { | ||
| return event.exception?.values?.[0]?.value === 'HTTPException 404'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/http-exception/404`); | ||
| expect(response.status).toBe(404); | ||
|
|
||
| const event = await errorWaiter; | ||
| expect(event.exception?.values?.[0]?.value).toBe('HTTPException 404'); | ||
| }); | ||
41 changes: 41 additions & 0 deletions
41
dev-packages/e2e-tests/test-applications/hono-4/tests/tracing.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| const APP_NAME = 'hono-4'; | ||
|
|
||
| test('sends a transaction for the index route', async ({ baseURL }) => { | ||
| const transactionWaiter = waitForTransaction(APP_NAME, event => { | ||
| return event.transaction === 'GET /'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/`); | ||
| expect(response.status).toBe(200); | ||
|
|
||
| const transaction = await transactionWaiter; | ||
| expect(transaction.contexts?.trace?.op).toBe('http.server'); | ||
| }); | ||
|
|
||
| test('sends a transaction for a parameterized route', async ({ baseURL }) => { | ||
| const transactionWaiter = waitForTransaction(APP_NAME, event => { | ||
| return event.transaction === 'GET /test-param/:paramId'; | ||
| }); | ||
|
|
||
| const response = await fetch(`${baseURL}/test-param/123`); | ||
| expect(response.status).toBe(200); | ||
|
|
||
| const transaction = await transactionWaiter; | ||
| expect(transaction.contexts?.trace?.op).toBe('http.server'); | ||
| expect(transaction.transaction).toBe('GET /test-param/:paramId'); | ||
| }); | ||
|
|
||
| test('sends a transaction for a route that throws', async ({ baseURL }) => { | ||
| const transactionWaiter = waitForTransaction(APP_NAME, event => { | ||
| return event.transaction === 'GET /error/:cause'; | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/error/test-cause`); | ||
|
|
||
| const transaction = await transactionWaiter; | ||
| expect(transaction.contexts?.trace?.op).toBe('http.server'); | ||
| expect(transaction.contexts?.trace?.status).toBe('internal_error'); | ||
| }); |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/hono-4/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler", | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "lib": ["ESNext"], | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "hono/jsx", | ||
| "types": ["@cloudflare/workers-types"] | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/hono-4/wrangler.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "name": "hono-4", | ||
| "main": "src/entry.cloudflare.ts", | ||
| "compatibility_date": "2026-04-20", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Is this some todo for this PR or another one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another one