@@ -38,14 +38,18 @@ describe('setupShortcuts', () => {
3838vi . clearAllMocks ( )
3939} )
4040
41- function setup ( context : Partial < ShortcutContext > = { } , { isTTY = true , isRaw = false } = { } ) {
41+ function setup ( context : Partial < ShortcutContext > = { } , { isTTY = true , isRaw = false , stdoutIsTTY = true } = { } ) {
4242const stdin = new PassThrough ( ) as unknown as typeof process . stdin
4343Object . assign ( stdin , { isTTY, isRaw, setRawMode : vi . fn ( ( raw : boolean ) => Object . assign ( stdin , { isRaw : raw } ) ) } )
4444
4545const original = process . stdin
4646Object . defineProperty ( process , 'stdin' , { value : stdin , configurable : true } )
4747restores . push ( ( ) => Object . defineProperty ( process , 'stdin' , { value : original , configurable : true } ) )
4848
49+ const originalStdoutIsTTY = process . stdout . isTTY
50+ Object . defineProperty ( process . stdout , 'isTTY' , { value : stdoutIsTTY , configurable : true } )
51+ restores . push ( ( ) => Object . defineProperty ( process . stdout , 'isTTY' , { value : originalStdoutIsTTY , configurable : true } ) )
52+
4953const log = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
5054
5155const listener = {
@@ -89,10 +93,16 @@ describe('setupShortcuts', () => {
8993expect ( setup ( ) . stdin . listenerCount ( 'data' ) ) . toBe ( 0 )
9094} )
9195
92- it ( 'should suggest `nuxt curl` when there is no TTY ' , ( ) => {
96+ it ( 'should suggest `nuxt curl` when stdin cannot be read ' , ( ) => {
9397const { log } = setup ( { } , { isTTY : false } )
9498
95- expect ( log . mock . calls . join ( '\n' ) ) . toContain ( 'nuxt curl /api/hello' )
99+ expect ( log . mock . calls . join ( '\n' ) ) . toContain ( 'nuxt curl /' )
100+ } )
101+
102+ it ( 'should stay silent when the output is redirected' , ( ) => {
103+ const { log } = setup ( { } , { isTTY : false , stdoutIsTTY : false } )
104+
105+ expect ( log . mock . calls . join ( '\n' ) ) . not . toContain ( 'nuxt curl' )
96106} )
97107
98108it ( 'should stay silent in CI' , ( ) => {
0 commit comments