Skip to content

Commit 00a5490

Browse files
Fishrock123addaleax
authored andcommitted
test: increase coverage of process.emitWarning
Previously our tests did not check these codepaths as seen at coverage.nodejs.org PR-URL: #9556 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f3db5e4 commit 00a5490

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/parallel/test-process-emitwarning.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ process.on('warning', common.mustCall((warning) => {
1010
assert(warning);
1111
assert(/^(Warning|CustomWarning)/.test(warning.name));
1212
assert(warning.message, 'A Warning');
13-
}, 3));
13+
}, 7));
1414

1515
process.emitWarning('A Warning');
1616
process.emitWarning('A Warning', 'CustomWarning');
17+
process.emitWarning('A Warning', CustomWarning);
18+
process.emitWarning('A Warning', 'CustomWarning', CustomWarning);
1719

1820
function CustomWarning() {
1921
Error.call(this);
@@ -24,6 +26,16 @@ function CustomWarning() {
2426
util.inherits(CustomWarning, Error);
2527
process.emitWarning(new CustomWarning());
2628

29+
const warningNoToString = new CustomWarning();
30+
warningNoToString.toString = null;
31+
process.emitWarning(warningNoToString);
32+
33+
const warningThrowToString = new CustomWarning();
34+
warningThrowToString.toString = function() {
35+
throw new Error('invalid toString');
36+
};
37+
process.emitWarning(warningThrowToString);
38+
2739
// TypeError is thrown on invalid output
2840
assert.throws(() => process.emitWarning(1), TypeError);
2941
assert.throws(() => process.emitWarning({}), TypeError);

0 commit comments

Comments
 (0)