Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed May 10, 2023
1 parent eea5df4 commit da6b84f
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window.Replay = new Sentry.Replay({
flushMinDelay: 1000,
flushMaxDelay: 1000,
});

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
sampleRate: 0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 0.0,

integrations: [window.Replay],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<input id="input" />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { expect } from '@playwright/test';
import { IncrementalSource } from '@sentry-internal/rrweb';
import type { inputData } from '@sentry-internal/rrweb/typings/types';

import { sentryTest } from '../../../utils/fixtures';
import { IncrementalRecordingSnapshot, getCustomRecordingEvents } from '../../../utils/replayHelpers';
import {
getIncrementalRecordingSnapshots,
shouldSkipReplayTest,
waitForReplayRequest,
} from '../../../utils/replayHelpers';

function isInputMutation(
snap: IncrementalRecordingSnapshot,
): snap is IncrementalRecordingSnapshot & { data: inputData } {
return snap.data.source == IncrementalSource.Input;
}

sentryTest('captures keyboard events', async ({ forceFlushReplay, getLocalTestPath, page }) => {
if (shouldSkipReplayTest()) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);

await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

const url = await getLocalTestPath({ testDir: __dirname });

await page.goto(url);
await reqPromise0;
await forceFlushReplay();

const reqPromise1 = waitForReplayRequest(page, (event, res) => {
return getCustomRecordingEvents(res).breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.keyDown');
});

// Trigger keyboard unfocused
await page.keyboard.press('Control+A');

// Type unfocused
await page.keyboard.type('Hello', { delay: 10 });

// Type focused
await page.locator('#input').focus();

await page.keyboard.press('Control+A');
await page.keyboard.type('Hello', { delay: 10 });

await forceFlushReplay();
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);

expect(breadcrumbs).toEqual([
{
timestamp: expect.any(Number),
type: 'default',
category: 'ui.keyDown',
message: 'body',
data: {
nodeId: expect.any(Number),
node: {
attributes: {},
id: expect.any(Number),
tagName: 'body',
textContent: '',
},
metaKey: false,
shiftKey: false,
ctrlKey: true,
altKey: false,
key: 'Control',
},
},
{
timestamp: expect.any(Number),
type: 'default',
category: 'ui.keyDown',
message: 'body',
data: {
nodeId: expect.any(Number),
node: { attributes: {}, id: expect.any(Number), tagName: 'body', textContent: '' },
metaKey: false,
shiftKey: false,
ctrlKey: true,
altKey: false,
key: 'A',
},
},
{
timestamp: expect.any(Number),
type: 'default',
category: 'ui.input',
message: 'body > input#input',
data: {
nodeId: expect.any(Number),
node: {
attributes: { id: 'input' },
id: expect.any(Number),
tagName: 'input',
textContent: '',
},
},
},
]);
});

0 comments on commit da6b84f

Please sign in to comment.