1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00
denoland-deno/cli/tests/testdata/test/captured_output.ts
Bartek Iwańczuk 4d07ed0efa
chore: rewrite tests and utils to use Deno.Command API (#16895)
Since "Deno.spawn()", "Deno.spawnSync()" and "Deno.spawnChild"
are getting deprecated, this commits rewrites all tests and utilities to
use "Deno.Command" API instead.
2022-12-02 14:43:17 +01:00

35 lines
997 B
TypeScript

Deno.test("output", async () => {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "console.log(0); console.error(1);"],
});
await p.status();
await p.close();
new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(2); console.error(3);"],
stdout: "inherit",
stderr: "inherit",
}).outputSync();
await new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(4); console.error(5);"],
stdout: "inherit",
stderr: "inherit",
}).output();
const c = new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(6); console.error(7);"],
stdout: "inherit",
stderr: "inherit",
}).spawn();
await c.status;
const worker = new Worker(
import.meta.resolve("./captured_output.worker.js"),
{ type: "module" },
);
// ensure worker output is captured
const response = new Promise<void>((resolve) =>
worker.onmessage = () => resolve()
);
worker.postMessage({});
await response;
worker.terminate();
});