summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-11-27 19:54:01 -0500
committerGitHub <noreply@github.com>2023-11-27 19:54:01 -0500
commitd4ef471744650e031fdc0b956e51e55f0f365203 (patch)
treed94fb8cbf2027af4bfc6fc4684ba66b3d1373d8b
parentd65a297943b57f6492909041aadf72323f503f09 (diff)
fix(node): `spawnSync`'s `status` was incorrect (#21359)
The exit code wasn't hooked up properly.
-rw-r--r--cli/tests/node_compat/test/parallel/test-stdin-from-file-spawn.js4
-rw-r--r--cli/tests/unit_node/child_process_test.ts9
-rw-r--r--ext/node/polyfills/internal/child_process.ts2
3 files changed, 12 insertions, 3 deletions
diff --git a/cli/tests/node_compat/test/parallel/test-stdin-from-file-spawn.js b/cli/tests/node_compat/test/parallel/test-stdin-from-file-spawn.js
index 89a0860a3..2f6b41898 100644
--- a/cli/tests/node_compat/test/parallel/test-stdin-from-file-spawn.js
+++ b/cli/tests/node_compat/test/parallel/test-stdin-from-file-spawn.js
@@ -5,7 +5,7 @@
// Taken from Node 18.8.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
-// TODO(cjihrig): 'run -A require.ts' should not be needed in
+// TODO(cjihrig): 'run -A runner.ts' should not be needed in
// execSync() call at the bottom of this test.
'use strict';
@@ -49,4 +49,4 @@ setTimeout(() => {
}, 100);
`);
-execSync(`${process.argv[0]} run -A require.ts ${tmpJsFile} < ${tmpCmdFile}`);
+execSync(`${process.argv[0]} run -A runner.ts ${tmpJsFile} < ${tmpCmdFile}`);
diff --git a/cli/tests/unit_node/child_process_test.ts b/cli/tests/unit_node/child_process_test.ts
index d226319e6..d5d41125d 100644
--- a/cli/tests/unit_node/child_process_test.ts
+++ b/cli/tests/unit_node/child_process_test.ts
@@ -722,3 +722,12 @@ Deno.test(function spawnSyncStdioUndefined() {
assertEquals(ret.stdout.toString("utf-8").trim(), "hello");
assertEquals(ret.stderr.toString("utf-8").trim(), "world");
});
+
+Deno.test(function spawnSyncExitNonZero() {
+ const ret = spawnSync(
+ `"${Deno.execPath()}" eval "Deno.exit(22)"`,
+ { shell: true },
+ );
+
+ assertEquals(ret.status, 22);
+});
diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts
index 1c9aced19..04773a8b7 100644
--- a/ext/node/polyfills/internal/child_process.ts
+++ b/ext/node/polyfills/internal/child_process.ts
@@ -855,7 +855,7 @@ export function spawnSync(
windowsRawArguments: windowsVerbatimArguments,
}).outputSync();
- const status = output.signal ? null : 0;
+ const status = output.signal ? null : output.code;
let stdout = parseSpawnSyncOutputStreams(output, "stdout");
let stderr = parseSpawnSyncOutputStreams(output, "stderr");