Skip to content

Commit b04a6d4

Browse files
authored
test(replay): Test that blocking elements works as expected (#7201)
1 parent 12e34d4 commit b04a6d4

File tree

16 files changed

+1592
-154
lines changed

16 files changed

+1592
-154
lines changed

packages/integration-tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test-results
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
blockAllMedia: false,
10+
block: ['link[rel="icon"]', 'video', '.nested-hide'],
11+
});
12+
13+
Sentry.init({
14+
dsn: 'https://[email protected]/1337',
15+
sampleRate: 0,
16+
replaysSessionSampleRate: 1.0,
17+
replaysOnErrorSampleRate: 0.0,
18+
19+
integrations: [window.Replay],
20+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" type="image/png" href="file://assets/icon/favicon.png"/>
6+
</head>
7+
<body>
8+
<button aria-label="Click me" onclick="console.log('Test log')">Click me</button>
9+
<div>This should be masked by default</div>
10+
<div data-sentry-unmask>This should be unmasked due to data attribute</div>
11+
<input placeholder="Placeholder should be masked" />
12+
<div title="Title should be masked">Title should be masked</div>
13+
<svg style="width:200px;height:200px" viewBox="0 0 80 80"><path d=""/><area /><rect /></svg>
14+
<svg style="width:200px;height:200px" viewBox="0 0 80 80" data-sentry-unblock><path d=""/><area /><rect /></svg>
15+
<img style="width:100px;height:100px" src="file:///none.png" />
16+
<img data-sentry-unblock style="width:100px;height:100px" src="file:///none.png" />
17+
<video style="width:30px;height:30px"><source src="file://foo.mp4" /></video>
18+
<div class="nested-hide">
19+
<div>This should be hidden.</div>
20+
</div>
21+
</body>
22+
</html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import {
5+
getFullRecordingSnapshots,
6+
normalize,
7+
shouldSkipReplayTest,
8+
waitForReplayRequest,
9+
} from '../../../utils/replayHelpers';
10+
11+
sentryTest('should allow to manually block elements', async ({ getLocalTestPath, page }) => {
12+
if (shouldSkipReplayTest()) {
13+
sentryTest.skip();
14+
}
15+
16+
const reqPromise0 = 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+
const snapshots = getFullRecordingSnapshots(await reqPromise0);
30+
expect(snapshots.length).toEqual(1);
31+
32+
const stringifiedSnapshot = normalize(snapshots[0], { normalizeNumberAttributes: ['rr_width', 'rr_height'] });
33+
34+
expect(stringifiedSnapshot).toMatchSnapshot('privacy.json');
35+
});

0 commit comments

Comments
 (0)