@@ -65,6 +65,49 @@ describe('Sentry Metro Serializer', () => {
6565 expect ( debugId ) . toMatch ( / ^ [ 0 - 9 a - f A - F ] { 8 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 12 } $ / ) ;
6666 }
6767 } ) ;
68+
69+ test ( 'calculates debug id from bundle code when debug id module is not found' , async ( ) => {
70+ // Create a custom serializer that returns bundle code without the debug ID module
71+ const customSerializer : MetroSerializer = async ( ) => {
72+ const bundleCodeWithoutDebugId = 'console.log("test bundle");' ;
73+ return {
74+ code : bundleCodeWithoutDebugId ,
75+ map : '{"version":3,"sources":[],"names":[],"mappings":""}' ,
76+ } ;
77+ } ;
78+
79+ const serializer = createSentryMetroSerializer ( customSerializer ) ;
80+ const bundle = await serializer ( ...mockMinSerializerArgs ( ) ) ;
81+
82+ if ( typeof bundle === 'string' ) {
83+ fail ( 'Expected bundle to be an object with a "code" property' ) ;
84+ }
85+
86+ // The debug ID should be calculated from the bundle code content
87+ // and added as a comment in the bundle code
88+ expect ( bundle . code ) . toContain ( '//# debugId=' ) ;
89+
90+ // Extract the debug ID from the comment
91+ const debugIdMatch = bundle . code . match ( / \/ \/ # d e b u g I d = ( [ 0 - 9 a - f A - F - ] + ) / ) ;
92+ expect ( debugIdMatch ) . toBeTruthy ( ) ;
93+ const debugId = debugIdMatch ?. [ 1 ] ;
94+
95+ // Verify it's a valid UUID format
96+ expect ( debugId ) . toMatch ( / ^ [ 0 - 9 a - f A - F ] { 8 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 4 } - [ 0 - 9 a - f A - F ] { 12 } $ / ) ;
97+
98+ // Verify the debug ID is also in the source map
99+ const sourceMap = JSON . parse ( bundle . map ) ;
100+ expect ( sourceMap . debug_id ) . toBe ( debugId ) ;
101+ expect ( sourceMap . debugId ) . toBe ( debugId ) ;
102+
103+ // The calculated debug ID should be deterministic based on the bundle content
104+ // Running the serializer again with the same content should produce the same debug ID
105+ const bundle2 = await serializer ( ...mockMinSerializerArgs ( ) ) ;
106+ if ( typeof bundle2 !== 'string' ) {
107+ const debugIdMatch2 = bundle2 . code . match ( / \/ \/ # d e b u g I d = ( [ 0 - 9 a - f A - F - ] + ) / ) ;
108+ expect ( debugIdMatch2 ?. [ 1 ] ) . toBe ( debugId ) ;
109+ }
110+ } ) ;
68111} ) ;
69112
70113function mockMinSerializerArgs ( options ?: {
0 commit comments