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 75c565b

Browse filesBrowse files
Trotttargos
authored andcommitted
test: improve expectWarning error message
expectWarning() fails with a TypeError and a message about undefined not being iterable when the warning is emitted more times than expected. This change produces a more useful error message. Refs: https://github.com/nodejs/node/pull/41307/files#r775197738 PR-URL: #41326 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent c136d59 commit 75c565b
Copy full SHA for 75c565b

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ function _expectWarning(name, expected, code) {
549549
expected.forEach(([_, code]) => assert(code, expected));
550550
}
551551
return mustCall((warning) => {
552-
const [ message, code ] = expected.shift();
552+
const expectedProperties = expected.shift();
553+
if (!expectedProperties) {
554+
assert.fail(`Unexpected extra warning received: ${warning}`);
555+
}
556+
const [ message, code ] = expectedProperties;
553557
assert.strictEqual(warning.name, name);
554558
if (typeof message === 'string') {
555559
assert.strictEqual(warning.message, message);
Collapse file
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { spawn } = require('child_process');
6+
7+
if (process.argv[2] !== 'child') {
8+
// Expected error not emitted.
9+
{
10+
const child = spawn(
11+
process.execPath, [__filename, 'child', 0], { encoding: 'utf8' }
12+
);
13+
child.on('exit', common.mustCall((status) => {
14+
assert.notStrictEqual(status, 0);
15+
}));
16+
}
17+
18+
// Expected error emitted.
19+
{
20+
const child = spawn(
21+
process.execPath, [__filename, 'child', 1], { encoding: 'utf8' }
22+
);
23+
child.on('exit', common.mustCall((status) => {
24+
assert.strictEqual(status, 0);
25+
}));
26+
}
27+
28+
// Expected error emitted too many times.
29+
{
30+
const child = spawn(
31+
process.execPath, [__filename, 'child', 2], { encoding: 'utf8' }
32+
);
33+
child.stderr.setEncoding('utf8');
34+
35+
let stderr = '';
36+
child.stderr.on('data', (data) => {
37+
stderr += data;
38+
});
39+
child.on('exit', common.mustCall((status) => {
40+
assert.notStrictEqual(status, 0);
41+
assert.match(stderr, /Unexpected extra warning received/);
42+
}));
43+
}
44+
} else {
45+
const iterations = +process.argv[3];
46+
common.expectWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads');
47+
for (let i = 0; i < iterations; i++) {
48+
process.emitWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads');
49+
}
50+
}

0 commit comments

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