@@ -14,8 +14,6 @@ vi.mock('@sentry/core', async importActual => {
1414 debug : {
1515 log : vi . fn ( ) ,
1616 } ,
17- mergeMetadataMap : vi . fn ( ) ,
18- getFilenameToMetadataMap : vi . fn ( ) ,
1917 } ;
2018} ) ;
2119
@@ -213,10 +211,10 @@ describe('webWorkerIntegration', () => {
213211 } ) ;
214212
215213 it ( 'processes module metadata from worker' , ( ) => {
216- const mockMergeMetadataMap = SentryCore . mergeMetadataMap as any ;
214+ ( helpers . WINDOW as any ) . _sentryModuleMetadata = undefined ;
217215 const moduleMetadata = {
218- 'worker-file1.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
219- 'worker-file2.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
216+ 'Error\n at worker-file1.js:1:1 ' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
217+ 'Error\n at worker-file2.js:2:2 ' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
220218 } ;
221219
222220 mockEvent . data = {
@@ -228,13 +226,13 @@ describe('webWorkerIntegration', () => {
228226
229227 expect ( mockEvent . stopImmediatePropagation ) . toHaveBeenCalled ( ) ;
230228 expect ( mockDebugLog ) . toHaveBeenCalledWith ( 'Sentry module metadata web worker message received' , mockEvent . data ) ;
231- expect ( mockMergeMetadataMap ) . toHaveBeenCalledWith ( moduleMetadata ) ;
229+ expect ( ( helpers . WINDOW as any ) . _sentryModuleMetadata ) . toEqual ( moduleMetadata ) ;
232230 } ) ;
233231
234232 it ( 'handles message with both debug IDs and module metadata' , ( ) => {
235- const mockMergeMetadataMap = SentryCore . mergeMetadataMap as any ;
233+ ( helpers . WINDOW as any ) . _sentryModuleMetadata = undefined ;
236234 const moduleMetadata = {
237- 'worker-file.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
235+ 'Error\n at worker-file.js:1:1 ' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
238236 } ;
239237
240238 mockEvent . data = {
@@ -246,16 +244,16 @@ describe('webWorkerIntegration', () => {
246244 messageHandler ( mockEvent ) ;
247245
248246 expect ( mockEvent . stopImmediatePropagation ) . toHaveBeenCalled ( ) ;
249- expect ( mockMergeMetadataMap ) . toHaveBeenCalledWith ( moduleMetadata ) ;
247+ expect ( ( helpers . WINDOW as any ) . _sentryModuleMetadata ) . toEqual ( moduleMetadata ) ;
250248 expect ( ( helpers . WINDOW as any ) . _sentryDebugIds ) . toEqual ( {
251249 'worker-file.js' : 'debug-id-1' ,
252250 } ) ;
253251 } ) ;
254252
255253 it ( 'accepts message with only module metadata' , ( ) => {
256- const mockMergeMetadataMap = SentryCore . mergeMetadataMap as any ;
254+ ( helpers . WINDOW as any ) . _sentryModuleMetadata = undefined ;
257255 const moduleMetadata = {
258- 'worker-file.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
256+ 'Error\n at worker-file.js:1:1 ' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
259257 } ;
260258
261259 mockEvent . data = {
@@ -266,7 +264,7 @@ describe('webWorkerIntegration', () => {
266264 messageHandler ( mockEvent ) ;
267265
268266 expect ( mockEvent . stopImmediatePropagation ) . toHaveBeenCalled ( ) ;
269- expect ( mockMergeMetadataMap ) . toHaveBeenCalledWith ( moduleMetadata ) ;
267+ expect ( ( helpers . WINDOW as any ) . _sentryModuleMetadata ) . toEqual ( moduleMetadata ) ;
270268 } ) ;
271269
272270 it ( 'ignores invalid module metadata' , ( ) => {
@@ -279,6 +277,29 @@ describe('webWorkerIntegration', () => {
279277
280278 expect ( mockEvent . stopImmediatePropagation ) . not . toHaveBeenCalled ( ) ;
281279 } ) ;
280+
281+ it ( 'gives main thread precedence over worker for conflicting module metadata' , ( ) => {
282+ ( helpers . WINDOW as any ) . _sentryModuleMetadata = {
283+ 'Error\n at shared-file.js:1:1' : { '_sentryBundlerPluginAppKey:main-app' : true , source : 'main' } ,
284+ 'Error\n at main-only.js:1:1' : { '_sentryBundlerPluginAppKey:main-app' : true } ,
285+ } ;
286+
287+ mockEvent . data = {
288+ _sentryMessage : true ,
289+ _sentryModuleMetadata : {
290+ 'Error\n at shared-file.js:1:1' : { '_sentryBundlerPluginAppKey:worker-app' : true , source : 'worker' } ,
291+ 'Error\n at worker-only.js:1:1' : { '_sentryBundlerPluginAppKey:worker-app' : true } ,
292+ } ,
293+ } ;
294+
295+ messageHandler ( mockEvent ) ;
296+
297+ expect ( ( helpers . WINDOW as any ) . _sentryModuleMetadata ) . toEqual ( {
298+ 'Error\n at shared-file.js:1:1' : { '_sentryBundlerPluginAppKey:main-app' : true , source : 'main' } , // Main thread wins
299+ 'Error\n at main-only.js:1:1' : { '_sentryBundlerPluginAppKey:main-app' : true } , // Main thread preserved
300+ 'Error\n at worker-only.js:1:1' : { '_sentryBundlerPluginAppKey:worker-app' : true } , // Worker added
301+ } ) ;
302+ } ) ;
282303 } ) ;
283304 } ) ;
284305} ) ;
@@ -343,38 +364,28 @@ describe('registerWebWorker', () => {
343364 } ) ;
344365 } ) ;
345366
346- it ( 'calls getFilenameToMetadataMap when module metadata is available' , ( ) => {
347- const mockGetFilenameToMetadataMap = SentryCore . getFilenameToMetadataMap as any ;
348- const extractedMetadata = {
349- 'worker-file1.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
350- 'worker-file2.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
351- } ;
352-
353- mockWorkerSelf . _sentryModuleMetadata = {
367+ it ( 'includes raw module metadata when available' , ( ) => {
368+ const rawMetadata = {
354369 'Error\n at worker-file1.js:1:1' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
355370 'Error\n at worker-file2.js:1:1' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
356371 } ;
357372
358- mockGetFilenameToMetadataMap . mockReturnValue ( extractedMetadata ) ;
373+ mockWorkerSelf . _sentryModuleMetadata = rawMetadata ;
359374
360375 registerWebWorker ( { self : mockWorkerSelf as any } ) ;
361376
362- expect ( mockGetFilenameToMetadataMap ) . toHaveBeenCalledWith ( expect . any ( Function ) ) ;
363377 expect ( mockWorkerSelf . postMessage ) . toHaveBeenCalledWith ( {
364378 _sentryMessage : true ,
365379 _sentryDebugIds : undefined ,
366- _sentryModuleMetadata : extractedMetadata ,
380+ _sentryModuleMetadata : rawMetadata ,
367381 } ) ;
368382 } ) ;
369383
370- it ( 'does not call getFilenameToMetadataMap when module metadata is not available' , ( ) => {
371- const mockGetFilenameToMetadataMap = SentryCore . getFilenameToMetadataMap as any ;
372-
384+ it ( 'sends undefined module metadata when not available' , ( ) => {
373385 mockWorkerSelf . _sentryModuleMetadata = undefined ;
374386
375387 registerWebWorker ( { self : mockWorkerSelf as any } ) ;
376388
377- expect ( mockGetFilenameToMetadataMap ) . not . toHaveBeenCalled ( ) ;
378389 expect ( mockWorkerSelf . postMessage ) . toHaveBeenCalledWith ( {
379390 _sentryMessage : true ,
380391 _sentryDebugIds : undefined ,
@@ -383,19 +394,14 @@ describe('registerWebWorker', () => {
383394 } ) ;
384395
385396 it ( 'includes both debug IDs and module metadata when both available' , ( ) => {
386- const mockGetFilenameToMetadataMap = SentryCore . getFilenameToMetadataMap as any ;
387- const extractedMetadata = {
388- 'worker-file.js' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
397+ const rawMetadata = {
398+ 'Error\n at worker-file.js:1:1' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
389399 } ;
390400
391401 mockWorkerSelf . _sentryDebugIds = {
392402 'worker-file.js' : 'debug-id-1' ,
393403 } ;
394- mockWorkerSelf . _sentryModuleMetadata = {
395- 'Error\n at worker-file.js:1:1' : { '_sentryBundlerPluginAppKey:my-app' : true } ,
396- } ;
397-
398- mockGetFilenameToMetadataMap . mockReturnValue ( extractedMetadata ) ;
404+ mockWorkerSelf . _sentryModuleMetadata = rawMetadata ;
399405
400406 registerWebWorker ( { self : mockWorkerSelf as any } ) ;
401407
@@ -404,7 +410,7 @@ describe('registerWebWorker', () => {
404410 _sentryDebugIds : {
405411 'worker-file.js' : 'debug-id-1' ,
406412 } ,
407- _sentryModuleMetadata : extractedMetadata ,
413+ _sentryModuleMetadata : rawMetadata ,
408414 } ) ;
409415 } ) ;
410416} ) ;
@@ -474,6 +480,7 @@ describe('registerWebWorker and webWorkerIntegration', () => {
474480 expect ( mockWorker . postMessage ) . toHaveBeenCalledWith ( {
475481 _sentryMessage : true ,
476482 _sentryDebugIds : mockWorker . _sentryDebugIds ,
483+ _sentryModuleMetadata : undefined ,
477484 } ) ;
478485
479486 expect ( ( helpers . WINDOW as any ) . _sentryDebugIds ) . toEqual ( {
@@ -494,6 +501,7 @@ describe('registerWebWorker and webWorkerIntegration', () => {
494501 expect ( mockWorker3 . postMessage ) . toHaveBeenCalledWith ( {
495502 _sentryMessage : true ,
496503 _sentryDebugIds : mockWorker3 . _sentryDebugIds ,
504+ _sentryModuleMetadata : undefined ,
497505 } ) ;
498506
499507 expect ( ( helpers . WINDOW as any ) . _sentryDebugIds ) . toEqual ( {
0 commit comments