-
-
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(loader): Update Loader Script & test error in
sentryOnLoad
(#1…
…3952) Updates the loader & adds tests for getsentry/sentry#78993
- Loading branch information
Showing
5 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
dev-packages/browser-integration-tests/loader-suites/loader/onLoad/sentryOnLoadError/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 @@ | ||
// we define sentryOnLoad in template |
1 change: 1 addition & 0 deletions
1
...ckages/browser-integration-tests/loader-suites/loader/onLoad/sentryOnLoadError/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 @@ | ||
Sentry.captureException('Test exception'); |
16 changes: 16 additions & 0 deletions
16
...ges/browser-integration-tests/loader-suites/loader/onLoad/sentryOnLoadError/template.html
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,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script> | ||
window.sentryOnLoad = function () { | ||
Sentry.init({ | ||
tracesSampleRate: 0.123, | ||
}); | ||
|
||
throw new Error('sentryOnLoad error'); | ||
}; | ||
</script> | ||
</head> | ||
<body></body> | ||
</html> |
31 changes: 31 additions & 0 deletions
31
dev-packages/browser-integration-tests/loader-suites/loader/onLoad/sentryOnLoadError/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,31 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'sentryOnLoad callback is called before Sentry.onLoad() and handles errors in handler', | ||
async ({ getLocalTestUrl, page }) => { | ||
const errors: string[] = []; | ||
|
||
page.on('console', msg => { | ||
if (msg.type() === 'error') { | ||
errors.push(msg.text()); | ||
} | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
const req = await waitForErrorRequestOnUrl(page, url); | ||
|
||
const eventData = envelopeRequestParser(req); | ||
|
||
expect(eventData.message).toBe('Test exception'); | ||
|
||
expect(await page.evaluate('Sentry.getClient().getOptions().tracesSampleRate')).toEqual(0.123); | ||
|
||
expect(errors).toEqual([ | ||
'Error while calling `sentryOnLoad` handler:', | ||
expect.stringContaining('Error: sentryOnLoad error'), | ||
]); | ||
}, | ||
); |