Skip to content

Commit 9aa2489

Browse files
committed
Add integration test
1 parent 50629fb commit 9aa2489

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { viewHierarchyIntegration } from '@sentry/browser';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
8+
integrations: [viewHierarchyIntegration()],
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error('Some error');
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+
<title></title>
6+
</head>
7+
<body>
8+
<h1>Some title</h1>
9+
<p>Some text</p>
10+
</body>
11+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from '@playwright/test';
2+
import type { ViewHierarchyData } from '@sentry/core';
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import { getMultipleSentryEnvelopeRequests, envelopeParser } from '../../../utils/helpers';
5+
6+
sentryTest('Captures view hierarchy as attachment', async ({ getLocalTestUrl, page }) => {
7+
const url = await getLocalTestUrl({ testDir: __dirname });
8+
9+
const [, events] = await Promise.all([
10+
page.goto(url),
11+
getMultipleSentryEnvelopeRequests<ViewHierarchyData>(
12+
page,
13+
1,
14+
{},
15+
req => envelopeParser(req)?.[4] as ViewHierarchyData,
16+
),
17+
]);
18+
19+
expect(events).toHaveLength(1);
20+
const event: ViewHierarchyData = events[0];
21+
22+
expect(event.rendering_system).toBe('DOM');
23+
expect(event.positioning).toBe('absolute');
24+
expect(event.windows).toHaveLength(2);
25+
expect(event.windows[0].type).toBe('h1');
26+
expect(event.windows[0].visible).toBe(true);
27+
expect(event.windows[0].alpha).toBe(1);
28+
expect(event.windows[0].children).toHaveLength(0);
29+
30+
expect(event.windows[1].type).toBe('p');
31+
expect(event.windows[1].visible).toBe(true);
32+
expect(event.windows[1].alpha).toBe(1);
33+
expect(event.windows[1].children).toHaveLength(0);
34+
});

0 commit comments

Comments
 (0)