@@ -39,6 +39,7 @@ import * as assert from 'assert';
3939import * as sinon from 'sinon' ;
4040import { DocumentLoadInstrumentation } from '../src' ;
4141import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
42+ import { EventNames } from '../src/enums/EventNames' ;
4243
4344const exporter = new InMemorySpanExporter ( ) ;
4445const provider = new BasicTracerProvider ( ) ;
@@ -182,6 +183,25 @@ const entriesFallback = {
182183 loadEventEnd : 1571078170394 ,
183184} as any ;
184185
186+ const paintEntries : PerformanceEntryList = [
187+ {
188+ duration : 0 ,
189+ entryType : 'paint' ,
190+ name : 'first-paint' ,
191+ startTime : 7.480000003241003 ,
192+ toJSON ( ) { } ,
193+ } ,
194+ {
195+ duration : 0 ,
196+ entryType : 'paint' ,
197+ name : 'first-contentful-paint' ,
198+ startTime : 8.480000003241003 ,
199+ toJSON ( ) { } ,
200+ } ,
201+ ] ;
202+
203+ performance . getEntriesByType ;
204+
185205const userAgent =
186206 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36' ;
187207
@@ -246,6 +266,7 @@ describe('DocumentLoad Instrumentation', () => {
246266 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
247267 spyEntries . withArgs ( 'navigation' ) . returns ( [ entries ] ) ;
248268 spyEntries . withArgs ( 'resource' ) . returns ( [ ] ) ;
269+ spyEntries . withArgs ( 'paint' ) . returns ( [ ] ) ;
249270 } ) ;
250271 afterEach ( ( ) => {
251272 spyEntries . restore ( ) ;
@@ -254,7 +275,7 @@ describe('DocumentLoad Instrumentation', () => {
254275 plugin . enable ( ) ;
255276 setTimeout ( ( ) => {
256277 assert . strictEqual ( window . document . readyState , 'complete' ) ;
257- assert . strictEqual ( spyEntries . callCount , 2 ) ;
278+ assert . strictEqual ( spyEntries . callCount , 3 ) ;
258279 done ( ) ;
259280 } ) ;
260281 } ) ;
@@ -270,6 +291,7 @@ describe('DocumentLoad Instrumentation', () => {
270291 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
271292 spyEntries . withArgs ( 'navigation' ) . returns ( [ entries ] ) ;
272293 spyEntries . withArgs ( 'resource' ) . returns ( [ ] ) ;
294+ spyEntries . withArgs ( 'paint' ) . returns ( [ ] ) ;
273295 } ) ;
274296 afterEach ( ( ) => {
275297 spyEntries . restore ( ) ;
@@ -293,7 +315,7 @@ describe('DocumentLoad Instrumentation', () => {
293315 } )
294316 ) ;
295317 setTimeout ( ( ) => {
296- assert . strictEqual ( spyEntries . callCount , 2 ) ;
318+ assert . strictEqual ( spyEntries . callCount , 3 ) ;
297319 done ( ) ;
298320 } ) ;
299321 } ) ;
@@ -305,6 +327,7 @@ describe('DocumentLoad Instrumentation', () => {
305327 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
306328 spyEntries . withArgs ( 'navigation' ) . returns ( [ entries ] ) ;
307329 spyEntries . withArgs ( 'resource' ) . returns ( [ ] ) ;
330+ spyEntries . withArgs ( 'paint' ) . returns ( paintEntries ) ;
308331 } ) ;
309332 afterEach ( ( ) => {
310333 spyEntries . restore ( ) ;
@@ -328,6 +351,12 @@ describe('DocumentLoad Instrumentation', () => {
328351 assert . strictEqual ( fetchSpan . name , 'documentLoad' ) ;
329352 ensureNetworkEventsExists ( rsEvents ) ;
330353
354+ assert . strictEqual ( fsEvents [ 9 ] . name , EventNames . FIRST_PAINT ) ;
355+ assert . strictEqual (
356+ fsEvents [ 10 ] . name ,
357+ EventNames . FIRST_CONTENTFUL_PAINT
358+ ) ;
359+
331360 assert . strictEqual ( fsEvents [ 0 ] . name , PTN . FETCH_START ) ;
332361 assert . strictEqual ( fsEvents [ 1 ] . name , PTN . UNLOAD_EVENT_START ) ;
333362 assert . strictEqual ( fsEvents [ 2 ] . name , PTN . UNLOAD_EVENT_END ) ;
@@ -342,7 +371,7 @@ describe('DocumentLoad Instrumentation', () => {
342371 assert . strictEqual ( fsEvents [ 8 ] . name , PTN . LOAD_EVENT_END ) ;
343372
344373 assert . strictEqual ( rsEvents . length , 9 ) ;
345- assert . strictEqual ( fsEvents . length , 9 ) ;
374+ assert . strictEqual ( fsEvents . length , 11 ) ;
346375 assert . strictEqual ( exporter . getFinishedSpans ( ) . length , 2 ) ;
347376 done ( ) ;
348377 } ) ;
@@ -401,6 +430,7 @@ describe('DocumentLoad Instrumentation', () => {
401430 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
402431 spyEntries . withArgs ( 'navigation' ) . returns ( [ entries ] ) ;
403432 spyEntries . withArgs ( 'resource' ) . returns ( resources ) ;
433+ spyEntries . withArgs ( 'paint' ) . returns ( [ ] ) ;
404434 } ) ;
405435 afterEach ( ( ) => {
406436 spyEntries . restore ( ) ;
@@ -438,6 +468,7 @@ describe('DocumentLoad Instrumentation', () => {
438468 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
439469 spyEntries . withArgs ( 'navigation' ) . returns ( [ entries ] ) ;
440470 spyEntries . withArgs ( 'resource' ) . returns ( resourcesNoSecureConnectionStart ) ;
471+ spyEntries . withArgs ( 'paint' ) . returns ( [ ] ) ;
441472 } ) ;
442473 afterEach ( ( ) => {
443474 spyEntries . restore ( ) ;
@@ -479,6 +510,7 @@ describe('DocumentLoad Instrumentation', () => {
479510 spyEntries = sandbox . stub ( window . performance , 'getEntriesByType' ) ;
480511 spyEntries . withArgs ( 'navigation' ) . returns ( [ entriesWithoutLoadEventEnd ] ) ;
481512 spyEntries . withArgs ( 'resource' ) . returns ( [ ] ) ;
513+ spyEntries . withArgs ( 'paint' ) . returns ( [ ] ) ;
482514 } ) ;
483515 afterEach ( ( ) => {
484516 spyEntries . restore ( ) ;
@@ -603,6 +635,8 @@ describe('DocumentLoad Instrumentation', () => {
603635 . withArgs ( 'navigation' )
604636 . returns ( [ navEntriesWithNegativeFetch ] )
605637 . withArgs ( 'resource' )
638+ . returns ( [ ] )
639+ . withArgs ( 'paint' )
606640 . returns ( [ ] ) ;
607641
608642 sandbox . stub ( window . performance , 'timing' ) . get ( ( ) => {
0 commit comments