File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -447,6 +447,33 @@ 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 : [ null ] ,
463+ } )
464+ const mockCallback = jest . fn ( )
465+
466+ // @ts -expect-error TypeScript knows proc.stdout should return a Readable
467+ // We overwrite it so that we can get testing coverage for the scenario
468+ // in onLine that would throw an error.
469+ proc . stdout = null
470+
471+ expect ( ( ) => util . onLine ( proc , mockCallback ) ) . toThrowError ( / s t d o u t / )
472+
473+ // Cleanup
474+ proc ?. kill ( )
475+ } )
476+ } )
450477} )
451478
452479describe ( "escapeHtml" , ( ) => {
You can’t perform that action at this time.
0 commit comments