|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | +const dc = require('diagnostics_channel'); |
| 5 | +const assert = require('assert'); |
| 6 | + |
| 7 | +let channel; |
| 8 | + |
| 9 | +// tracingChannel creating with name |
| 10 | +channel = dc.tracingChannel('test'); |
| 11 | +assert.strictEqual(channel.start.name, 'tracing:test:start'); |
| 12 | + |
| 13 | +// tracingChannel creating with channels |
| 14 | +channel = dc.tracingChannel({ |
| 15 | + start: dc.channel('tracing:test:start'), |
| 16 | + end: dc.channel('tracing:test:end'), |
| 17 | + asyncStart: dc.channel('tracing:test:asyncStart'), |
| 18 | + asyncEnd: dc.channel('tracing:test:asyncEnd'), |
| 19 | + error: dc.channel('tracing:test:error'), |
| 20 | +}); |
| 21 | + |
| 22 | +// tracingChannel creating without nameOrChannels must throw TypeError |
| 23 | +assert.throws(() => (channel = dc.tracingChannel(0)), { |
| 24 | + code: 'ERR_INVALID_ARG_TYPE', |
| 25 | + name: 'TypeError', |
| 26 | + message: |
| 27 | + /The "nameOrChannels" argument must be of type string or an instance of Channel or Object/, |
| 28 | +}); |
| 29 | + |
| 30 | +// tracingChannel creating without instance of Channel must throw error |
| 31 | +assert.throws(() => (channel = dc.tracingChannel({ start: '' })), { |
| 32 | + code: 'ERR_INVALID_ARG_TYPE', |
| 33 | + message: /The "nameOrChannels\.start" property must be an instance of Channel/, |
| 34 | +}); |
| 35 | + |
| 36 | +// tracingChannel creating with empty nameOrChannels must throw error |
| 37 | +assert.throws(() => (channel = dc.tracingChannel({})), { |
| 38 | + message: /Cannot convert undefined or null to object/, |
| 39 | +}); |
0 commit comments