diff options
author | James M Snell <jasnell@gmail.com> | 2016-12-04 09:30:53 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-01-30 11:09:38 -0800 |
commit | 5e1f32fd94f53acbec6c5f6eb4d2de5fdef2cd67 (patch) | |
tree | 21062feedeb533996e65bf1944bd55765f386de3 /test/parallel/test-process-emitwarning.js | |
parent | 60d77bd514d3dc65cfbb64ebb8ae1f364e8bf8eb (diff) | |
download | android-node-v8-5e1f32fd94f53acbec6c5f6eb4d2de5fdef2cd67.tar.gz android-node-v8-5e1f32fd94f53acbec6c5f6eb4d2de5fdef2cd67.tar.bz2 android-node-v8-5e1f32fd94f53acbec6c5f6eb4d2de5fdef2cd67.zip |
process: add optional code to warnings + type checking
Add the ability to assign an optional code to process warnings +
add additional type checking to ensure that names and codes can
only be strings.
PR-URL: https://github.com/nodejs/node/pull/10116
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Diffstat (limited to 'test/parallel/test-process-emitwarning.js')
-rw-r--r-- | test/parallel/test-process-emitwarning.js | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/test/parallel/test-process-emitwarning.js b/test/parallel/test-process-emitwarning.js index 651bdbd1ab..b749100001 100644 --- a/test/parallel/test-process-emitwarning.js +++ b/test/parallel/test-process-emitwarning.js @@ -9,18 +9,21 @@ const util = require('util'); process.on('warning', common.mustCall((warning) => { assert(warning); assert(/^(Warning|CustomWarning)/.test(warning.name)); - assert(warning.message, 'A Warning'); -}, 7)); + assert.strictEqual(warning.message, 'A Warning'); + if (warning.code) assert.strictEqual(warning.code, 'CODE001'); +}, 8)); process.emitWarning('A Warning'); process.emitWarning('A Warning', 'CustomWarning'); process.emitWarning('A Warning', CustomWarning); process.emitWarning('A Warning', 'CustomWarning', CustomWarning); +process.emitWarning('A Warning', 'CustomWarning', 'CODE001'); function CustomWarning() { Error.call(this); this.name = 'CustomWarning'; this.message = 'A Warning'; + this.code = 'CODE001'; Error.captureStackTrace(this, CustomWarning); } util.inherits(CustomWarning, Error); @@ -36,6 +39,16 @@ warningThrowToString.toString = function() { }; process.emitWarning(warningThrowToString); -// TypeError is thrown on invalid output +// TypeError is thrown on invalid input assert.throws(() => process.emitWarning(1), TypeError); assert.throws(() => process.emitWarning({}), TypeError); +assert.throws(() => process.emitWarning(true), TypeError); +assert.throws(() => process.emitWarning([]), TypeError); +assert.throws(() => process.emitWarning('', {}), TypeError); +assert.throws(() => process.emitWarning('', '', {}), TypeError); +assert.throws(() => process.emitWarning('', 1), TypeError); +assert.throws(() => process.emitWarning('', '', 1), TypeError); +assert.throws(() => process.emitWarning('', true), TypeError); +assert.throws(() => process.emitWarning('', '', true), TypeError); +assert.throws(() => process.emitWarning('', []), TypeError); +assert.throws(() => process.emitWarning('', '', []), TypeError); |