From 81a9c7201f66855cdca534dae1a3f53f822a009b Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 2 Jun 2019 22:33:23 -0400 Subject: [PATCH] trace_events: respect inspect() depth This commit causes the Tracing class to account for util.inspect() depth. PR-URL: https://github.com/nodejs/node/pull/28037 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/trace_events.js | 3 +++ test/parallel/test-util-inspect.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/trace_events.js b/lib/trace_events.js index 2b154946d86..0d533c76a78 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -61,6 +61,9 @@ class Tracing { } [customInspectSymbol](depth, opts) { + if (typeof depth === 'number' && depth < 0) + return this; + const obj = { enabled: this.enabled, categories: this.categories diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 834b0c0236a..f9566df48a1 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2519,3 +2519,15 @@ assert.strictEqual( assert(i < 2 || line.startsWith('\u001b[90m')); }); } + +{ + // Tracing class respects inspect depth. + try { + const trace = require('trace_events').createTracing({ categories: ['fo'] }); + const actual = util.inspect({ trace }, { depth: 0 }); + assert.strictEqual(actual, '{ trace: [Tracing] }'); + } catch (err) { + if (err.code !== 'ERR_TRACE_EVENTS_UNAVAILABLE') + throw err; + } +}