Skip to content

Commit ebf8ba6

Browse files
committed
add test
1 parent 0b9a8b2 commit ebf8ba6

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.Replay = new Sentry.Replay({
5+
flushMinDelay: 200,
6+
flushMaxDelay: 200,
7+
minReplayDuration: 0,
8+
});
9+
10+
Sentry.init({
11+
dsn: 'https://[email protected]/1337',
12+
sampleRate: 1,
13+
replaysSessionSampleRate: 0.0,
14+
replaysOnErrorSampleRate: 1.0,
15+
16+
integrations: [window.Replay],
17+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button onclick="console.log('Test log 1')" id="button1">Click me</button>
8+
<button onclick="window.doesNotExist()" id="buttonError">Click me</button>
9+
</body>
10+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import {
5+
getReplaySnapshot,
6+
shouldSkipReplayTest,
7+
waitForReplayRequest,
8+
waitForReplayRunning,
9+
} from '../../../utils/replayHelpers';
10+
11+
sentryTest('continues buffer session in session mode after error & reload', async ({ getLocalTestPath, page }) => {
12+
if (shouldSkipReplayTest()) {
13+
sentryTest.skip();
14+
}
15+
16+
const reqPromise1 = waitForReplayRequest(page, 0);
17+
18+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
19+
return route.fulfill({
20+
status: 200,
21+
contentType: 'application/json',
22+
body: JSON.stringify({ id: 'test-id' }),
23+
});
24+
});
25+
26+
const url = await getLocalTestPath({ testDir: __dirname });
27+
28+
await page.goto(url);
29+
30+
// buffer session captures an error & switches to session mode
31+
await page.click('#buttonError');
32+
await new Promise(resolve => setTimeout(resolve, 300));
33+
await reqPromise1;
34+
35+
await waitForReplayRunning(page);
36+
const replay1 = await getReplaySnapshot(page);
37+
38+
expect(replay1.recordingMode).toEqual('session');
39+
expect(replay1.session?.sampled).toEqual('buffer');
40+
41+
// Reload to ensure the session is correctly recovered from sessionStorage
42+
await page.reload();
43+
44+
await waitForReplayRunning(page);
45+
const replay2 = await getReplaySnapshot(page);
46+
47+
expect(replay2.recordingMode).toEqual('session');
48+
expect(replay2.session?.sampled).toEqual('buffer');
49+
});

0 commit comments

Comments
 (0)