Skip to content

Commit 6925882

Browse files
committed
add tests
1 parent 10d17c6 commit 6925882

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<script></script>
8+
<button onclick="console.log('Test log')" data-log-message>Log message</button>
9+
<button onclick="console.log(document.body)" data-log-element>Log element</button>
10+
</body>
11+
</html>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
5+
6+
sentryTest('should capture console messages in replay', async ({ getLocalTestPath, page, forceFlushReplay }) => {
7+
if (shouldSkipReplayTest()) {
8+
sentryTest.skip();
9+
}
10+
11+
const reqPromise0 = waitForReplayRequest(page, 0);
12+
const reqPromise1 = waitForReplayRequest(page, 1);
13+
14+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
15+
return route.fulfill({
16+
status: 200,
17+
contentType: 'application/json',
18+
body: JSON.stringify({ id: 'test-id' }),
19+
});
20+
});
21+
22+
const url = await getLocalTestPath({ testDir: __dirname });
23+
24+
await page.goto(url);
25+
26+
await reqPromise0;
27+
28+
await page.click('[data-log-message]');
29+
await page.click('[data-log-element]');
30+
31+
await forceFlushReplay();
32+
33+
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1);
34+
35+
expect(breadcrumbs.filter(breadcrumb => breadcrumb.category === 'console')).toEqual([
36+
{
37+
timestamp: expect.any(Number),
38+
type: 'default',
39+
category: 'console',
40+
data: { arguments: ['Test log'], logger: 'console' },
41+
level: 'log',
42+
message: 'Test log',
43+
},
44+
45+
{
46+
timestamp: expect.any(Number),
47+
type: 'default',
48+
category: 'console',
49+
data: { arguments: ['[HTMLElement: HTMLBodyElement]'], logger: 'console' },
50+
level: 'log',
51+
message: '[object HTMLBodyElement]',
52+
},
53+
]);
54+
});

0 commit comments

Comments
 (0)