@@ -903,7 +903,7 @@ it('allow aborting the prompt using signals', async () => {
903903 await expect ( answer ) . rejects . toThrow ( AbortPromptError ) ;
904904} ) ;
905905
906- it ( 'should ignore keypresses buffered before prompt creation' , async ( ) => {
906+ it ( 'should ignore keypresses buffered before prompt creation on a TTY ' , async ( ) => {
907907 const prompt = createPrompt (
908908 ( _config : { message : string } , done : ( value : string ) => void ) => {
909909 useKeypress ( ( key : KeypressEvent ) => {
@@ -917,9 +917,11 @@ it('should ignore keypresses buffered before prompt creation', async () => {
917917 ) ;
918918
919919 // Use PassThrough which has proper stream buffering (like real process.stdin)
920- const input = new PassThrough ( ) ;
920+ const input = Object . assign ( new PassThrough ( ) , { isTTY : true } ) ;
921921 const output = new PassThrough ( ) ;
922922 output . write = ( ) => true ; // suppress output
923+ // On a terminal, keys typed before the prompt started are stale user input
924+ // (see issue #1303): the first render defers one tick and discards them.
923925
924926 // Buffer an Enter keypress BEFORE the prompt exists
925927 input . write ( '\r' ) ;
@@ -938,6 +940,34 @@ it('should ignore keypresses buffered before prompt creation', async () => {
938940 await expect ( answer ) . resolves . toBe ( 'submitted' ) ;
939941} ) ;
940942
943+ it ( 'should consume input piped into non-TTY stdin before the prompt starts' , async ( ) => {
944+ const prompt = createPrompt (
945+ ( _config : { message : string } , done : ( value : string ) => void ) => {
946+ useKeypress ( ( key : KeypressEvent ) => {
947+ if ( isEnterKey ( key ) ) {
948+ done ( 'submitted' ) ;
949+ }
950+ } ) ;
951+
952+ return 'Question?' ;
953+ } ,
954+ ) ;
955+
956+ const input = new PassThrough ( ) ;
957+ const output = new PassThrough ( ) ;
958+ output . write = ( ) => true ; // suppress output
959+
960+ // Piped stdin (no isTTY) is intentional input, e.g. answers written to a
961+ // child process's stdin the moment it is spawned. It must not be dropped
962+ // by the first-render deferral, or the prompt waits forever — the cause
963+ // of the intermittent 30s timeouts in the Deno integration suite.
964+ input . write ( '\r' ) ;
965+
966+ const answer = prompt ( { message : 'test' } , { input, output } ) ;
967+
968+ await expect ( answer ) . resolves . toBe ( 'submitted' ) ;
969+ } ) ;
970+
941971it ( 'fail on aborted signals' , async ( ) => {
942972 const Prompt = ( config : { message : string } , done : ( value : string ) => void ) => {
943973 useKeypress ( ( key : KeypressEvent ) => {
0 commit comments