1'use strict'; 2 3const common = require('../common'); 4const dc = require('diagnostics_channel'); 5const assert = require('assert'); 6 7const channel = dc.tracingChannel('test'); 8 9const expectedError = new Error('test'); 10const input = { foo: 'bar' }; 11const thisArg = { baz: 'buz' }; 12 13function check(found) { 14 assert.deepStrictEqual(found, input); 15} 16 17const handlers = { 18 start: common.mustCall(check, 2), 19 end: common.mustCall(check, 2), 20 asyncStart: common.mustCall(check, 2), 21 asyncEnd: common.mustCall(check, 2), 22 error: common.mustCall((found) => { 23 check(found); 24 assert.deepStrictEqual(found.error, expectedError); 25 }, 2) 26}; 27 28channel.subscribe(handlers); 29 30channel.traceCallback(function(cb, err) { 31 assert.deepStrictEqual(this, thisArg); 32 setImmediate(cb, err); 33}, 0, input, thisArg, common.mustCall((err, res) => { 34 assert.strictEqual(err, expectedError); 35 assert.strictEqual(res, undefined); 36}), expectedError); 37 38channel.tracePromise(function(value) { 39 assert.deepStrictEqual(this, thisArg); 40 return Promise.reject(value); 41}, input, thisArg, expectedError).then( 42 common.mustNotCall(), 43 common.mustCall((value) => { 44 assert.deepStrictEqual(value, expectedError); 45 }) 46); 47