Skip to content

Commit 7dce2da

Browse files
committed
add first test
1 parent 441efad commit 7dce2da

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Replay } from '@sentry/replay';
3+
4+
window.Sentry = Sentry;
5+
window.Replay = new Replay({
6+
flushMinDelay: 200,
7+
flushMaxDelay: 200,
8+
useCompression: false,
9+
});
10+
11+
Sentry.init({
12+
dsn: 'https://[email protected]/1337',
13+
sampleRate: 0,
14+
replaysSessionSampleRate: 1.0,
15+
replaysOnErrorSampleRate: 0.0,
16+
17+
integrations: [window.Replay],
18+
});
Lines changed: 9 additions & 0 deletions
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>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import {
5+
expectedFCPPerformanceSpan,
6+
expectedFPPerformanceSpan,
7+
expectedLCPPerformanceSpan,
8+
expectedMemoryPerformanceSpan,
9+
expectedNavigationPerformanceSpan,
10+
getExpectedReplayEvent,
11+
} from '../../../utils/replayEventTemplates';
12+
import { getCustomRecordingEvents, getReplayEvent, waitForReplayRequest } from '../../../utils/replayHelpers';
13+
14+
sentryTest('replay recording should contain default performance spans', async ({ getLocalTestPath, page }) => {
15+
// Replay bundles are es6 only
16+
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_es5')) {
17+
sentryTest.skip();
18+
}
19+
20+
const reqPromise0 = waitForReplayRequest(page, 0);
21+
const reqPromise1 = waitForReplayRequest(page, 1);
22+
23+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
24+
return route.fulfill({
25+
status: 200,
26+
contentType: 'application/json',
27+
body: JSON.stringify({ id: 'test-id' }),
28+
});
29+
});
30+
31+
const url = await getLocalTestPath({ testDir: __dirname });
32+
33+
await page.goto(url);
34+
const replayEvent0 = getReplayEvent(await reqPromise0);
35+
const { performanceSpans: performanceSpans0 } = getCustomRecordingEvents(await reqPromise0);
36+
37+
expect(replayEvent0).toEqual(getExpectedReplayEvent({ segment_id: 0 }));
38+
expect(performanceSpans0).toEqual([expectedMemoryPerformanceSpan]);
39+
40+
await page.click('button');
41+
42+
const replayEvent1 = getReplayEvent(await reqPromise1);
43+
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(await reqPromise1);
44+
45+
expect(replayEvent1).toEqual(getExpectedReplayEvent({ segment_id: 1, urls: [], replay_start_timestamp: undefined }));
46+
47+
expect(performanceSpans1).toEqual([
48+
expectedNavigationPerformanceSpan,
49+
expectedLCPPerformanceSpan,
50+
expectedFPPerformanceSpan,
51+
expectedFCPPerformanceSpan,
52+
expectedMemoryPerformanceSpan,
53+
]);
54+
});

0 commit comments

Comments
 (0)