Skip to content

Commit 13a489d

Browse files
mydeabillyvg
authored andcommitted
test(loader): Update Loader Script & test error in sentryOnLoad (#13952)
Updates the loader & adds tests for getsentry/sentry#78993
1 parent 9fb6ac0 commit 13a489d

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

Diff for: dev-packages/browser-integration-tests/fixtures/loader.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// we define sentryOnLoad in template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureException('Test exception');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script>
6+
window.sentryOnLoad = function () {
7+
Sentry.init({
8+
tracesSampleRate: 0.123,
9+
});
10+
11+
throw new Error('sentryOnLoad error');
12+
};
13+
</script>
14+
</head>
15+
<body></body>
16+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
5+
6+
sentryTest(
7+
'sentryOnLoad callback is called before Sentry.onLoad() and handles errors in handler',
8+
async ({ getLocalTestUrl, page }) => {
9+
const errors: string[] = [];
10+
11+
page.on('console', msg => {
12+
if (msg.type() === 'error') {
13+
errors.push(msg.text());
14+
}
15+
});
16+
17+
const url = await getLocalTestUrl({ testDir: __dirname });
18+
const req = await waitForErrorRequestOnUrl(page, url);
19+
20+
const eventData = envelopeRequestParser(req);
21+
22+
expect(eventData.message).toBe('Test exception');
23+
24+
expect(await page.evaluate('Sentry.getClient().getOptions().tracesSampleRate')).toEqual(0.123);
25+
26+
expect(errors).toEqual([
27+
'Error while calling `sentryOnLoad` handler:',
28+
expect.stringContaining('Error: sentryOnLoad error'),
29+
]);
30+
},
31+
);

0 commit comments

Comments
 (0)