From 65d7420ee795a30f25499beb765c4837a7c6b20e Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 22 Nov 2021 20:18:58 +0000 Subject: [PATCH] feat: add test for onLine throw error (#4542) --- test/unit/node/util.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit/node/util.test.ts b/test/unit/node/util.test.ts index 3a37f4a90..45289229a 100644 --- a/test/unit/node/util.test.ts +++ b/test/unit/node/util.test.ts @@ -447,6 +447,28 @@ describe("onLine", () => { expect(await received).toEqual(expected) }) + + describe("used with a process missing stdout ", () => { + it("should throw an error", async () => { + // Initialize a process that does not have stdout. + // "If the child was spawned with stdio set to anything + // other than 'pipe', then subprocess.stdout will be null." + // Source: https://stackoverflow.com/a/46024006/3015595 + // Other source: https://nodejs.org/api/child_process.html#child_process_subprocess_stdout + // NOTE@jsjoeio - I'm not sure if this actually happens though + // which is why I have to set proc.stdout = null + // a couple lines below. + const proc = cp.spawn("node", [], { + stdio: "ignore", + }) + const mockCallback = jest.fn() + + expect(() => util.onLine(proc, mockCallback)).toThrowError(/stdout/) + + // Cleanup + proc?.kill() + }) + }) }) describe("escapeHtml", () => {