Skip to content

Commit 39bcfff

Browse files
authored
test(loader): Update loader & test for window.onerror (#7838)
1 parent 7f54143 commit 39bcfff

File tree

8 files changed

+36
-6
lines changed

8 files changed

+36
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ jobs:
583583
bundle:
584584
- loader_base
585585
- loader_eager
586+
- loader_debug
586587
- loader_tracing
587588
- loader_replay
588589
- loader_tracing_replay

packages/browser-integration-tests/fixtures/loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browser-integration-tests/loader-suites/loader/noOnLoad/captureException/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from '@playwright/test';
22

33
import { sentryTest } from '../../../../utils/fixtures';
4-
import { envelopeRequestParser,waitForErrorRequest } from '../../../../utils/helpers';
4+
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';
55

66
sentryTest('captureException works', async ({ getLocalTestUrl, page }) => {
77
const req = waitForErrorRequest(page);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const oldOnError = window.onerror;
2+
3+
window.onerror = function () {
4+
console.log('custom error');
5+
oldOnError && oldOnError.apply(this, arguments);
6+
};
7+
8+
window.doSomethingWrong();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('error handler works with a recursive custom error handler', async ({ getLocalTestUrl, page }) => {
7+
const req = waitForErrorRequest(page);
8+
9+
const url = await getLocalTestUrl({ testDir: __dirname });
10+
await page.goto(url);
11+
12+
const eventData = envelopeRequestParser(await req);
13+
expect(eventData.exception?.values?.length).toBe(1);
14+
expect(eventData.exception?.values?.[0]?.value).toBe('window.doSomethingWrong is not a function');
15+
});

packages/browser-integration-tests/loader-suites/loader/onLoad/captureException/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from '@playwright/test';
22

33
import { sentryTest } from '../../../../utils/fixtures';
4-
import { envelopeRequestParser,waitForErrorRequest } from '../../../../utils/helpers';
4+
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';
55

66
sentryTest('captureException works', async ({ getLocalTestUrl, page }) => {
77
const req = waitForErrorRequest(page);

packages/browser-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"test:loader:tracing": "PW_BUNDLE=loader_tracing yarn test:loader",
4040
"test:loader:replay": "PW_BUNDLE=loader_replay yarn test:loader",
4141
"test:loader:full": "PW_BUNDLE=loader_tracing_replay yarn test:loader",
42+
"test:loader:debug": "PW_BUNDLE=loader_debug yarn test:loader",
4243
"test:ci": "playwright test ./suites --browser='all' --reporter='line'",
4344
"test:update-snapshots": "yarn test --update-snapshots --browser='all' && yarn test --update-snapshots",
4445
"test:detect-flaky": "ts-node scripts/detectFlakyTests.ts",

packages/browser-integration-tests/utils/generatePage.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ const LOADER_TEMPLATE = readFileSync(path.join(__dirname, '../fixtures/loader.js
1111

1212
const LOADER_CONFIGS: Record<string, { bundle: string; options: Record<string, unknown>; lazy: boolean }> = {
1313
loader_base: {
14-
bundle: 'browser/build/bundles/bundle.es5.js',
14+
bundle: 'browser/build/bundles/bundle.es5.min.js',
1515
options: {},
1616
lazy: true,
1717
},
1818
loader_eager: {
19-
bundle: 'browser/build/bundles/bundle.es5.js',
19+
bundle: 'browser/build/bundles/bundle.es5.min.js',
2020
options: {},
2121
lazy: false,
2222
},
23+
loader_debug: {
24+
bundle: 'browser/build/bundles/bundle.es5.debug.min.js',
25+
options: { debug: true },
26+
lazy: true,
27+
},
2328
loader_tracing: {
24-
bundle: 'browser/build/bundles/bundle.tracing.es5.js',
29+
bundle: 'browser/build/bundles/bundle.tracing.es5.min.js',
2530
options: { tracesSampleRate: 1 },
2631
lazy: false,
2732
},

0 commit comments

Comments
 (0)