Skip to content

Commit 3aaaf76

Browse files
committed
Add config tests.
1 parent b2f2332 commit 3aaaf76

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

packages/browser/test/e2e/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
integrations: [new Sentry.Integrations.Dedupe()],
88
attachStacktrace: true,
9+
ignoreErrors: ['ignoreErrorTest'],
910
denyUrls: ['foo.js'],
1011
beforeBreadcrumb: function(breadcrumb, breadcrumbHint) {
1112
// Remove circular properties from event target
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { test, expect } = require('@playwright/test');
2+
const Sentry = require('@sentry/browser');
3+
4+
const { getSentryEvents } = require('./utils/helpers');
5+
6+
test.describe.only('config', () => {
7+
test.beforeEach(async ({ baseURL, page }) => {
8+
await page.goto(baseURL);
9+
});
10+
11+
test('should allow to ignore specific errors', async ({ page }) => {
12+
const eventData = await getSentryEvents(page, () => {
13+
Sentry.captureException(new Error('foo'));
14+
Sentry.captureException(new Error('ignoreErrorTest'));
15+
Sentry.captureException(new Error('bar'));
16+
});
17+
18+
expect(eventData).toHaveLength(2);
19+
expect(eventData[0].exception.values[0].type).toBe('Error');
20+
expect(eventData[0].exception.values[0].value).toBe('foo');
21+
expect(eventData[1].exception.values[0].type).toBe('Error');
22+
expect(eventData[1].exception.values[0].value).toBe('bar');
23+
});
24+
25+
test('should allow to ignore specific urls', async ({ page }) => {
26+
const eventData = await getSentryEvents(page, () => {
27+
/**
28+
* We always filter on the caller, not the cause of the error
29+
*
30+
* > foo.js file called a function in bar.js
31+
* > bar.js file called a function in baz.js
32+
* > baz.js threw an error
33+
*
34+
* foo.js is denied in the `init` call (init.js), thus we filter it
35+
* */
36+
var urlWithDeniedUrl = new Error('filter');
37+
urlWithDeniedUrl.stack =
38+
'Error: bar\n' +
39+
' at http://localhost:5000/foo.js:7:19\n' +
40+
' at bar(http://localhost:5000/bar.js:2:3)\n' +
41+
' at baz(http://localhost:5000/baz.js:2:9)\n';
42+
43+
/**
44+
* > foo-pass.js file called a function in bar-pass.js
45+
* > bar-pass.js file called a function in baz-pass.js
46+
* > baz-pass.js threw an error
47+
*
48+
* foo-pass.js is *not* denied in the `init` call (init.js), thus we don't filter it
49+
* */
50+
var urlWithoutDeniedUrl = new Error('pass');
51+
urlWithoutDeniedUrl.stack =
52+
'Error: bar\n' +
53+
' at http://localhost:5000/foo-pass.js:7:19\n' +
54+
' at bar(http://localhost:5000/bar-pass.js:2:3)\n' +
55+
' at baz(http://localhost:5000/baz-pass.js:2:9)\n';
56+
57+
Sentry.captureException(urlWithDeniedUrl);
58+
Sentry.captureException(urlWithoutDeniedUrl);
59+
});
60+
61+
expect(eventData).toHaveLength(1);
62+
expect(eventData[0].exception.values[0].type).toBe('Error');
63+
expect(eventData[0].exception.values[0].value).toBe('pass');
64+
});
65+
});

0 commit comments

Comments
 (0)