Skip to content

Commit a5e7ff6

Browse files
authored
test(browser): Add integration tests for configureScope (#4350)
1 parent 15773ba commit a5e7ff6

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sentry.configureScope(scope => {
2+
scope.setTag('foo', 'bar');
3+
scope.setUser({ id: 'baz' });
4+
scope.setExtra('qux', 'quux');
5+
scope.clear();
6+
});
7+
8+
Sentry.captureMessage('cleared_scope');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should clear previously set properties of a scope', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('cleared_scope');
12+
expect(eventData.user).toBeUndefined();
13+
expect(eventData.tags).toBeUndefined();
14+
expect(eventData.extra).toBeUndefined();
15+
});
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sentry.configureScope(scope => {
2+
scope.setTag('foo', 'bar');
3+
scope.setUser({ id: 'baz' });
4+
scope.setExtra('qux', 'quux');
5+
});
6+
7+
Sentry.captureMessage('configured_scope');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should set different properties of a scope', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('configured_scope');
12+
expect(eventData.user).toMatchObject({ id: 'baz' });
13+
expect(eventData.tags).toMatchObject({ foo: 'bar' });
14+
expect(eventData.extra).toMatchObject({ qux: 'quux' });
15+
});
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>

0 commit comments

Comments
 (0)