From f5c1ff08e6c67c38043b4c76b5472ad71c93d697 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 2 Jun 2023 17:46:50 +0200 Subject: fix(node): map stdio [0, 1, 2] to "inherit" (#19352) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internally, `node-tap` spawns a child process with `stdio: [0, 1, 2]`. Whilst we don't support passing fd numbers as an argument so far, it turns out that `[0, 1, 2]` is equivalent to `"inherit"` which we already support. See: https://nodejs.org/api/child_process.html#optionsstdio Mapping it to `"inherit"` is fine for us and gets us one step closer in getting `node-tap` working. I'm now at the stage where already the coverage table is shown 🎉 --- cli/tests/unit_node/child_process_test.ts | 22 ++++++++++++++++++++++ .../unit_node/testdata/child_process_stdio_012.js | 15 +++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 cli/tests/unit_node/testdata/child_process_stdio_012.js (limited to 'cli/tests') diff --git a/cli/tests/unit_node/child_process_test.ts b/cli/tests/unit_node/child_process_test.ts index d4a2a4cc6..f8de5b6f6 100644 --- a/cli/tests/unit_node/child_process_test.ts +++ b/cli/tests/unit_node/child_process_test.ts @@ -600,6 +600,28 @@ Deno.test( }, ); +Deno.test( + "[node/child_process spawn] supports stdio [0, 1, 2] option", + async () => { + const cmdFinished = deferred(); + let output = ""; + const script = path.join( + path.dirname(path.fromFileUrl(import.meta.url)), + "testdata", + "child_process_stdio_012.js", + ); + const cp = spawn(Deno.execPath(), ["run", "-A", script]); + cp.stdout?.on("data", (data) => { + output += data; + }); + cp.on("close", () => cmdFinished.resolve()); + await cmdFinished; + + assertStringIncludes(output, "foo"); + assertStringIncludes(output, "close"); + }, +); + Deno.test({ name: "[node/child_process spawn] supports SIGIOT signal", ignore: Deno.build.os === "windows", diff --git a/cli/tests/unit_node/testdata/child_process_stdio_012.js b/cli/tests/unit_node/testdata/child_process_stdio_012.js new file mode 100644 index 000000000..682d8a084 --- /dev/null +++ b/cli/tests/unit_node/testdata/child_process_stdio_012.js @@ -0,0 +1,15 @@ +import childProcess from "node:child_process"; +import process from "node:process"; +import * as path from "node:path"; + +const script = path.join( + path.dirname(path.fromFileUrl(import.meta.url)), + "node_modules", + "foo", + "index.js", +); + +const child = childProcess.spawn(process.execPath, [script], { + stdio: [0, 1, 2], +}); +child.on("close", () => console.log("close")); -- cgit v1.2.3