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),
19  end: common.mustCall(check),
20  asyncStart: common.mustNotCall(),
21  asyncEnd: common.mustNotCall(),
22  error: common.mustCall((found) => {
23    check(found);
24    assert.deepStrictEqual(found.error, expectedError);
25  })
26};
27
28channel.subscribe(handlers);
29try {
30  channel.traceSync(function(err) {
31    assert.deepStrictEqual(this, thisArg);
32    assert.strictEqual(err, expectedError);
33    throw err;
34  }, input, thisArg, expectedError);
35
36  throw new Error('It should not reach this error');
37} catch (error) {
38  assert.deepStrictEqual(error, expectedError);
39}
40