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