From 58eab0e2b37fd8c3c83445196d4bde419740373d Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 26 Apr 2022 19:00:04 -0400 Subject: fix(test): capture worker stdout and stderr in test output (#14410) --- cli/tests/testdata/test/captured_output.out | 19 ++++++++++++ cli/tests/testdata/test/captured_output.ts | 35 ++++++++++++++++++++++ cli/tests/testdata/test/captured_output.worker.js | 6 ++++ .../testdata/test/captured_subprocess_output.out | 17 ----------- .../testdata/test/captured_subprocess_output.ts | 23 -------------- 5 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 cli/tests/testdata/test/captured_output.out create mode 100644 cli/tests/testdata/test/captured_output.ts create mode 100644 cli/tests/testdata/test/captured_output.worker.js delete mode 100644 cli/tests/testdata/test/captured_subprocess_output.out delete mode 100644 cli/tests/testdata/test/captured_subprocess_output.ts (limited to 'cli/tests/testdata/test') diff --git a/cli/tests/testdata/test/captured_output.out b/cli/tests/testdata/test/captured_output.out new file mode 100644 index 000000000..5ac367561 --- /dev/null +++ b/cli/tests/testdata/test/captured_output.out @@ -0,0 +1,19 @@ +[WILDCARD] +running 1 test from [WILDCARD]/captured_output.ts +output ... +------- output ------- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +----- output end ----- +ok ([WILDCARD]s) + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]s) +[WILDCARD] diff --git a/cli/tests/testdata/test/captured_output.ts b/cli/tests/testdata/test/captured_output.ts new file mode 100644 index 000000000..3710c27b0 --- /dev/null +++ b/cli/tests/testdata/test/captured_output.ts @@ -0,0 +1,35 @@ +Deno.test("output", async () => { + const p = Deno.run({ + cmd: [Deno.execPath(), "eval", "console.log(1); console.error(2);"], + }); + await p.status(); + await p.close(); + Deno.spawnSync(Deno.execPath(), { + args: ["eval", "console.log(3); console.error(4);"], + stdout: "inherit", + stderr: "inherit", + }); + await Deno.spawn(Deno.execPath(), { + args: ["eval", "console.log(5); console.error(6);"], + stdout: "inherit", + stderr: "inherit", + }); + const c = await Deno.spawnChild(Deno.execPath(), { + args: ["eval", "console.log(7); console.error(8);"], + stdout: "inherit", + stderr: "inherit", + }); + await c.status; + const worker = new Worker( + new URL("./captured_output.worker.js", import.meta.url).href, + { type: "module" }, + ); + + // ensure worker output is captured + const response = new Promise((resolve) => + worker.onmessage = () => resolve() + ); + worker.postMessage({}); + await response; + worker.terminate(); +}); diff --git a/cli/tests/testdata/test/captured_output.worker.js b/cli/tests/testdata/test/captured_output.worker.js new file mode 100644 index 000000000..b674bce56 --- /dev/null +++ b/cli/tests/testdata/test/captured_output.worker.js @@ -0,0 +1,6 @@ +self.onmessage = () => { + console.log(9); + console.error(10); + self.postMessage({}); + self.close(); +}; diff --git a/cli/tests/testdata/test/captured_subprocess_output.out b/cli/tests/testdata/test/captured_subprocess_output.out deleted file mode 100644 index 2a40170af..000000000 --- a/cli/tests/testdata/test/captured_subprocess_output.out +++ /dev/null @@ -1,17 +0,0 @@ -[WILDCARD] -running 1 test from [WILDCARD]/captured_subprocess_output.ts -output ... -------- output ------- -1 -2 -3 -4 -5 -6 -7 -8 ------ output end ----- -ok ([WILDCARD]s) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]s) -[WILDCARD] diff --git a/cli/tests/testdata/test/captured_subprocess_output.ts b/cli/tests/testdata/test/captured_subprocess_output.ts deleted file mode 100644 index 277ac340e..000000000 --- a/cli/tests/testdata/test/captured_subprocess_output.ts +++ /dev/null @@ -1,23 +0,0 @@ -Deno.test("output", async () => { - const p = Deno.run({ - cmd: [Deno.execPath(), "eval", "console.log(1); console.error(2);"], - }); - await p.status(); - await p.close(); - Deno.spawnSync(Deno.execPath(), { - args: ["eval", "console.log(3); console.error(4);"], - stdout: "inherit", - stderr: "inherit", - }); - await Deno.spawn(Deno.execPath(), { - args: ["eval", "console.log(5); console.error(6);"], - stdout: "inherit", - stderr: "inherit", - }); - const c = await Deno.spawnChild(Deno.execPath(), { - args: ["eval", "console.log(7); console.error(8);"], - stdout: "inherit", - stderr: "inherit", - }); - await c.status; -}); -- cgit v1.2.3