Skip to content

Commit d17bf2f

Browse files
cjihrigmarco-ippolito
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 5660b99 commit d17bf2f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed
Lines 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,40 +26,40 @@ ChildProcess.prototype.spawn = function() {
2426
this.stderr = null;
2527

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

2931
function createChild(options, callback) {
3032
const cmd = `"${process.execPath}" "${__filename}" child`;
3133

3234
return cp.exec(cmd, options, common.mustCall(callback));
3335
}
3436

35-
// Verify that normal execution of a child process is handled.
36-
{
37+
test('normal execution of a child process is handled', (_, done) => {
3738
createChild({}, (err, stdout, stderr) => {
3839
assert.strictEqual(err, null);
3940
assert.strictEqual(stdout, '');
4041
assert.strictEqual(stderr, '');
42+
done();
4143
});
42-
}
44+
});
4345

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

5355
child.emit('error', error);
54-
}
56+
});
5557

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy