aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/child_process/child_process-node.test.js
diff options
context:
space:
mode:
authorGravatar cirospaciari <ciro.spaciari@gmail.com> 2023-05-11 18:16:16 -0300
committerGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-05-13 06:25:02 -0300
commitd6e12c0f1de7194f00aa1e8158ee7a176e4105d2 (patch)
tree1eddd062718d1b37f126fd211f16809c5ca7004c /test/js/node/child_process/child_process-node.test.js
parent7f25aa9e0864e95aad72ee85d475a03aee68bfb4 (diff)
downloadbun-d6e12c0f1de7194f00aa1e8158ee7a176e4105d2.tar.gz
bun-d6e12c0f1de7194f00aa1e8158ee7a176e4105d2.tar.zst
bun-d6e12c0f1de7194f00aa1e8158ee7a176e4105d2.zip
avoid unreacheable and fix tests to not hang
Diffstat (limited to 'test/js/node/child_process/child_process-node.test.js')
-rw-r--r--test/js/node/child_process/child_process-node.test.js34
1 files changed, 13 insertions, 21 deletions
diff --git a/test/js/node/child_process/child_process-node.test.js b/test/js/node/child_process/child_process-node.test.js
index f69b8668f..8fbaaeb0d 100644
--- a/test/js/node/child_process/child_process-node.test.js
+++ b/test/js/node/child_process/child_process-node.test.js
@@ -230,7 +230,6 @@ describe("child_process cwd", () => {
function testCwd(options, { expectPidType, expectCode = 0, expectData }, done = () => {}) {
const createDone = createDoneDotAll(done);
const { mustCall } = createCallCheckCtx(createDone(1500));
- const exitDone = createDone(5000);
const child = spawn(...common.pwdCommand, options);
@@ -244,19 +243,7 @@ describe("child_process cwd", () => {
data += chunk;
});
- // TODO: Test exit events
- // // Can't assert callback, as stayed in to API:
- // // _The 'exit' event may or may not fire after an error has occurred._
- child.on("exit", (code, signal) => {
- try {
- strictEqual(code, expectCode);
- exitDone();
- } catch (err) {
- exitDone(err);
- }
- });
-
- child.on(
+ child.stdout.on(
"close",
mustCall(() => {
expectData && strictEqual(data.trim(), expectData);
@@ -374,9 +361,12 @@ describe("child_process default options", () => {
describe("child_process double pipe", () => {
it("should allow two pipes to be used at once", done => {
- // const { mustCallAtLeast, mustCall } = createCallCheckCtx(done);
- const mustCallAtLeast = fn => fn;
- const mustCall = fn => fn;
+ const createDone = createDoneDotAll(done);
+ const { mustCall, mustCallAtLeast } = createCallCheckCtx(createDone(3000));
+ const sedExitDone = createDone(3000);
+ const echoExitDone = createDone(3000);
+ const grepExitDone = createDone(3000);
+
let grep, sed, echo;
grep = spawn("grep", ["o"], { stdio: ["pipe", "pipe", "pipe"] });
sed = spawn("sed", ["s/o/O/"]);
@@ -386,7 +376,7 @@ describe("child_process double pipe", () => {
grep.stdout.on(
"data",
mustCallAtLeast(data => {
- debug(`grep stdout ${data.length}`);
+ console.log(`grep stdout ${data.length}`);
if (!sed.stdin.write(data)) {
grep.stdout.pause();
}
@@ -435,6 +425,7 @@ describe("child_process double pipe", () => {
"exit",
mustCall(() => {
debug("echo exit");
+ echoExitDone();
}),
);
@@ -442,11 +433,12 @@ describe("child_process double pipe", () => {
"exit",
mustCall(() => {
debug("grep exit");
+ grepExitDone();
}),
);
- sed.on(
- "exit",
+ sed.stdout.on(
+ "close",
mustCall(() => {
debug("sed exit");
}),
@@ -474,7 +466,7 @@ describe("child_process double pipe", () => {
mustCall(() => {
debug("result: " + result);
strictEqual(result, `hellO\nnOde\nwOrld\n`);
- done();
+ sedExitDone();
}),
);
});