|
| 1 | +import { SDK_VERSION } from '@sentry/core'; |
| 2 | +import { expect, it } from 'vitest'; |
| 3 | +import { SHORT_UUID_MATCHER, UUID_MATCHER } from '../../expect'; |
| 4 | +import { createRunner } from '../../runner'; |
| 5 | + |
| 6 | +it('Hono app captures errors (Hono SDK)', async ({ signal }) => { |
| 7 | + const runner = createRunner(__dirname) |
| 8 | + .expect(envelope => { |
| 9 | + const [, envelopeItems] = envelope; |
| 10 | + const [itemHeader, itemPayload] = envelopeItems[0]; |
| 11 | + |
| 12 | + expect(itemHeader.type).toBe('event'); |
| 13 | + |
| 14 | + // todo: check with function eventEnvelope |
| 15 | + |
| 16 | + // Validate error event structure |
| 17 | + expect(itemPayload).toMatchObject({ |
| 18 | + level: 'error', |
| 19 | + platform: 'javascript', |
| 20 | + transaction: 'GET /error', |
| 21 | + // fixme: should be hono |
| 22 | + sdk: { name: 'sentry.javascript.cloudflare', version: SDK_VERSION }, |
| 23 | + // fixme: should contain trace |
| 24 | + // trace: expect.objectContaining({ trace_id: UUID_MATCHER }), |
| 25 | + exception: { |
| 26 | + values: expect.arrayContaining([ |
| 27 | + expect.objectContaining({ |
| 28 | + type: 'Error', |
| 29 | + value: 'Test error from Hono app', |
| 30 | + mechanism: expect.objectContaining({ |
| 31 | + type: 'generic', // fixme: should be 'auto.faas.hono.error_handler' |
| 32 | + handled: true, // fixme: should be false |
| 33 | + }), |
| 34 | + }), |
| 35 | + ]), |
| 36 | + }, |
| 37 | + request: expect.objectContaining({ |
| 38 | + method: 'GET', |
| 39 | + url: expect.stringContaining('/error'), |
| 40 | + }), |
| 41 | + }); |
| 42 | + }) |
| 43 | + .expect(envelope => { |
| 44 | + const [, envelopeItems] = envelope; |
| 45 | + const [itemHeader, itemPayload] = envelopeItems[0]; |
| 46 | + |
| 47 | + expect(itemHeader.type).toBe('transaction'); |
| 48 | + |
| 49 | + expect(itemPayload).toMatchObject({ |
| 50 | + type: 'transaction', |
| 51 | + platform: 'javascript', |
| 52 | + transaction: 'GET /error', |
| 53 | + contexts: { |
| 54 | + trace: { |
| 55 | + span_id: expect.any(String), |
| 56 | + trace_id: expect.any(String), |
| 57 | + op: 'http.server', |
| 58 | + status: 'internal_error', |
| 59 | + origin: 'auto.http.cloudflare', |
| 60 | + }, |
| 61 | + }, |
| 62 | + request: expect.objectContaining({ |
| 63 | + method: 'GET', |
| 64 | + url: expect.stringContaining('/error'), |
| 65 | + }), |
| 66 | + }); |
| 67 | + }) |
| 68 | + |
| 69 | + .unordered() |
| 70 | + .start(signal); |
| 71 | + |
| 72 | + await runner.makeRequest('get', '/error', { expectError: true }); |
| 73 | + await runner.completed(); |
| 74 | +}); |
| 75 | + |
| 76 | +it('Hono app captures parametrized names', async ({ signal }) => { |
| 77 | + const runner = createRunner(__dirname) |
| 78 | + .expect(envelope => { |
| 79 | + const [, envelopeItems] = envelope; |
| 80 | + const [itemHeader, itemPayload] = envelopeItems[0]; |
| 81 | + |
| 82 | + expect(itemHeader.type).toBe('transaction'); |
| 83 | + |
| 84 | + expect(itemPayload).toMatchObject({ |
| 85 | + type: 'transaction', |
| 86 | + platform: 'javascript', |
| 87 | + transaction: 'GET /hello/:name', |
| 88 | + contexts: { |
| 89 | + trace: { |
| 90 | + span_id: SHORT_UUID_MATCHER, |
| 91 | + trace_id: UUID_MATCHER, |
| 92 | + op: 'http.server', |
| 93 | + status: 'ok', |
| 94 | + origin: 'auto.http.cloudflare', |
| 95 | + }, |
| 96 | + }, |
| 97 | + request: expect.objectContaining({ |
| 98 | + method: 'GET', |
| 99 | + url: expect.stringContaining('/hello/:name'), |
| 100 | + }), |
| 101 | + }); |
| 102 | + }) |
| 103 | + |
| 104 | + .unordered() |
| 105 | + .start(signal); |
| 106 | + |
| 107 | + await runner.makeRequest('get', '/hello/:name', { expectError: false }); |
| 108 | + await runner.completed(); |
| 109 | +}); |
0 commit comments