Skip to content

test(loader): Update loader & test for window.onerror #7838

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 1 commit into from
Apr 13, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ jobs:
bundle:
- loader_base
- loader_eager
- loader_debug
- loader_tracing
- loader_replay
- loader_tracing_replay
Expand Down
2 changes: 1 addition & 1 deletion 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
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser,waitForErrorRequest } from '../../../../utils/helpers';
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';

sentryTest('captureException works', async ({ getLocalTestUrl, page }) => {
const req = waitForErrorRequest(page);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const oldOnError = window.onerror;

window.onerror = function () {
console.log('custom error');
oldOnError && oldOnError.apply(this, arguments);
};

window.doSomethingWrong();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';

sentryTest('error handler works with a recursive custom error handler', async ({ getLocalTestUrl, page }) => {
const req = waitForErrorRequest(page);

const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);

const eventData = envelopeRequestParser(await req);
expect(eventData.exception?.values?.length).toBe(1);
expect(eventData.exception?.values?.[0]?.value).toBe('window.doSomethingWrong is not a function');
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser,waitForErrorRequest } from '../../../../utils/helpers';
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';

sentryTest('captureException works', async ({ getLocalTestUrl, page }) => {
const req = waitForErrorRequest(page);
Expand Down
1 change: 1 addition & 0 deletions packages/browser-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test:loader:tracing": "PW_BUNDLE=loader_tracing yarn test:loader",
"test:loader:replay": "PW_BUNDLE=loader_replay yarn test:loader",
"test:loader:full": "PW_BUNDLE=loader_tracing_replay yarn test:loader",
"test:loader:debug": "PW_BUNDLE=loader_debug yarn test:loader",
"test:ci": "playwright test ./suites --browser='all' --reporter='line'",
"test:update-snapshots": "yarn test --update-snapshots --browser='all' && yarn test --update-snapshots",
"test:detect-flaky": "ts-node scripts/detectFlakyTests.ts",
Expand Down
11 changes: 8 additions & 3 deletions packages/browser-integration-tests/utils/generatePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ const LOADER_TEMPLATE = readFileSync(path.join(__dirname, '../fixtures/loader.js

const LOADER_CONFIGS: Record<string, { bundle: string; options: Record<string, unknown>; lazy: boolean }> = {
loader_base: {
bundle: 'browser/build/bundles/bundle.es5.js',
bundle: 'browser/build/bundles/bundle.es5.min.js',
options: {},
lazy: true,
},
loader_eager: {
bundle: 'browser/build/bundles/bundle.es5.js',
bundle: 'browser/build/bundles/bundle.es5.min.js',
options: {},
lazy: false,
},
loader_debug: {
bundle: 'browser/build/bundles/bundle.es5.debug.min.js',
options: { debug: true },
lazy: true,
},
loader_tracing: {
bundle: 'browser/build/bundles/bundle.tracing.es5.js',
bundle: 'browser/build/bundles/bundle.tracing.es5.min.js',
options: { tracesSampleRate: 1 },
lazy: false,
},
Expand Down