Skip to content

Commit ef90b0f

Browse files
Flarnatargos
authored andcommitted
test: verify tracing channel doesn't swallow unhandledRejection
Add a test to verify that TracingChannel.tracePromise doesn't swallow unhandledRejection events in case no then/catch handler is set by user. PR-URL: #59974 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 7b2032b commit ef90b0f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constdc=require('diagnostics_channel');
5+
constassert=require('assert');
6+
7+
constchannel=dc.tracingChannel('test');
8+
9+
constexpectedError=newError('test');
10+
constinput={foo: 'bar'};
11+
constthisArg={baz: 'buz'};
12+
13+
process.on('unhandledRejection',common.mustCall((reason)=>{
14+
assert.deepStrictEqual(reason,expectedError);
15+
}));
16+
17+
functioncheck(found){
18+
assert.deepStrictEqual(found,input);
19+
}
20+
21+
consthandlers={
22+
start: common.mustCall(check),
23+
end: common.mustCall(check),
24+
asyncStart: common.mustCall(check),
25+
asyncEnd: common.mustCall(check),
26+
error: common.mustCall((found)=>{
27+
check(found);
28+
assert.deepStrictEqual(found.error,expectedError);
29+
})
30+
};
31+
32+
channel.subscribe(handlers);
33+
34+
// Set no then/catch handler to verify unhandledRejection happens
35+
channel.tracePromise(function(value){
36+
assert.deepStrictEqual(this,thisArg);
37+
returnPromise.reject(value);
38+
},input,thisArg,expectedError);

0 commit comments

Comments
 (0)