|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { Event } from '@sentry/types'; |
| 3 | + |
| 4 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 5 | +import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; |
| 6 | + |
| 7 | +sentryTest('captures Breadcrumb with log level for 4xx response code', async ({ getLocalTestUrl, page }) => { |
| 8 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 9 | + |
| 10 | + await page.route('**/foo', async route => { |
| 11 | + await route.fulfill({ |
| 12 | + status: 404, |
| 13 | + contentType: 'text/plain', |
| 14 | + body: 'Not Found!', |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); |
| 19 | + |
| 20 | + expect(eventData.exception?.values).toHaveLength(1); |
| 21 | + |
| 22 | + expect(eventData?.breadcrumbs?.length).toBe(1); |
| 23 | + expect(eventData!.breadcrumbs![0]).toEqual({ |
| 24 | + timestamp: expect.any(Number), |
| 25 | + category: 'fetch', |
| 26 | + type: 'http', |
| 27 | + data: { |
| 28 | + method: 'GET', |
| 29 | + status_code: 404, |
| 30 | + url: 'http://sentry-test.io/foo', |
| 31 | + }, |
| 32 | + level: 'warning', |
| 33 | + }); |
| 34 | + |
| 35 | + await page.route('**/foo', async route => { |
| 36 | + await route.fulfill({ |
| 37 | + status: 500, |
| 38 | + contentType: 'text/plain', |
| 39 | + body: 'Internal Server Error', |
| 40 | + }); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +sentryTest('captures Breadcrumb with log level for 5xx response code', async ({ getLocalTestUrl, page }) => { |
| 45 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 46 | + |
| 47 | + await page.route('**/foo', async route => { |
| 48 | + await route.fulfill({ |
| 49 | + status: 500, |
| 50 | + contentType: 'text/plain', |
| 51 | + body: 'Internal Server Error', |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); |
| 56 | + |
| 57 | + expect(eventData.exception?.values).toHaveLength(1); |
| 58 | + |
| 59 | + expect(eventData?.breadcrumbs?.length).toBe(1); |
| 60 | + expect(eventData!.breadcrumbs![0]).toEqual({ |
| 61 | + timestamp: expect.any(Number), |
| 62 | + category: 'fetch', |
| 63 | + type: 'http', |
| 64 | + data: { |
| 65 | + method: 'GET', |
| 66 | + status_code: 500, |
| 67 | + url: 'http://sentry-test.io/foo', |
| 68 | + }, |
| 69 | + level: 'error', |
| 70 | + }); |
| 71 | +}); |
0 commit comments