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 b1c5443

Browse filesBrowse files
cjihrigaduh95
authored andcommitted
test: update test-child-process-bad-stdio to use node:test
This commit updates test/parallel/test-child-process-bad-stdio.js to use node:test. This change prevents multiple child processes from being spawned in parallel, which can be problematic in the CI. PR-URL: #56562 Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 0d772a9 commit b1c5443
Copy full SHA for b1c5443

File tree

Expand file treeCollapse file tree

1 file changed

+16
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-14
lines changed
Open diff view settings
Collapse file
+16-14Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22
// Flags: --expose-internals
33
const common = require('../common');
4-
const assert = require('assert');
5-
const cp = require('child_process');
64

75
if (process.argv[2] === 'child') {
86
setTimeout(() => {}, common.platformTimeout(100));
97
return;
108
}
119

10+
const assert = require('node:assert');
11+
const cp = require('node:child_process');
12+
const { mock, test } = require('node:test');
13+
const { ChildProcess } = require('internal/child_process');
14+
1215
// Monkey patch spawn() to create a child process normally, but destroy the
1316
// stdout and stderr streams. This replicates the conditions where the streams
1417
// cannot be properly created.
15-
const ChildProcess = require('internal/child_process').ChildProcess;
1618
const original = ChildProcess.prototype.spawn;
1719

18-
ChildProcess.prototype.spawn = function() {
20+
mock.method(ChildProcess.prototype, 'spawn', function() {
1921
const err = original.apply(this, arguments);
2022

2123
this.stdout.destroy();
@@ -24,7 +26,7 @@ ChildProcess.prototype.spawn = function() {
2426
this.stderr = null;
2527

2628
return err;
27-
};
29+
});
2830

2931
function createChild(options, callback) {
3032
const [cmd, opts] = common.escapePOSIXShell`"${process.execPath}" "${__filename}" child`;
@@ -33,32 +35,32 @@ function createChild(options, callback) {
3335
return cp.exec(cmd, options, common.mustCall(callback));
3436
}
3537

36-
// Verify that normal execution of a child process is handled.
37-
{
38+
test('normal execution of a child process is handled', (_, done) => {
3839
createChild({}, (err, stdout, stderr) => {
3940
assert.strictEqual(err, null);
4041
assert.strictEqual(stdout, '');
4142
assert.strictEqual(stderr, '');
43+
done();
4244
});
43-
}
45+
});
4446

45-
// Verify that execution with an error event is handled.
46-
{
47+
test('execution with an error event is handled', (_, done) => {
4748
const error = new Error('foo');
4849
const child = createChild({}, (err, stdout, stderr) => {
4950
assert.strictEqual(err, error);
5051
assert.strictEqual(stdout, '');
5152
assert.strictEqual(stderr, '');
53+
done();
5254
});
5355

5456
child.emit('error', error);
55-
}
57+
});
5658

57-
// Verify that execution with a killed process is handled.
58-
{
59+
test('execution with a killed process is handled', (_, done) => {
5960
createChild({ timeout: 1 }, (err, stdout, stderr) => {
6061
assert.strictEqual(err.killed, true);
6162
assert.strictEqual(stdout, '');
6263
assert.strictEqual(stderr, '');
64+
done();
6365
});
64-
}
66+
});

0 commit comments

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