-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Port ignoreErrors and denyUrls tests from karma runner (#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 #11084 day 2: #11436
- Loading branch information
1 parent
75d288c
commit 091d23b
Showing
8 changed files
with
99 additions
and
56 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
dev-packages/browser-integration-tests/suites/public-api/denyUrls/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
32 changes: 32 additions & 0 deletions
32
dev-packages/browser-integration-tests/suites/public-api/denyUrls/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
17 changes: 17 additions & 0 deletions
17
dev-packages/browser-integration-tests/suites/public-api/denyUrls/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
14 changes: 14 additions & 0 deletions
14
dev-packages/browser-integration-tests/suites/public-api/ignoreErrors/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); |
3 changes: 3 additions & 0 deletions
3
dev-packages/browser-integration-tests/suites/public-api/ignoreErrors/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
19 changes: 19 additions & 0 deletions
19
dev-packages/browser-integration-tests/suites/public-api/ignoreErrors/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters