@@ -153,32 +153,37 @@ test.describe("POST beacon LoAF", () => {
153153 if ( loafSupported ) {
154154 expect ( loafScripts . length ) . toEqual ( 2 ) ;
155155
156- const external = loafScripts [ 0 ] ;
157- const externalUrl = new URL ( external . sourceUrl ) ;
158- const [ externalStartTime , externalDuration ] = external . timings [ 0 ] ;
156+ const documentScript = loafScripts . find ( ( script ) =>
157+ script . sourceUrl . endsWith ( "/long-animation-frames.html" ) ,
158+ ) ! ;
159+ const externalScript = loafScripts . find ( ( script ) =>
160+ script . sourceUrl . endsWith ( "/external-long-task.js" ) ,
161+ ) ! ;
162+
163+ const externalUrl = new URL ( externalScript . sourceUrl ) ;
164+ const [ externalStartTime , externalDuration ] = externalScript . timings [ 0 ] ;
159165 expect ( externalUrl . pathname ) . toEqual ( "/external-long-task.js" ) ;
160166 // Invoker has been removed to try and reduce the number of LoAF entries
161167 // expect(external.invoker).toEqual(external.sourceUrl);
162- expect ( external . invoker ) . toEqual ( "" ) ;
163- expect ( external . sourceFunctionName ) . toEqual ( "" ) ;
164- expect ( external . totalEntries ) . toEqual ( 1 ) ;
165- expect ( external . totalDuration ) . toBeBetween ( 49 , 59 ) ;
168+ expect ( externalScript . invoker ) . toEqual ( "" ) ;
169+ expect ( externalScript . sourceFunctionName ) . toEqual ( "" ) ;
170+ expect ( externalScript . totalEntries ) . toEqual ( 1 ) ;
171+ expect ( externalScript . totalDuration ) . toBeBetween ( 49 , 59 ) ;
166172 expect ( externalStartTime ) . toBeGreaterThanOrEqual ( inp . startTime ) ;
167173 expect ( externalDuration ) . toBeBetween ( 49 , 59 ) ;
168174
169- const onload = loafScripts [ 1 ] ;
170- const onloadUrl = new URL ( onload . sourceUrl ) ;
171- const [ onloadStartTime , onloadDuration ] = onload . timings [ 0 ] ;
175+ const documentUrl = new URL ( documentScript . sourceUrl ) ;
176+ const [ documentStartTime , documentDuration ] = documentScript . timings [ 0 ] ;
172177
173- expect ( onloadUrl . pathname ) . toEqual ( "/long-animation-frames.html" ) ;
178+ expect ( documentUrl . pathname ) . toEqual ( "/long-animation-frames.html" ) ;
174179 // Invoker has been removed to try and reduce the number of LoAF entries
175180 // expect(onload.invoker).toEqual("SCRIPT[src=external-long-task.js].onload");
176- expect ( onload . invoker ) . toEqual ( "" ) ;
177- expect ( onload . sourceFunctionName ) . toEqual ( "" ) ;
178- expect ( onload . totalEntries ) . toEqual ( 1 ) ;
179- expect ( onload . totalDuration ) . toBeBetween ( 49 , 59 ) ;
180- expect ( onloadStartTime ) . toBeGreaterThanOrEqual ( inp . startTime ) ;
181- expect ( onloadDuration ) . toBeBetween ( 49 , 59 ) ;
181+ expect ( documentScript . invoker ) . toEqual ( "" ) ;
182+ expect ( documentScript . sourceFunctionName ) . toEqual ( "" ) ;
183+ expect ( documentScript . totalEntries ) . toEqual ( 1 ) ;
184+ expect ( documentScript . totalDuration ) . toBeBetween ( 49 , 59 ) ;
185+ expect ( documentStartTime ) . toBeGreaterThanOrEqual ( inp . startTime ) ;
186+ expect ( documentDuration ) . toBeBetween ( 49 , 59 ) ;
182187 } else {
183188 expect ( loafScripts . length ) . toEqual ( 0 ) ;
184189 }
0 commit comments