From 178fe215a40c8513420823b579f95efd34bf2547 Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Wed, 5 May 2021 20:44:32 +0800 Subject: [PATCH] test: increase coverage for Histogram 1. custom inspect test case Refs: https://coverage.nodejs.org/coverage-18e4f405b14b26f9/lib/internal/histogram.js.html#L56 2. tests that RecordableHistogram is impossible to construct manually Refs: https://coverage.nodejs.org/coverage-18e4f405b14b26f9/lib/internal/histogram.js.html#L132 PR-URL: https://github.com/nodejs/node/pull/38555 Reviewed-By: James M Snell Reviewed-By: Darshan Sen --- test/parallel/test-perf-hooks-histogram.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-perf-hooks-histogram.js b/test/parallel/test-perf-hooks-histogram.js index f8c373bbd4c4b9..323dbeb153633a 100644 --- a/test/parallel/test-perf-hooks-histogram.js +++ b/test/parallel/test-perf-hooks-histogram.js @@ -6,6 +6,7 @@ const { createHistogram, monitorEventLoopDelay, } = require('perf_hooks'); +const { inspect } = require('util'); { const h = createHistogram(); @@ -67,3 +68,18 @@ const { }); setTimeout(() => mc.port2.postMessage(e), 100); } + +{ + const h = createHistogram(); + assert(inspect(h, { depth: null }).startsWith('Histogram')); + assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]'); +} + +{ + // Tests that RecordableHistogram is impossible to construct manually + const h = createHistogram(); + assert.throws( + () => new h.constructor(), + /^TypeError: illegal constructor$/ + ); +}