|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | +constdc=require('diagnostics_channel'); |
| 5 | +constassert=require('assert'); |
| 6 | + |
| 7 | +letchannel; |
| 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"argumentmustbeoftypestringoraninstanceofChannelorObject/, |
| 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"propertymustbeaninstanceofChannel/, |
| 34 | +}); |
| 35 | + |
| 36 | +// tracingChannel creating with empty nameOrChannels must throw error |
| 37 | +assert.throws(()=>(channel=dc.tracingChannel({})),{ |
| 38 | +message: /Cannotconvertundefinedornulltoobject/, |
| 39 | +}); |
0 commit comments