@@ -53,8 +53,10 @@ function breadcrumbPathsSentToNative(): string[] {
5353 . filter ( ( p : string ) => p . includes ( 'breadcrumb' ) ) ;
5454}
5555
56- function attributesSentToNative ( ) : Record < string , string > {
57- return Object . assign ( { } , ...nativeMock . useAttributes . mock . calls . map ( ( call ) => call [ 0 ] ) ) ;
56+ async function settle ( ) {
57+ for ( let i = 0 ; i < 10 ; i ++ ) {
58+ await nextTick ( ) ;
59+ }
5860}
5961
6062describe ( 'BacktraceClient native breadcrumb propagation' , ( ) => {
@@ -67,21 +69,24 @@ describe('BacktraceClient native breadcrumb propagation', () => {
6769 it ( 'Should tell the native crash reporter about the breadcrumb files created after rotation' , async ( ) => {
6870 const client = createClient ( ) ;
6971 client . initialize ( ) ;
70-
71- const pathsAtInit = nativeMock . initialize . mock . calls [ 0 ] [ 3 ] . filter ( ( p : string ) => p . includes ( 'breadcrumb' ) ) ;
7272 nativeMock . useAttachments . mockClear ( ) ;
7373
7474 for ( let i = 0 ; i < 20 ; i ++ ) {
7575 client . breadcrumbs ?. info ( `breadcrumb-${ i } ` ) ;
7676 await nextTick ( ) ;
7777 }
78+ await settle ( ) ;
7879
7980 const sentLater = breadcrumbPathsSentToNative ( ) ;
80- expect ( sentLater . length ) . toBeGreaterThan ( 0 ) ;
81- expect ( sentLater . some ( ( p ) => ! pathsAtInit . includes ( p ) ) ) . toBe ( true ) ;
81+ expect ( sentLater . some ( ( p ) => / b t - b r e a d c r u m b s - [ 1 - 9 ] / . test ( p ) ) ) . toBe ( true ) ;
82+
83+ const calls = nativeMock . useAttachments . mock . calls ;
84+ const lastPaths = calls [ calls . length - 1 ] [ 0 ] . filter ( ( p : string ) => p . includes ( 'breadcrumb' ) ) ;
85+ expect ( lastPaths . length ) . toBeGreaterThan ( 0 ) ;
86+ expect ( lastPaths . some ( ( p : string ) => p . includes ( 'bt-breadcrumbs-0_' ) ) ) . toBe ( false ) ;
8287 } ) ;
8388
84- it ( 'Should send the last breadcrumb id to the native crash reporter' , async ( ) => {
89+ it ( 'Should send a fresh last breadcrumb id to the native crash reporter on every rotation ' , async ( ) => {
8590 const client = createClient ( ) ;
8691 client . initialize ( ) ;
8792 nativeMock . useAttributes . mockClear ( ) ;
@@ -90,7 +95,13 @@ describe('BacktraceClient native breadcrumb propagation', () => {
9095 client . breadcrumbs ?. info ( `breadcrumb-${ i } ` ) ;
9196 await nextTick ( ) ;
9297 }
93-
94- expect ( attributesSentToNative ( ) [ 'breadcrumbs.lastId' ] ) . toBeDefined ( ) ;
98+ await settle ( ) ;
99+
100+ const pushed = nativeMock . useAttributes . mock . calls
101+ . map ( ( call ) => call [ 0 ] [ 'breadcrumbs.lastId' ] )
102+ . filter ( ( value ) => value !== undefined )
103+ . map ( Number ) ;
104+ expect ( pushed . length ) . toBeGreaterThan ( 1 ) ;
105+ expect ( pushed [ pushed . length - 1 ] ) . toBeGreaterThan ( pushed [ 0 ] ) ;
95106 } ) ;
96107} ) ;
0 commit comments