|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { sentryTest } from '../../../utils/fixtures'; |
| 3 | +import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../utils/helpers'; |
| 4 | + |
| 5 | +sentryTest('makes a call to sentry.io to diagnose SDK connectivity', async ({ getLocalTestUrl, page }) => { |
| 6 | + const bundle = process.env.PW_BUNDLE as string | undefined; |
| 7 | + if (shouldSkipTracingTest() || !!bundle) { |
| 8 | + // the CDN bundle doesn't export diagnoseSdkConnectivity. So skipping the test for bundles. |
| 9 | + sentryTest.skip(); |
| 10 | + } |
| 11 | + |
| 12 | + const pageloadRequestPromise = waitForTransactionRequest(page, e => e.contexts?.trace?.op === 'pageload'); |
| 13 | + |
| 14 | + // mock sdk connectivity url to avoid making actual request to sentry.io |
| 15 | + page.route('**/api/4509632503087104/envelope/**/*', route => { |
| 16 | + return route.fulfill({ |
| 17 | + status: 200, |
| 18 | + body: '{}', |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + const diagnoseMessagePromise = new Promise<string>(resolve => { |
| 23 | + page.on('console', msg => { |
| 24 | + if (msg.text().includes('SDK connectivity:')) { |
| 25 | + resolve(msg.text()); |
| 26 | + } |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 31 | + await page.goto(url); |
| 32 | + |
| 33 | + const pageLoadEvent = envelopeRequestParser(await pageloadRequestPromise); |
| 34 | + |
| 35 | + // undefined is expected and means the request was successful |
| 36 | + expect(await diagnoseMessagePromise).toEqual('SDK connectivity: undefined'); |
| 37 | + |
| 38 | + // the request to sentry.io should not be traced, hence no http.client span should be sent. |
| 39 | + const httpClientSpans = pageLoadEvent.spans?.filter(s => s.op === 'http.client'); |
| 40 | + expect(httpClientSpans).toHaveLength(0); |
| 41 | + |
| 42 | + // no fetch breadcrumb should be sent (only breadcrumb for the console log) |
| 43 | + expect(pageLoadEvent.breadcrumbs).toEqual([ |
| 44 | + expect.objectContaining({ |
| 45 | + category: 'console', |
| 46 | + message: 'SDK connectivity: undefined', |
| 47 | + }), |
| 48 | + ]); |
| 49 | +}); |
0 commit comments