|
| 1 | +import { expect, Page } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { getSentryTransactionRequest } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest.beforeEach(({ browserName }) => { |
| 7 | + if (browserName !== 'chromium') { |
| 8 | + sentryTest.skip(); |
| 9 | + } |
| 10 | +}); |
| 11 | + |
| 12 | +async function createSessionWithLatency(page: Page, latency: number) { |
| 13 | + const session = await page.context().newCDPSession(page); |
| 14 | + await session.send('Network.emulateNetworkConditions', { |
| 15 | + offline: false, |
| 16 | + latency: latency, |
| 17 | + downloadThroughput: (25 * 1024) / 8, |
| 18 | + uploadThroughput: (5 * 1024) / 8, |
| 19 | + }); |
| 20 | + |
| 21 | + return session; |
| 22 | +} |
| 23 | + |
| 24 | +sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => { |
| 25 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 26 | + const eventData = await getSentryTransactionRequest(page, url); |
| 27 | + |
| 28 | + expect(eventData.measurements).toBeDefined(); |
| 29 | + expect(eventData.measurements?.['connection.rtt']?.value).toBe(0); |
| 30 | +}); |
| 31 | + |
| 32 | +sentryTest( |
| 33 | + 'should capture a `connection.rtt` metric with emulated value 200ms on Chromium.', |
| 34 | + async ({ getLocalTestPath, page }) => { |
| 35 | + const session = await createSessionWithLatency(page, 200); |
| 36 | + |
| 37 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 38 | + const eventData = await getSentryTransactionRequest(page, url); |
| 39 | + |
| 40 | + await session.detach(); |
| 41 | + |
| 42 | + expect(eventData.measurements).toBeDefined(); |
| 43 | + expect(eventData.measurements?.['connection.rtt']?.value).toBe(200); |
| 44 | + }, |
| 45 | +); |
| 46 | + |
| 47 | +sentryTest( |
| 48 | + 'should capture a `connection.rtt` metric with emulated value 100ms on Chromium.', |
| 49 | + async ({ getLocalTestPath, page }) => { |
| 50 | + const session = await createSessionWithLatency(page, 100); |
| 51 | + |
| 52 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 53 | + const eventData = await getSentryTransactionRequest(page, url); |
| 54 | + |
| 55 | + await session.detach(); |
| 56 | + |
| 57 | + expect(eventData.measurements).toBeDefined(); |
| 58 | + expect(eventData.measurements?.['connection.rtt']?.value).toBe(100); |
| 59 | + }, |
| 60 | +); |
| 61 | + |
| 62 | +sentryTest( |
| 63 | + 'should capture a `connection.rtt` metric with emulated value 50ms on Chromium.', |
| 64 | + async ({ getLocalTestPath, page }) => { |
| 65 | + const session = await createSessionWithLatency(page, 50); |
| 66 | + |
| 67 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 68 | + const eventData = await getSentryTransactionRequest(page, url); |
| 69 | + |
| 70 | + await session.detach(); |
| 71 | + |
| 72 | + expect(eventData.measurements).toBeDefined(); |
| 73 | + expect(eventData.measurements?.['connection.rtt']?.value).toBe(50); |
| 74 | + }, |
| 75 | +); |
0 commit comments