From cb259e7147b06dc20e0950c072e7ef2d5af2a12b Mon Sep 17 00:00:00 2001 From: Erik Dunteman Date: Fri, 5 Jul 2024 18:30:30 -0700 Subject: [PATCH] add TS perf_hooks tests --- test/js/node/perf_hooks/perf_hooks.test.ts | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/js/node/perf_hooks/perf_hooks.test.ts b/test/js/node/perf_hooks/perf_hooks.test.ts index 61a75d49b9..57a869c731 100644 --- a/test/js/node/perf_hooks/perf_hooks.test.ts +++ b/test/js/node/perf_hooks/perf_hooks.test.ts @@ -3,7 +3,6 @@ import { test, expect } from "bun:test"; test("stubs", () => { expect(() => perf.monitorEventLoopDelay()).toThrow(); - expect(() => perf.createHistogram()).toThrow(); expect(perf.performance.nodeTiming).toBeObject(); expect(perf.performance.now()).toBeNumber(); @@ -21,4 +20,39 @@ test("doesn't throw", () => { expect(() => performance.getEntriesByType("measure")).not.toThrow(); expect(() => performance.now()).not.toThrow(); expect(() => performance.timeOrigin).not.toThrow(); + expect(() => perf.createHistogram()).not.toThrow(); + expect(() => performance.timerify(() => {})).not.toThrow(); + expect(() => performance.timerify(() => {}, { histogram: perf.createHistogram() })).not.toThrow(); +}); + +test("timerify with histogram", () => { + const histogram = perf.createHistogram({ auto: true }); + const fn = performance.timerify(() => {}, { histogram: histogram }); + expect(histogram.max).toBe(0); // should default to 0 + fn(); + expect(histogram.toJSON()).toBeObject(); + expect(histogram.min).toBeGreaterThan(0); + expect(histogram.max).toBe(histogram.min); // one entry + expect(histogram.percentiles.size).toBe(2); // 0th and 100th + fn(); + expect(histogram.min).toBeGreaterThan(0); + expect(histogram.max).toBeGreaterThan(histogram.min); + expect(histogram.percentiles.size).toBeGreaterThan(2); +}); + +test("nested timerify", () => { + const zeroth = (a, b = 1) => {}; + const first = performance.timerify(zeroth); + const second = performance.timerify(first); + expect(first).not.toBe(second); + expect(second).not.toBe(first); + expect(first.name).toBe("timerified zeroth"); + expect(second.name).toBe("timerified timerified zeroth"); + + // assert.notStrictEqual(n, o); + // assert.notStrictEqual(n, p); + // assert.notStrictEqual(o, p); + // assert.strictEqual(n.length, m.length); + // assert.strictEqual(n.name, "timerified m"); + // assert.strictEqual(p.name, "timerified timerified m"); });