MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

test/parallel/test-performance-resourcetimingbufferfull.js:35–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33const cacheMode = '';
34
35async function main() {
36 performance.setResourceTimingBufferSize(1);
37 const args = [
38 requestedUrl,
39 initiatorType,
40 globalThis,
41 cacheMode,
42 {}, // body info
43 200,
44 '',
45 ];
46 performance.markResourceTiming(createTimingInfo(1), ...args);
47 // Trigger a resourcetimingbufferfull event.
48 performance.markResourceTiming(createTimingInfo(2), ...args);
49 performance.markResourceTiming(createTimingInfo(3), ...args);
50 assert.strictEqual(performance.getEntriesByType('resource').length, 1);
51
52 // Clear resource timings on resourcetimingbufferfull event.
53 await new Promise((resolve) => {
54 const listener = common.mustCall((event) => {
55 assert.strictEqual(event.type, 'resourcetimingbufferfull');
56 performance.removeEventListener('resourcetimingbufferfull', listener);
57
58 performance.clearResourceTimings();
59 assert.strictEqual(performance.getEntriesByType('resource').length, 0);
60
61 resolve();
62 });
63 performance.addEventListener('resourcetimingbufferfull', listener);
64 });
65
66 // Secondary buffer has been added to the global buffer.
67 {
68 const entries = performance.getEntriesByType('resource');
69 assert.strictEqual(entries.length, 1);
70 assert.strictEqual(entries[0].startTime, 2);
71 // The last item is discarded.
72 }
73
74
75 performance.clearResourceTimings();
76 performance.setResourceTimingBufferSize(1);
77 performance.markResourceTiming(createTimingInfo(4), ...args);
78 // Trigger a resourcetimingbufferfull event.
79 performance.markResourceTiming(createTimingInfo(5), ...args);
80 performance.markResourceTiming(createTimingInfo(6), ...args);
81
82 // Increase the buffer size on resourcetimingbufferfull event.
83 await new Promise((resolve) => {
84 const listener = common.mustCall((event) => {
85 assert.strictEqual(event.type, 'resourcetimingbufferfull');
86 performance.removeEventListener('resourcetimingbufferfull', listener);
87
88 performance.setResourceTimingBufferSize(2);
89 assert.strictEqual(performance.getEntriesByType('resource').length, 1);
90
91 resolve();
92 });

Calls 7

clearResourceTimingsMethod · 0.80
createTimingInfoFunction · 0.70
removeEventListenerMethod · 0.65
addEventListenerMethod · 0.65
resolveFunction · 0.50
getEntriesByTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…