Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Port ignoreErrors and denyUrls tests from karma runner #11449

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

window._errorCount = 0;

Sentry.init({
dsn: 'https://[email protected]/1337',
denyUrls: ['foo.js'],
beforeSend: event => {
window._errorCount++;
return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* We always filter on the caller, not the cause of the error
*
* > foo.js file called a function in bar.js
* > bar.js file called a function in baz.js
* > baz.js threw an error
*
* foo.js is denied in the `init` call (init.js), thus we filter it
* */
var urlWithDeniedUrl = new Error('filter');
urlWithDeniedUrl.stack =
'Error: bar\n' +
' at http://localhost:5000/foo.js:7:19\n' +
' at bar(http://localhost:5000/bar.js:2:3)\n' +
' at baz(http://localhost:5000/baz.js:2:9)\n';

/**
* > foo-pass.js file called a function in bar-pass.js
* > bar-pass.js file called a function in baz-pass.js
* > baz-pass.js threw an error
*
* foo-pass.js is *not* denied in the `init` call (init.js), thus we don't filter it
* */
var urlWithoutDeniedUrl = new Error('pass');
urlWithoutDeniedUrl.stack =
'Error: bar\n' +
' at http://localhost:5000/foo-pass.js:7:19\n' +
' at bar(http://localhost:5000/bar-pass.js:2:3)\n' +
' at baz(http://localhost:5000/baz-pass.js:2:9)\n';

Sentry.captureException(urlWithDeniedUrl);
Sentry.captureException(urlWithoutDeniedUrl);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';

sentryTest('should allow to ignore specific urls', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.exception?.values?.[0].type).toEqual('Error');
expect(eventData.exception?.values?.[0].value).toEqual('pass');

const count = await page.evaluate('window._errorCount');
expect(count).toEqual(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

window._errorCount = 0;

Sentry.init({
dsn: 'https://[email protected]/1337',
ignoreErrors: ['ignoreErrorTest'],
beforeSend: event => {
window._errorCount++;
return event;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sentry.captureException(new Error('foo'));
Sentry.captureException(new Error('ignoreErrorTest'));
Sentry.captureException(new Error('bar'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getMultipleSentryEnvelopeRequests } from '../../../utils/helpers';

sentryTest('should allow to ignore specific errors', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });

expect(events[0].exception?.values?.[0].type).toEqual('Error');
expect(events[0].exception?.values?.[0].value).toEqual('foo');
expect(events[1].exception?.values?.[0].type).toEqual('Error');
expect(events[1].exception?.values?.[0].value).toEqual('bar');

const count = await page.evaluate('window._errorCount');
expect(count).toEqual(2);
});
55 changes: 0 additions & 55 deletions packages/browser/test/integration/suites/config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/browser/test/integration/suites/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function runVariant(variant) {
/**
* The test runner will replace each of these placeholders with the contents of the corresponding file.
*/
{{ suites/config.js }} // biome-ignore format: No trailing commas
{{ suites/onerror.js }} // biome-ignore format: No trailing commas
{{ suites/onunhandledrejection.js }} // biome-ignore format: No trailing commas
{{ suites/builtins.js }} // biome-ignore format: No trailing commas
Expand Down
Loading