|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { sentryTest } from '../../../../../utils/fixtures'; |
| 3 | +import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../../utils/helpers'; |
| 4 | + |
| 5 | +sentryTest( |
| 6 | + 'should create a navigation.redirect span if a click happened more than 300ms before navigation', |
| 7 | + async ({ getLocalTestUrl, page }) => { |
| 8 | + if (shouldSkipTracingTest()) { |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 13 | + |
| 14 | + const pageloadRequestPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === 'pageload'); |
| 15 | + const navigationRequestPromise = waitForTransactionRequest( |
| 16 | + page, |
| 17 | + event => event.contexts?.trace?.op === 'navigation', |
| 18 | + ); |
| 19 | + |
| 20 | + await page.goto(url); |
| 21 | + |
| 22 | + await pageloadRequestPromise; |
| 23 | + |
| 24 | + // Now trigger navigation, and then a redirect in the navigation, with |
| 25 | + await page.click('#btn1'); |
| 26 | + |
| 27 | + const navigationRequest = envelopeRequestParser(await navigationRequestPromise); |
| 28 | + |
| 29 | + expect(navigationRequest.contexts?.trace?.op).toBe('navigation'); |
| 30 | + expect(navigationRequest.transaction).toEqual('/sub-page'); |
| 31 | + |
| 32 | + const spans = navigationRequest.spans || []; |
| 33 | + |
| 34 | + expect(spans).toContainEqual( |
| 35 | + expect.objectContaining({ |
| 36 | + op: 'navigation.redirect', |
| 37 | + description: '/sub-page-redirect', |
| 38 | + }), |
| 39 | + ); |
| 40 | + }, |
| 41 | +); |
0 commit comments