|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | +import { eventEnvelope, SHORT_UUID_MATCHER, UUID_MATCHER } from '../../expect'; |
| 3 | +import { createRunner } from '../../runner'; |
| 4 | + |
| 5 | +it('Hono app captures parametrized errors (Hono SDK on Bun)', async ({ signal }) => { |
| 6 | + const runner = createRunner(__dirname) |
| 7 | + .expect(envelope => { |
| 8 | + const [, envelopeItems] = envelope; |
| 9 | + const [itemHeader, itemPayload] = envelopeItems[0]; |
| 10 | + |
| 11 | + expect(itemHeader.type).toBe('transaction'); |
| 12 | + |
| 13 | + expect(itemPayload).toMatchObject({ |
| 14 | + type: 'transaction', |
| 15 | + platform: 'node', |
| 16 | + transaction: 'GET /error/:param', |
| 17 | + transaction_info: { |
| 18 | + source: 'route', |
| 19 | + }, |
| 20 | + contexts: { |
| 21 | + trace: { |
| 22 | + span_id: expect.any(String), |
| 23 | + trace_id: expect.any(String), |
| 24 | + op: 'http.server', |
| 25 | + status: 'internal_error', |
| 26 | + origin: 'auto.http.bun.serve', |
| 27 | + }, |
| 28 | + response: { |
| 29 | + status_code: 500, |
| 30 | + }, |
| 31 | + }, |
| 32 | + request: expect.objectContaining({ |
| 33 | + method: 'GET', |
| 34 | + url: expect.stringContaining('/error/param-123'), |
| 35 | + }), |
| 36 | + breadcrumbs: [ |
| 37 | + { |
| 38 | + timestamp: expect.any(Number), |
| 39 | + category: 'console', |
| 40 | + level: 'error', |
| 41 | + message: 'Error: Test error from Hono app', |
| 42 | + data: expect.objectContaining({ |
| 43 | + logger: 'console', |
| 44 | + arguments: [{ message: 'Test error from Hono app', name: 'Error', stack: expect.any(String) }], |
| 45 | + }), |
| 46 | + }, |
| 47 | + ], |
| 48 | + }); |
| 49 | + }) |
| 50 | + |
| 51 | + .expect( |
| 52 | + eventEnvelope( |
| 53 | + { |
| 54 | + level: 'error', |
| 55 | + transaction: 'GET /error/:param', |
| 56 | + exception: { |
| 57 | + values: [ |
| 58 | + { |
| 59 | + type: 'Error', |
| 60 | + value: 'Test error from Hono app', |
| 61 | + stacktrace: { |
| 62 | + frames: expect.any(Array), |
| 63 | + }, |
| 64 | + mechanism: { type: 'auto.http.hono.context_error', handled: false }, |
| 65 | + }, |
| 66 | + ], |
| 67 | + }, |
| 68 | + request: { |
| 69 | + cookies: {}, |
| 70 | + headers: expect.any(Object), |
| 71 | + method: 'GET', |
| 72 | + url: expect.stringContaining('/error/param-123'), |
| 73 | + }, |
| 74 | + breadcrumbs: [ |
| 75 | + { |
| 76 | + timestamp: expect.any(Number), |
| 77 | + category: 'console', |
| 78 | + level: 'error', |
| 79 | + message: 'Error: Test error from Hono app', |
| 80 | + data: expect.objectContaining({ |
| 81 | + logger: 'console', |
| 82 | + arguments: [{ message: 'Test error from Hono app', name: 'Error', stack: expect.any(String) }], |
| 83 | + }), |
| 84 | + }, |
| 85 | + ], |
| 86 | + }, |
| 87 | + { sdk: 'hono', includeSampleRand: true, includeTransaction: true }, |
| 88 | + ), |
| 89 | + ) |
| 90 | + .unordered() |
| 91 | + .start(signal); |
| 92 | + |
| 93 | + await runner.makeRequest('get', '/error/param-123', { expectError: true }); |
| 94 | + await runner.completed(); |
| 95 | +}); |
| 96 | + |
| 97 | +it('Hono app captures parametrized route names on Bun', async ({ signal }) => { |
| 98 | + const runner = createRunner(__dirname) |
| 99 | + .expect(envelope => { |
| 100 | + const [, envelopeItems] = envelope; |
| 101 | + const [itemHeader, itemPayload] = envelopeItems[0]; |
| 102 | + |
| 103 | + expect(itemHeader.type).toBe('transaction'); |
| 104 | + |
| 105 | + expect(itemPayload).toMatchObject({ |
| 106 | + type: 'transaction', |
| 107 | + platform: 'node', |
| 108 | + transaction: 'GET /hello/:name', |
| 109 | + transaction_info: { |
| 110 | + source: 'route', |
| 111 | + }, |
| 112 | + contexts: { |
| 113 | + trace: { |
| 114 | + span_id: SHORT_UUID_MATCHER, |
| 115 | + trace_id: UUID_MATCHER, |
| 116 | + op: 'http.server', |
| 117 | + status: 'ok', |
| 118 | + origin: 'auto.http.bun.serve', |
| 119 | + }, |
| 120 | + }, |
| 121 | + request: expect.objectContaining({ |
| 122 | + method: 'GET', |
| 123 | + url: expect.stringContaining('/hello/world'), |
| 124 | + }), |
| 125 | + }); |
| 126 | + }) |
| 127 | + .start(signal); |
| 128 | + |
| 129 | + await runner.makeRequest('get', '/hello/world'); |
| 130 | + await runner.completed(); |
| 131 | +}); |
0 commit comments