Skip to content

Commit 0426e92

Browse files
committed
add integration test, add public export
1 parent a294ec4 commit 0426e92

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
self._sentryDebugIds = {
2+
'Error at http://sentry-test.io/worker.js': 'worker-debug-id-789',
3+
};
4+
5+
self.postMessage({
6+
_sentryMessage: true,
7+
_sentryDebugIds: self._sentryDebugIds,
8+
});
9+
10+
self.addEventListener('message', event => {
11+
if (event.data.type === 'throw-error') {
12+
throw new Error('Worker error for testing');
13+
}
14+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
// Initialize Sentry with webWorker integration
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
debug: true,
7+
beforeSend(event) {
8+
console.log('xx beforeSend', JSON.stringify(event.exception.values[0].stacktrace.frames, null, 2));
9+
return event;
10+
},
11+
});
12+
13+
const worker = new Worker('/worker.js');
14+
15+
worker.addEventListener('message', event => {
16+
console.log('xx message', event);
17+
});
18+
19+
Sentry.addIntegration(Sentry.webWorkerIntegration({ worker }));
20+
21+
const btn = document.getElementById('errWorker');
22+
23+
btn.addEventListener('click', () => {
24+
worker.postMessage({
25+
type: 'throw-error',
26+
});
27+
});

dev-packages/browser-integration-tests/suites/integrations/webWorker/subject.js

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button id="errWorker">Throw error in worker</button>
8+
</body>
9+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
6+
sentryTest('Assigns web worker debug IDs when using webWorkerIntegration', async ({ getLocalTestUrl, page }) => {
7+
const bundle = process.env.PW_BUNDLE as string | undefined;
8+
if (bundle != null && !bundle.includes('esm') && !bundle.includes('cjs')) {
9+
sentryTest.skip();
10+
}
11+
12+
const url = await getLocalTestUrl({ testDir: __dirname });
13+
14+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page, url);
15+
16+
page.route('**/worker.js', route => {
17+
route.fulfill({
18+
path: `${__dirname}/assets/worker.js`,
19+
});
20+
});
21+
22+
const button = page.locator('#errWorker');
23+
await button.click();
24+
25+
const errorEvent = await errorEventPromise;
26+
27+
expect(errorEvent.debug_meta?.images).toBeDefined();
28+
29+
const debugImages = errorEvent.debug_meta?.images || [];
30+
31+
expect(debugImages.length).toBe(1);
32+
33+
debugImages.forEach(image => {
34+
expect(image.type).toBe('sourcemap');
35+
expect(image.debug_id).toEqual('worker-debug-id-789');
36+
expect(image.code_file).toEqual('http://sentry-test.io/worker.js');
37+
});
38+
});

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ export { openFeatureIntegration, OpenFeatureIntegrationHook } from './integratio
7373
export { unleashIntegration } from './integrations/featureFlags/unleash';
7474
export { statsigIntegration } from './integrations/featureFlags/statsig';
7575
export { diagnoseSdkConnectivity } from './diagnose-sdk';
76+
export { webWorkerIntegration } from './integrations/webWorker';

0 commit comments

Comments
 (0)