GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: improve expectWarning error message · nodejs/node@75c565b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test
    • common
      • index.js
    • parallel
      • test-common-expect-warning.js
Expand file treeCollapse file tree
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

‎test/parallel/test-common-expect-warning.js‎

Copy file name to clipboard
+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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.