Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 318328f

Browse filesBrowse files
committed
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>
1 parent 084ffd8 commit 318328f
Copy full SHA for 318328f

File tree

Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-1
lines changed
Open diff view settings
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,15 @@ let catchWarning;
528528
function expectWarning(nameOrMap, expected, code) {
529529
if (catchWarning === undefined) {
530530
catchWarning = {};
531-
process.on('warning', (warning) => catchWarning[warning.name](warning));
531+
process.on('warning', (warning) => {
532+
if (!catchWarning[warning.name]) {
533+
throw new TypeError(
534+
`"${warning.name}" was triggered without being expected.\n` +
535+
util.inspect(warning)
536+
);
537+
}
538+
catchWarning[warning.name](warning);
539+
});
532540
}
533541
if (typeof nameOrMap === 'string') {
534542
catchWarning[nameOrMap] = _expectWarning(nameOrMap, expected, code);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.