Skip to content

Commit 65d7420

Browse files
authored
feat: add test for onLine throw error (#4542)
1 parent 0bc9698 commit 65d7420

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/unit/node/util.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,28 @@ describe("onLine", () => {
447447

448448
expect(await received).toEqual(expected)
449449
})
450+
451+
describe("used with a process missing stdout ", () => {
452+
it("should throw an error", async () => {
453+
// Initialize a process that does not have stdout.
454+
// "If the child was spawned with stdio set to anything
455+
// other than 'pipe', then subprocess.stdout will be null."
456+
// Source: https://stackoverflow.com/a/46024006/3015595
457+
// Other source: https://nodejs.org/api/child_process.html#child_process_subprocess_stdout
458+
// NOTE@jsjoeio - I'm not sure if this actually happens though
459+
// which is why I have to set proc.stdout = null
460+
// a couple lines below.
461+
const proc = cp.spawn("node", [], {
462+
stdio: "ignore",
463+
})
464+
const mockCallback = jest.fn()
465+
466+
expect(() => util.onLine(proc, mockCallback)).toThrowError(/stdout/)
467+
468+
// Cleanup
469+
proc?.kill()
470+
})
471+
})
450472
})
451473

452474
describe("escapeHtml", () => {

0 commit comments

Comments
 (0)