Skip to content

Commit 1733ef9

Browse files
tniessenMylesBorins
authored andcommitted
test: make handling of noWarnCode stricter
This change requires all expected warnings to be specified along with their respective code and will raise an error if the code does not match. This also kind of fixes the behavior when the expected warning code was noWarnCode and there is an actual warning code. PR-URL: #21075 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent ba71fe8 commit 1733ef9

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

test/common/index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ exports.isAlive = function isAlive(pid) {
589589
}
590590
};
591591

592-
exports.noWarnCode = 'no_expected_warning_code';
592+
exports.noWarnCode = undefined;
593593

594594
function expectWarning(name, expected) {
595595
const map = new Map(expected);
@@ -598,14 +598,7 @@ function expectWarning(name, expected) {
598598
assert.ok(map.has(warning.message),
599599
`unexpected error message: "${warning.message}"`);
600600
const code = map.get(warning.message);
601-
if (code === undefined) {
602-
throw new Error('An error code must be specified or use ' +
603-
'common.noWarnCode if there is no error code. The error ' +
604-
`code for this warning was ${warning.code}`);
605-
}
606-
if (code !== exports.noWarnCode) {
607-
assert.strictEqual(warning.code, code);
608-
}
601+
assert.strictEqual(warning.code, code);
609602
// Remove a warning message after it is seen so that we guarantee that we
610603
// get each message only once.
611604
map.delete(expected);

test/parallel/test-promises-unhandled-symbol-rejections.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const expectedDeprecationWarning = ['Unhandled promise rejections are ' +
66
'deprecated. In the future, promise ' +
77
'rejections that are not handled will ' +
88
'terminate the Node.js process with a ' +
9-
'non-zero exit code.', common.noWarnCode];
9+
'non-zero exit code.', 'DEP0018'];
1010
const expectedPromiseWarning = ['Unhandled promise rejection. ' +
1111
'This error originated either by throwing ' +
1212
'inside of an async function without a catch ' +

test/parallel/test-util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ assert.strictEqual(util.isFunction(), false);
142142
assert.strictEqual(util.isFunction('string'), false);
143143

144144
common.expectWarning('DeprecationWarning', [
145-
['util.print is deprecated. Use console.log instead.', common.noWarnCode],
146-
['util.puts is deprecated. Use console.log instead.', common.noWarnCode],
147-
['util.debug is deprecated. Use console.error instead.', common.noWarnCode],
148-
['util.error is deprecated. Use console.error instead.', common.noWarnCode]
145+
['util.print is deprecated. Use console.log instead.', 'DEP0026'],
146+
['util.puts is deprecated. Use console.log instead.', 'DEP0027'],
147+
['util.debug is deprecated. Use console.error instead.', 'DEP0028'],
148+
['util.error is deprecated. Use console.error instead.', 'DEP0029']
149149
]);
150150

151151
util.print('test');

0 commit comments

Comments
 (0)