|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 4 | +import { envelopeRequestParser, waitForErrorRequest } from '../../../../../utils/helpers'; |
| 5 | +import { shouldSkipReplayTest } from '../../../../../utils/replayHelpers'; |
| 6 | + |
| 7 | +sentryTest('parses response_body_size from Content-Length header if available', async ({ getLocalTestPath, page }) => { |
| 8 | + if (shouldSkipReplayTest()) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + await page.route('**/foo', route => { |
| 13 | + return route.fulfill({ |
| 14 | + status: 200, |
| 15 | + body: JSON.stringify({ |
| 16 | + userNames: ['John', 'Jane'], |
| 17 | + }), |
| 18 | + headers: { |
| 19 | + 'Content-Type': 'application/json', |
| 20 | + 'Content-Length': '789', |
| 21 | + }, |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + const requestPromise = waitForErrorRequest(page); |
| 26 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 27 | + await page.goto(url); |
| 28 | + |
| 29 | + await page.evaluate(() => { |
| 30 | + /* eslint-disable */ |
| 31 | + fetch('http://localhost:7654/foo', { |
| 32 | + headers: { |
| 33 | + Accept: 'application/json', |
| 34 | + 'Content-Type': 'application/json', |
| 35 | + Cache: 'no-cache', |
| 36 | + }, |
| 37 | + }).then(() => { |
| 38 | + // @ts-ignore Sentry is a global |
| 39 | + Sentry.captureException('test error'); |
| 40 | + }); |
| 41 | + /* eslint-enable */ |
| 42 | + }); |
| 43 | + |
| 44 | + const request = await requestPromise; |
| 45 | + const eventData = envelopeRequestParser(request); |
| 46 | + |
| 47 | + expect(eventData.exception?.values).toHaveLength(1); |
| 48 | + |
| 49 | + expect(eventData?.breadcrumbs?.length).toBe(1); |
| 50 | + expect(eventData!.breadcrumbs![0]).toEqual({ |
| 51 | + timestamp: expect.any(Number), |
| 52 | + category: 'fetch', |
| 53 | + type: 'http', |
| 54 | + data: { |
| 55 | + method: 'GET', |
| 56 | + response_body_size: 789, |
| 57 | + status_code: 200, |
| 58 | + url: 'http://localhost:7654/foo', |
| 59 | + }, |
| 60 | + }); |
| 61 | +}); |
0 commit comments