| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a7f565f commit 6e84d21
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,8 +41,40 @@ const epsilon = 50; | |||
| 41 | 41 | assert.strictEqual(performance.nodeTiming.name, 'node'); | |
| 42 | 42 | assert.strictEqual(performance.nodeTiming.entryType, 'node'); | |
| 43 | 43 | ||
| 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'); | ||
| 44 | 75 | // Copy all the values from the getters. | |
| 45 | 76 | const initialTiming = { ...performance.nodeTiming }; | |
| 77 | + checkNodeTiming(initialTiming); | ||
| 46 | 78 | ||
| 47 | 79 | { | |
| 48 | 80 | const { | |
@@ -87,36 +119,6 @@ const initialTiming = { ...performance.nodeTiming }; | |||
| 87 | 119 | `bootstrapComplete ${bootstrapComplete} >= ${testStartTime}`); | |
| 88 | 120 | } | |
| 89 | 121 | ||
| 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); | ||
| 120 | 122 | assert.strictEqual(initialTiming.loopExit, -1); | |
| 121 | 123 | ||
| 122 | 124 | function checkValue(timing, name, min, max) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments