Skip to content

Commit

Permalink
Add config tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Nov 9, 2021
1 parent b2f2332 commit c28ceac
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/browser/test/e2e/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [new Sentry.Integrations.Dedupe()],
attachStacktrace: true,
ignoreErrors: ['ignoreErrorTest'],
denyUrls: ['foo.js'],
beforeBreadcrumb: function(breadcrumb, breadcrumbHint) {
// Remove circular properties from event target
Expand Down
65 changes: 65 additions & 0 deletions packages/browser/test/e2e/test/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { test, expect } = require('@playwright/test');
const Sentry = require('@sentry/browser');

const { getSentryEvents } = require('./utils/helpers');

test.describe('config', () => {
test.beforeEach(async ({ baseURL, page }) => {
await page.goto(baseURL);
});

test('should allow to ignore specific errors', async ({ page }) => {
const eventData = await getSentryEvents(page, () => {
Sentry.captureException(new Error('foo'));
Sentry.captureException(new Error('ignoreErrorTest'));
Sentry.captureException(new Error('bar'));
});

expect(eventData).toHaveLength(2);
expect(eventData[0].exception.values[0].type).toBe('Error');
expect(eventData[0].exception.values[0].value).toBe('foo');
expect(eventData[1].exception.values[0].type).toBe('Error');
expect(eventData[1].exception.values[0].value).toBe('bar');
});

test('should allow to ignore specific urls', async ({ page }) => {
const eventData = await getSentryEvents(page, () => {
/**
* 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);
});

expect(eventData).toHaveLength(1);
expect(eventData[0].exception.values[0].type).toBe('Error');
expect(eventData[0].exception.values[0].value).toBe('pass');
});
});

0 comments on commit c28ceac

Please sign in to comment.