Skip to content

Commit 4d28de1

Browse files
authored
test(browser): Add integration tests for setTag (#4346)
1 parent 698d631 commit 4d28de1

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sentry.setTag('tag_1', {});
2+
Sentry.setTag('tag_2', []);
3+
Sentry.setTag('tag_3', ['a', new Map()]);
4+
Sentry.setTag('tag_4');
5+
Sentry.setTag('tag_5', () => {});
6+
7+
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sentry.setTag('tag_1', 'foo');
2+
Sentry.setTag('tag_2', Math.PI);
3+
Sentry.setTag('tag_3', false);
4+
Sentry.setTag('tag_4', null);
5+
Sentry.setTag('tag_5', undefined);
6+
Sentry.setTag('tag_6', -1);
7+
8+
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)