Skip to content

Commit da6b84f

Browse files
committed
add integration test
1 parent eea5df4 commit da6b84f

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed
Lines changed: 16 additions & 0 deletions
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: 1000,
6+
flushMaxDelay: 1000,
7+
});
8+
9+
Sentry.init({
10+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
11+
sampleRate: 0,
12+
replaysSessionSampleRate: 1.0,
13+
replaysOnErrorSampleRate: 0.0,
14+
15+
integrations: [window.Replay],
16+
});
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+
<input id="input" />
8+
</body>
9+
</html>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { expect } from '@playwright/test';
2+
import { IncrementalSource } from '@sentry-internal/rrweb';
3+
import type { inputData } from '@sentry-internal/rrweb/typings/types';
4+
5+
import { sentryTest } from '../../../utils/fixtures';
6+
import { IncrementalRecordingSnapshot, getCustomRecordingEvents } from '../../../utils/replayHelpers';
7+
import {
8+
getIncrementalRecordingSnapshots,
9+
shouldSkipReplayTest,
10+
waitForReplayRequest,
11+
} from '../../../utils/replayHelpers';
12+
13+
function isInputMutation(
14+
snap: IncrementalRecordingSnapshot,
15+
): snap is IncrementalRecordingSnapshot & { data: inputData } {
16+
return snap.data.source == IncrementalSource.Input;
17+
}
18+
19+
sentryTest('captures keyboard events', async ({ forceFlushReplay, getLocalTestPath, page }) => {
20+
if (shouldSkipReplayTest()) {
21+
sentryTest.skip();
22+
}
23+
24+
const reqPromise0 = waitForReplayRequest(page, 0);
25+
26+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
27+
return route.fulfill({
28+
status: 200,
29+
contentType: 'application/json',
30+
body: JSON.stringify({ id: 'test-id' }),
31+
});
32+
});
33+
34+
const url = await getLocalTestPath({ testDir: __dirname });
35+
36+
await page.goto(url);
37+
await reqPromise0;
38+
await forceFlushReplay();
39+
40+
const reqPromise1 = waitForReplayRequest(page, (event, res) => {
41+
return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.keyDown');
42+
});
43+
44+
// Trigger keyboard unfocused
45+
await page.keyboard.press('Control+A');
46+
47+
// Type unfocused
48+
await page.keyboard.type('Hello', { delay: 10 });
49+
50+
// Type focused
51+
await page.locator('#input').focus();
52+
53+
await page.keyboard.press('Control+A');
54+
await page.keyboard.type('Hello', { delay: 10 });
55+
56+
await forceFlushReplay();
57+
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);
58+
59+
expect(breadcrumbs).toEqual([
60+
{
61+
timestamp: expect.any(Number),
62+
type: 'default',
63+
category: 'ui.keyDown',
64+
message: 'body',
65+
data: {
66+
nodeId: expect.any(Number),
67+
node: {
68+
attributes: {},
69+
id: expect.any(Number),
70+
tagName: 'body',
71+
textContent: '',
72+
},
73+
metaKey: false,
74+
shiftKey: false,
75+
ctrlKey: true,
76+
altKey: false,
77+
key: 'Control',
78+
},
79+
},
80+
{
81+
timestamp: expect.any(Number),
82+
type: 'default',
83+
category: 'ui.keyDown',
84+
message: 'body',
85+
data: {
86+
nodeId: expect.any(Number),
87+
node: { attributes: {}, id: expect.any(Number), tagName: 'body', textContent: '' },
88+
metaKey: false,
89+
shiftKey: false,
90+
ctrlKey: true,
91+
altKey: false,
92+
key: 'A',
93+
},
94+
},
95+
{
96+
timestamp: expect.any(Number),
97+
type: 'default',
98+
category: 'ui.input',
99+
message: 'body > input#input',
100+
data: {
101+
nodeId: expect.any(Number),
102+
node: {
103+
attributes: { id: 'input' },
104+
id: expect.any(Number),
105+
tagName: 'input',
106+
textContent: '',
107+
},
108+
},
109+
},
110+
]);
111+
});

0 commit comments

Comments
 (0)