diff --git a/test/common.js b/test/common.js index a4089183eff727..a72560be77a3a9 100644 --- a/test/common.js +++ b/test/common.js @@ -533,3 +533,17 @@ ArrayStream.prototype.writable = true; ArrayStream.prototype.pause = function() {}; ArrayStream.prototype.resume = function() {}; ArrayStream.prototype.write = function() {}; + +exports.expectWarning = function(name, expected) { + if (typeof expected === 'string') + expected = [expected]; + process.on('warning', exports.mustCall((warning) => { + assert.strictEqual(warning.name, name); + assert.ok(expected.includes(warning.message), + `unexpected error message: "${warning.message}"`); + // Remove a warning message after it is seen so that we guarantee that we + // get each message only once. + expected.splice(expected.indexOf(warning.message), 1); + }, expected.length)); +}; +