mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): support input option in spawnSync (#28792)
This commit is contained in:
parent
9bc9faff49
commit
cb00561e97
4 changed files with 99 additions and 3 deletions
|
@ -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',
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue