Skip to content

Commit 8b53d16

Browse files
authored
test(browser): Add integration tests for setTags (#4345)
1 parent 4d28de1 commit 8b53d16

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
});
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+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
7+
</head>
8+
<body>
9+
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
10+
</body>
11+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sentry.setTags({
2+
tag_1: {},
3+
tag_2: [],
4+
tag_3: ['a', new Map()],
5+
tag_4: () => {},
6+
});
7+
8+
Sentry.captureMessage('non_primitives');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should not accept non-primitive tags', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('non_primitives');
12+
expect(eventData.tags).toMatchObject({});
13+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Sentry.setTags({
2+
tag_1: 'foo',
3+
tag_2: Math.PI,
4+
tag_3: false,
5+
tag_4: null,
6+
tag_5: undefined,
7+
tag_6: -1,
8+
});
9+
10+
Sentry.captureMessage('primitive_tags');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should set primitive tags', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('primitive_tags');
12+
expect(eventData.tags).toMatchObject({
13+
tag_1: 'foo',
14+
tag_2: 3.141592653589793,
15+
tag_3: false,
16+
tag_4: null,
17+
tag_6: -1,
18+
});
19+
});

0 commit comments

Comments
 (0)