@@ -41,8 +41,40 @@ const epsilon = 50;
4141assert . strictEqual ( performance . nodeTiming . name , 'node' ) ;
4242assert . strictEqual ( performance . nodeTiming . entryType , 'node' ) ;
4343
44+ // If timing.duration gets copied into the argument instead of being computed
45+ // via the getter, this should be called right after timing is created.
46+ function checkNodeTiming ( timing ) {
47+ // Calculate the difference between now() and duration as soon as possible.
48+ const now = performance . now ( ) ;
49+ const delta = Math . abs ( now - timing . duration ) ;
50+
51+ log ( JSON . stringify ( timing , null , 2 ) ) ;
52+ // Check that the properties are still reasonable.
53+ assert . strictEqual ( timing . name , 'node' ) ;
54+ assert . strictEqual ( timing . entryType , 'node' ) ;
55+
56+ // Check that duration is positive and practically the same as
57+ // performance.now() i.e. measures Node.js instance up time.
58+ assert . strictEqual ( typeof timing . duration , 'number' ) ;
59+ assert ( timing . duration > 0 , `timing.duration ${ timing . duration } <= 0` ) ;
60+ assert ( delta < 10 ,
61+ `now (${ now } ) - timing.duration (${ timing . duration } ) = ${ delta } >= ${ 10 } ` ) ;
62+
63+ // Check that the following fields do not change.
64+ assert . strictEqual ( timing . startTime , initialTiming . startTime ) ;
65+ assert . strictEqual ( timing . nodeStart , initialTiming . nodeStart ) ;
66+ assert . strictEqual ( timing . v8Start , initialTiming . v8Start ) ;
67+ assert . strictEqual ( timing . environment , initialTiming . environment ) ;
68+ assert . strictEqual ( timing . bootstrapComplete , initialTiming . bootstrapComplete ) ;
69+
70+ assert . strictEqual ( typeof timing . loopStart , 'number' ) ;
71+ assert . strictEqual ( typeof timing . loopExit , 'number' ) ;
72+ }
73+
74+ log ( 'check initial nodeTiming' ) ;
4475// Copy all the values from the getters.
4576const initialTiming = { ...performance . nodeTiming } ;
77+ checkNodeTiming ( initialTiming ) ;
4678
4779{
4880 const {
@@ -87,36 +119,6 @@ const initialTiming = { ...performance.nodeTiming };
87119 `bootstrapComplete ${ bootstrapComplete } >= ${ testStartTime } ` ) ;
88120}
89121
90- function checkNodeTiming ( timing ) {
91- // Calculate the difference between now() and duration as soon as possible.
92- const now = performance . now ( ) ;
93- const delta = Math . abs ( now - timing . duration ) ;
94-
95- log ( JSON . stringify ( timing , null , 2 ) ) ;
96- // Check that the properties are still reasonable.
97- assert . strictEqual ( timing . name , 'node' ) ;
98- assert . strictEqual ( timing . entryType , 'node' ) ;
99-
100- // Check that duration is positive and practically the same as
101- // performance.now() i.e. measures Node.js instance up time.
102- assert . strictEqual ( typeof timing . duration , 'number' ) ;
103- assert ( timing . duration > 0 , `timing.duration ${ timing . duration } <= 0` ) ;
104- assert ( delta < 10 ,
105- `now (${ now } ) - timing.duration (${ timing . duration } ) = ${ delta } >= 10` ) ;
106-
107- // Check that the following fields do not change.
108- assert . strictEqual ( timing . startTime , initialTiming . startTime ) ;
109- assert . strictEqual ( timing . nodeStart , initialTiming . nodeStart ) ;
110- assert . strictEqual ( timing . v8Start , initialTiming . v8Start ) ;
111- assert . strictEqual ( timing . environment , initialTiming . environment ) ;
112- assert . strictEqual ( timing . bootstrapComplete , initialTiming . bootstrapComplete ) ;
113-
114- assert . strictEqual ( typeof timing . loopStart , 'number' ) ;
115- assert . strictEqual ( typeof timing . loopExit , 'number' ) ;
116- }
117-
118- log ( 'check initial nodeTiming' ) ;
119- checkNodeTiming ( initialTiming ) ;
120122assert . strictEqual ( initialTiming . loopExit , - 1 ) ;
121123
122124function checkValue ( timing , name , min , max ) {
0 commit comments