Skip to content

Commit

Permalink
test: increase coverage of process.emitWarning
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Fishrock123 authored and addaleax committed Nov 22, 2016
1 parent f3db5e4 commit 00a5490
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/parallel/test-process-emitwarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ process.on('warning', common.mustCall((warning) => {
assert(warning);
assert(/^(Warning|CustomWarning)/.test(warning.name));
assert(warning.message, 'A Warning');
}, 3));
}, 7));

process.emitWarning('A Warning');
process.emitWarning('A Warning', 'CustomWarning');
process.emitWarning('A Warning', CustomWarning);
process.emitWarning('A Warning', 'CustomWarning', CustomWarning);

function CustomWarning() {
Error.call(this);
Expand All @@ -24,6 +26,16 @@ function CustomWarning() {
util.inherits(CustomWarning, Error);
process.emitWarning(new CustomWarning());

const warningNoToString = new CustomWarning();
warningNoToString.toString = null;
process.emitWarning(warningNoToString);

const warningThrowToString = new CustomWarning();
warningThrowToString.toString = function() {
throw new Error('invalid toString');
};
process.emitWarning(warningThrowToString);

// TypeError is thrown on invalid output
assert.throws(() => process.emitWarning(1), TypeError);
assert.throws(() => process.emitWarning({}), TypeError);

0 comments on commit 00a5490

Please sign in to comment.