@@ -13,7 +13,7 @@ import { describe, it, expect } from "vitest";
1313import * as fs from "node:fs" ;
1414import * as os from "node:os" ;
1515import * as path from "node:path" ;
16- import { fileURLToPath } from "node:url" ;
16+ import { fileURLToPath , pathToFileURL } from "node:url" ;
1717import { spawnSync } from "node:child_process" ;
1818import { execSync } from "node:child_process" ;
1919import { COMMANDS } from "../src/completions.ts" ;
@@ -186,6 +186,26 @@ printf '%s\n' "\${COMPREPLY[@]}"`;
186186 }
187187 } ) ;
188188
189+ it ( "lets piped stdout drain before exiting" , ( ) => {
190+ const delayedStdout = pathToFileURL (
191+ path . join ( __dirname , "fixtures" , "delayed-stdout.mjs" ) ,
192+ ) . href ;
193+ for ( const shell of [ "fish" , "bash" , "zsh" ] ) {
194+ const r = spawnSync (
195+ nodeBin ,
196+ [ "--import" , delayedStdout , cliPath , "completions" , shell ] ,
197+ { encoding : "utf8" } ,
198+ ) ;
199+ const checkedIn = fs . readFileSync (
200+ path . join ( __dirname , ".." , "completions" , `pty.${ shell } ` ) ,
201+ "utf8" ,
202+ ) ;
203+
204+ expect ( r . status , r . stderr ) . toBe ( 0 ) ;
205+ expect ( r . stdout , `${ shell } output was truncated` ) . toBe ( checkedIn ) ;
206+ }
207+ } ) ;
208+
189209 it ( "prints usage and exits non-zero for an unknown shell" , ( ) => {
190210 const r = spawnSync ( nodeBin , [ cliPath , "completions" , "tcsh" ] , {
191211 encoding : "utf8" ,
0 commit comments