MCPcopy Create free account
hub / github.com/nodejs/node / main

Function main

test/parallel/test-performance-resourcetimingbuffersize.js:32–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30const cacheMode = '';
31
32async function main() {
33 const args = [
34 timingInfo,
35 requestedUrl,
36 initiatorType,
37 globalThis,
38 cacheMode,
39 ];
40
41 assert.throws(() => performance.setResourceTimingBufferSize(1n), {
42 name: 'TypeError',
43 code: 'ERR_INVALID_ARG_TYPE',
44 message: 'maxSize is a BigInt and cannot be converted to a number.',
45 });
46
47 assert.throws(() => performance.setResourceTimingBufferSize(Symbol()), {
48 name: 'TypeError',
49 code: 'ERR_INVALID_ARG_TYPE',
50 message: 'maxSize is a Symbol and cannot be converted to a number.',
51 });
52
53 // Invalid buffer size values are converted to 0.
54 const invalidValues = [ null, undefined, true, false, -1, 0.5, Infinity, NaN, '', 'foo', {}, [], () => {} ];
55 for (const value of invalidValues) {
56 performance.setResourceTimingBufferSize(value);
57 performance.markResourceTiming(...args);
58 assert.strictEqual(performance.getEntriesByType('resource').length, 0);
59 performance.clearResourceTimings();
60 }
61 // Wait for the buffer full event to be cleared.
62 await waitBufferFullEvent();
63
64 performance.setResourceTimingBufferSize(1);
65 performance.markResourceTiming(...args);
66 // Trigger a resourcetimingbufferfull event.
67 performance.markResourceTiming(...args);
68 assert.strictEqual(performance.getEntriesByType('resource').length, 1);
69 await waitBufferFullEvent();
70
71 // Apply a new buffer size limit
72 performance.setResourceTimingBufferSize(0);
73 // Buffer is not cleared on `performance.setResourceTimingBufferSize`.
74 assert.strictEqual(performance.getEntriesByType('resource').length, 1);
75
76 performance.clearResourceTimings();
77 assert.strictEqual(performance.getEntriesByType('resource').length, 0);
78 // Trigger a resourcetimingbufferfull event.
79 performance.markResourceTiming(...args);
80 // New entry is not added to the global buffer.
81 assert.strictEqual(performance.getEntriesByType('resource').length, 0);
82 await waitBufferFullEvent();
83
84 // Apply a new buffer size limit
85 performance.setResourceTimingBufferSize(1);
86 performance.markResourceTiming(...args);
87 assert.strictEqual(performance.getEntriesByType('resource').length, 1);
88}
89

Calls 5

waitBufferFullEventFunction · 0.85
clearResourceTimingsMethod · 0.80
SymbolFunction · 0.50
getEntriesByTypeMethod · 0.45

Tested by

no test coverage detected