★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/318328f6b7Nouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files
test: improve unexpected warnings error
If someone adds an `expectsWarning` listener without handling all
warning triggered in that test file, it'll result in a cryptic error
message. This improves the situation by providing an explicit error
about the unexpected warning.

PR-URL: #28138
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Jun 17, 2019
1 parent 084ffd8 commit 318328f6b75915c0185d4a4cb89ac3dadc125078
Showing with 9 additions and 1 deletion.
  1. +9 −1 test/common/index.js
@@ -528,7 +528,15 @@ let catchWarning;
function expectWarning(nameOrMap, expected, code) {
if (catchWarning === undefined) {
catchWarning = {};
process.on('warning', (warning) => catchWarning[warning.name](warning));
process.on('warning', (warning) => {
if (!catchWarning[warning.name]) {
throw new TypeError(
`"${warning.name}" was triggered without being expected.\n` +
util.inspect(warning)
);
}
catchWarning[warning.name](warning);
});
}
if (typeof nameOrMap === 'string') {
catchWarning[nameOrMap] = _expectWarning(nameOrMap, expected, code);

0 comments on commit 318328f

Please sign in to comment.