From 9dd840dff58aff2ac2f0098174a8daee3722cbcd 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 2b154946d86504..0d533c76a78253 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 6646a56294872b..7133cc59acba41 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2497,3 +2497,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; + } +}