fix(ext/node): support input option in spawnSync (#28792)

This commit is contained in:
Yoshiya Hinosawa 2025-04-09 13:42:12 +09:00 committed by GitHub
parent 9bc9faff49
commit cb00561e97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 99 additions and 3 deletions

View file

@ -1128,3 +1128,46 @@ Deno.test(async function noWarningsFlag() {
await timeout.promise;
});
Deno.test({
name: "[node/child_process] spawnSync supports input option",
fn() {
const text = " console.log('hello')";
const expected = `console.log("hello");\n`;
{
const { stdout } = spawnSync(Deno.execPath(), ["fmt", "-"], {
input: text,
});
assertEquals(stdout.toString(), expected);
}
{
const { stdout } = spawnSync(Deno.execPath(), ["fmt", "-"], {
input: Buffer.from(text),
});
assertEquals(stdout.toString(), expected);
}
{
const { stdout } = spawnSync(Deno.execPath(), ["fmt", "-"], {
input: new TextEncoder().encode(text),
});
assertEquals(stdout.toString(), expected);
}
{
const { stdout } = spawnSync(Deno.execPath(), ["fmt", "-"], {
input: new DataView(Buffer.from(text).buffer),
});
assertEquals(stdout.toString(), expected);
}
assertThrows(
() => {
spawnSync(Deno.execPath(), ["fmt", "-"], {
// deno-lint-ignore no-explicit-any
input: {} as any,
});
},
Error,
'The "input" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object',
);
},
});