Skip to content

Commit

Permalink
test: Port ignoreErrors and denyUrls tests from karma runner (#11449)
Browse files Browse the repository at this point in the history
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 #11084
day 2: #11436
  • Loading branch information
AbhiPrasad authored Apr 8, 2024
1 parent 75d288c commit 091d23b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 56 deletions.
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://public@dsn.ingest.sentry.io/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://public@dsn.ingest.sentry.io/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

0 comments on commit 091d23b

Please sign in to comment.