Skip to content

Commit 98c7072

Browse files
committed
add test to continue checking replay browser export
1 parent 9ac9033 commit 98c7072

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.Replay = new Sentry.Replay({
5+
flushMinDelay: 200,
6+
initialFlushDelay: 200,
7+
});
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
sampleRate: 0,
12+
replaysSessionSampleRate: 1.0,
13+
replaysOnErrorSampleRate: 0.0,
14+
15+
integrations: [window.Replay],
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button onclick="console.log('Test log')">Click me</button>
8+
</body>
9+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect } from '@playwright/test';
2+
import { SDK_VERSION } from '@sentry/browser';
3+
import type { Event } from '@sentry/types';
4+
5+
import { sentryTest } from '../../../utils/fixtures';
6+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
7+
8+
sentryTest('captureReplay', async ({ getLocalTestPath, page }) => {
9+
// For this test, we skip all bundle tests, as we're only interested in Replay being correctly
10+
// exported from the `@sentry/browser` npm package.
11+
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
12+
sentryTest.skip();
13+
}
14+
15+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
16+
return route.fulfill({
17+
status: 200,
18+
contentType: 'application/json',
19+
body: JSON.stringify({ id: 'test-id' }),
20+
});
21+
});
22+
23+
const url = await getLocalTestPath({ testDir: __dirname });
24+
await page.goto(url);
25+
26+
await page.click('button');
27+
await page.waitForTimeout(300);
28+
29+
const replayEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
30+
31+
expect(replayEvent).toBeDefined();
32+
expect(replayEvent).toEqual({
33+
type: 'replay_event',
34+
timestamp: expect.any(Number),
35+
error_ids: [],
36+
trace_ids: [],
37+
urls: [expect.stringContaining('/dist/index.html')],
38+
replay_id: expect.stringMatching(/\w{32}/),
39+
segment_id: 2,
40+
replay_type: 'session',
41+
event_id: expect.stringMatching(/\w{32}/),
42+
environment: 'production',
43+
sdk: {
44+
integrations: [
45+
'InboundFilters',
46+
'FunctionToString',
47+
'TryCatch',
48+
'Breadcrumbs',
49+
'GlobalHandlers',
50+
'LinkedErrors',
51+
'Dedupe',
52+
'HttpContext',
53+
'Replay',
54+
],
55+
version: SDK_VERSION,
56+
name: 'sentry.javascript.browser',
57+
},
58+
sdkProcessingMetadata: {},
59+
request: {
60+
url: expect.stringContaining('/dist/index.html'),
61+
headers: {
62+
'User-Agent': expect.stringContaining(''),
63+
},
64+
},
65+
platform: 'javascript',
66+
tags: { sessionSampleRate: 1, errorSampleRate: 0 },
67+
});
68+
});

0 commit comments

Comments
 (0)