Skip to content

test(loader): Update Loader Script & test error in sentryOnLoad #13952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-packages/browser-integration-tests/fixtures/loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// we define sentryOnLoad in template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sentry.captureException('Test exception');
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>
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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: we could assert on the console output here so that we ensure that the error is logged, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to assert on the error message!

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'),
]);
},
);
Loading