Skip to content

Commit b5012f3

Browse files
targosMylesBorins
authored andcommitted
test: add expectWarning to common
There are multiple tests that use the same boilerplate to test that warnings are correctly emitted. This adds a new common function to do that and changes the tests to use it. PR-URL: #8662 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b98813d commit b5012f3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/common.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,17 @@ ArrayStream.prototype.writable = true;
533533
ArrayStream.prototype.pause = function() {};
534534
ArrayStream.prototype.resume = function() {};
535535
ArrayStream.prototype.write = function() {};
536+
537+
exports.expectWarning = function(name, expected) {
538+
if (typeof expected === 'string')
539+
expected = [expected];
540+
process.on('warning', exports.mustCall((warning) => {
541+
assert.strictEqual(warning.name, name);
542+
assert.ok(expected.includes(warning.message),
543+
`unexpected error message: "${warning.message}"`);
544+
// Remove a warning message after it is seen so that we guarantee that we
545+
// get each message only once.
546+
expected.splice(expected.indexOf(warning.message), 1);
547+
}, expected.length));
548+
};
549+

0 commit comments

Comments
 (0)