From 00a5490ecd947ea8e6ad4a02a51fef88b248177a Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Fri, 11 Nov 2016 15:57:18 -0500 Subject: [PATCH] test: increase coverage of process.emitWarning Previously our tests did not check these codepaths as seen at coverage.nodejs.org PR-URL: https://github.com/nodejs/node/pull/9556 Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Anna Henningsen --- test/parallel/test-process-emitwarning.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-process-emitwarning.js b/test/parallel/test-process-emitwarning.js index 33547377bb901b..651bdbd1abc1ed 100644 --- a/test/parallel/test-process-emitwarning.js +++ b/test/parallel/test-process-emitwarning.js @@ -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); @@ -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);