|
| 1 | +import { expect, Request } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { getSentryTransactionRequest } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest('should create spans for multiple fetch requests', async ({ getLocalTestPath, page }) => { |
| 7 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 8 | + |
| 9 | + const eventData = await getSentryTransactionRequest(page, url); |
| 10 | + const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client'); |
| 11 | + |
| 12 | + expect(requestSpans).toHaveLength(3); |
| 13 | + |
| 14 | + requestSpans?.forEach((span, index) => |
| 15 | + expect(span).toMatchObject({ |
| 16 | + description: `GET http://example.com/${index}`, |
| 17 | + parent_span_id: eventData.contexts?.trace.span_id, |
| 18 | + span_id: expect.any(String), |
| 19 | + start_timestamp: expect.any(Number), |
| 20 | + timestamp: expect.any(Number), |
| 21 | + trace_id: eventData.contexts?.trace.trace_id, |
| 22 | + }), |
| 23 | + ); |
| 24 | +}); |
| 25 | + |
| 26 | +sentryTest('should attach `sentry-trace` header to multiple fetch requests', async ({ getLocalTestPath, page }) => { |
| 27 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 28 | + |
| 29 | + page.goto(url); |
| 30 | + const requests = await Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))); |
| 31 | + |
| 32 | + expect(requests).toHaveLength(3); |
| 33 | + |
| 34 | + requests?.forEach(async (request: Request) => { |
| 35 | + const requestHeaders = await request.allHeaders(); |
| 36 | + expect(requestHeaders).toMatchObject({ |
| 37 | + 'sentry-trace': expect.any(String), |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
0 commit comments