Skip to content

Commit 9671596

Browse files
AbhiPrasadcadesalaberry
authored andcommitted
test: Port ignoreErrors and denyUrls tests from karma runner (getsentry#11449)
I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 3: `packages/browser/test/integration/suites/config.js` I was surprised we never had `ignoreErrors` or `denyUrls` tests in playwright, so it's good to get the confidence that everything works here. ref getsentry#11084 day 2: getsentry#11436
1 parent dc1b206 commit 9671596

File tree

8 files changed

+99
-56
lines changed

8 files changed

+99
-56
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
window._errorCount = 0;
6+
7+
Sentry.init({
8+
dsn: 'https://[email protected]/1337',
9+
denyUrls: ['foo.js'],
10+
beforeSend: event => {
11+
window._errorCount++;
12+
return event;
13+
},
14+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* We always filter on the caller, not the cause of the error
3+
*
4+
* > foo.js file called a function in bar.js
5+
* > bar.js file called a function in baz.js
6+
* > baz.js threw an error
7+
*
8+
* foo.js is denied in the `init` call (init.js), thus we filter it
9+
* */
10+
var urlWithDeniedUrl = new Error('filter');
11+
urlWithDeniedUrl.stack =
12+
'Error: bar\n' +
13+
' at http://localhost:5000/foo.js:7:19\n' +
14+
' at bar(http://localhost:5000/bar.js:2:3)\n' +
15+
' at baz(http://localhost:5000/baz.js:2:9)\n';
16+
17+
/**
18+
* > foo-pass.js file called a function in bar-pass.js
19+
* > bar-pass.js file called a function in baz-pass.js
20+
* > baz-pass.js threw an error
21+
*
22+
* foo-pass.js is *not* denied in the `init` call (init.js), thus we don't filter it
23+
* */
24+
var urlWithoutDeniedUrl = new Error('pass');
25+
urlWithoutDeniedUrl.stack =
26+
'Error: bar\n' +
27+
' at http://localhost:5000/foo-pass.js:7:19\n' +
28+
' at bar(http://localhost:5000/bar-pass.js:2:3)\n' +
29+
' at baz(http://localhost:5000/baz-pass.js:2:9)\n';
30+
31+
Sentry.captureException(urlWithDeniedUrl);
32+
Sentry.captureException(urlWithoutDeniedUrl);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
6+
7+
sentryTest('should allow to ignore specific urls', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.exception?.values?.[0].type).toEqual('Error');
13+
expect(eventData.exception?.values?.[0].value).toEqual('pass');
14+
15+
const count = await page.evaluate('window._errorCount');
16+
expect(count).toEqual(1);
17+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
window._errorCount = 0;
6+
7+
Sentry.init({
8+
dsn: 'https://[email protected]/1337',
9+
ignoreErrors: ['ignoreErrorTest'],
10+
beforeSend: event => {
11+
window._errorCount++;
12+
return event;
13+
},
14+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sentry.captureException(new Error('foo'));
2+
Sentry.captureException(new Error('ignoreErrorTest'));
3+
Sentry.captureException(new Error('bar'));
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+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers';
6+
7+
sentryTest('should allow to ignore specific errors', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });
11+
12+
expect(events[0].exception?.values?.[0].type).toEqual('Error');
13+
expect(events[0].exception?.values?.[0].value).toEqual('foo');
14+
expect(events[1].exception?.values?.[0].type).toEqual('Error');
15+
expect(events[1].exception?.values?.[0].value).toEqual('bar');
16+
17+
const count = await page.evaluate('window._errorCount');
18+
expect(count).toEqual(2);
19+
});

packages/browser/test/integration/suites/config.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/browser/test/integration/suites/shell.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function runVariant(variant) {
2222
/**
2323
* The test runner will replace each of these placeholders with the contents of the corresponding file.
2424
*/
25-
{{ suites/config.js }} // biome-ignore format: No trailing commas
2625
{{ suites/onerror.js }} // biome-ignore format: No trailing commas
2726
{{ suites/onunhandledrejection.js }} // biome-ignore format: No trailing commas
2827
{{ suites/builtins.js }} // biome-ignore format: No trailing commas

0 commit comments

Comments
 (0)