Skip to content

test: Port onerror tests to playwright #11543

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
dsn: 'https://[email protected]/1337'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function throwStringError() {
throw 'stringError';
}

throwStringError();
Comment on lines +1 to +5
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this code is that it throws an error immediately when the subject script is evaluated by the browser. This results in the infamous Script Error which the SDK filters by default. If you enable debug logging you should see that the error gets dropped by the SDK.

I usually add a click listener to a button and click it in the test to work around this.

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 catch thrown strings', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0].type).toMatch(/SyntaxError/);

// two frames - one from the eval and one from try catch
expect(eventData.exception?.values?.[0].stacktrace?.frames?.length).toBe(2);
});
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/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
{{ suites/loader.js }} // biome-ignore format: No trailing commas
Expand Down
Loading