From 3441e1982d906d32cdb2934c50fbe6d1d42f2094 Mon Sep 17 00:00:00 2001 From: Jithil P Ponnan Date: Thu, 19 Oct 2023 17:37:09 +1100 Subject: [PATCH] test: improve code coverage of diagnostics_channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test: improve code coverage of diagnostics_channel PR-URL: https://github.com/nodejs/node/pull/50053 Reviewed-By: Gerhard Stöbich --- ...tics-channel-tracing-channel-args-types.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/parallel/test-diagnostics-channel-tracing-channel-args-types.js diff --git a/test/parallel/test-diagnostics-channel-tracing-channel-args-types.js b/test/parallel/test-diagnostics-channel-tracing-channel-args-types.js new file mode 100644 index 00000000000000..5ae55badc4ac8e --- /dev/null +++ b/test/parallel/test-diagnostics-channel-tracing-channel-args-types.js @@ -0,0 +1,39 @@ +'use strict'; + +require('../common'); +const dc = require('diagnostics_channel'); +const assert = require('assert'); + +let channel; + +// tracingChannel creating with name +channel = dc.tracingChannel('test'); +assert.strictEqual(channel.start.name, 'tracing:test:start'); + +// tracingChannel creating with channels +channel = dc.tracingChannel({ + start: dc.channel('tracing:test:start'), + end: dc.channel('tracing:test:end'), + asyncStart: dc.channel('tracing:test:asyncStart'), + asyncEnd: dc.channel('tracing:test:asyncEnd'), + error: dc.channel('tracing:test:error'), +}); + +// tracingChannel creating without nameOrChannels must throw TypeError +assert.throws(() => (channel = dc.tracingChannel(0)), { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: + /The "nameOrChannels" argument must be of type string or an instance of Channel or Object/, +}); + +// tracingChannel creating without instance of Channel must throw error +assert.throws(() => (channel = dc.tracingChannel({ start: '' })), { + code: 'ERR_INVALID_ARG_TYPE', + message: /The "nameOrChannels\.start" property must be an instance of Channel/, +}); + +// tracingChannel creating with empty nameOrChannels must throw error +assert.throws(() => (channel = dc.tracingChannel({})), { + message: /Cannot convert undefined or null to object/, +});