Skip to content

Commit acaf41a

Browse files
committed
add integration test
1 parent eea5df4 commit acaf41a

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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('a');
46+
await page.keyboard.press('Control+A');
47+
48+
// Type unfocused
49+
await page.keyboard.type('Hello', { delay: 10 });
50+
51+
// Type focused
52+
await page.locator('#input').focus();
53+
54+
await page.keyboard.press('Control+A');
55+
await page.keyboard.type('Hello', { delay: 10 });
56+
57+
await forceFlushReplay();
58+
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);
59+
60+
expect(breadcrumbs).toEqual([
61+
{
62+
timestamp: expect.any(Number),
63+
type: 'default',
64+
category: 'ui.keyDown',
65+
message: 'body',
66+
data: {
67+
nodeId: expect.any(Number),
68+
node: {
69+
attributes: {},
70+
id: expect.any(Number),
71+
tagName: 'body',
72+
textContent: '',
73+
},
74+
metaKey: false,
75+
shiftKey: false,
76+
ctrlKey: true,
77+
altKey: false,
78+
key: 'Control',
79+
},
80+
},
81+
{
82+
timestamp: expect.any(Number),
83+
type: 'default',
84+
category: 'ui.keyDown',
85+
message: 'body',
86+
data: {
87+
nodeId: expect.any(Number),
88+
node: { attributes: {}, id: expect.any(Number), tagName: 'body', textContent: '' },
89+
metaKey: false,
90+
shiftKey: false,
91+
ctrlKey: true,
92+
altKey: false,
93+
key: 'A',
94+
},
95+
},
96+
{
97+
timestamp: expect.any(Number),
98+
type: 'default',
99+
category: 'ui.input',
100+
message: 'body > input#input',
101+
data: {
102+
nodeId: expect.any(Number),
103+
node: {
104+
attributes: { id: 'input' },
105+
id: expect.any(Number),
106+
tagName: 'input',
107+
textContent: '',
108+
},
109+
},
110+
},
111+
]);
112+
});

0 commit comments

Comments
 (0)