@@ -38,16 +38,24 @@ vi.mock('@inquirer/prompts', () => ({
3838} ) ) ;
3939
4040describe ( 'utils' , ( ) => {
41+ const stderrIsTTYDescriptor = Object . getOwnPropertyDescriptor ( process . stderr , 'isTTY' ) ;
42+
4143beforeEach ( ( ) => {
4244vi . clearAllMocks ( ) ;
4345vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
4446vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => {
4547throw new Error ( 'process.exit called' ) ;
4648} ) ;
49+ Object . defineProperty ( process . stderr , 'isTTY' , { value : true , configurable : true } ) ;
4750} ) ;
4851
4952afterEach ( ( ) => {
5053vi . restoreAllMocks ( ) ;
54+ if ( stderrIsTTYDescriptor ) {
55+ Object . defineProperty ( process . stderr , 'isTTY' , stderrIsTTYDescriptor ) ;
56+ } else {
57+ delete process . stderr . isTTY ;
58+ }
5159} ) ;
5260
5361describe ( 'constants' , ( ) => {
@@ -93,7 +101,7 @@ describe('utils', () => {
93101
94102it ( 'should return different messages on multiple calls' , ( ) => {
95103const messages = new Set ( ) ;
96- // Call multiple times to increase chance of getting different messages
104+ // Call repeatedly to increase the chance of getting different messages
97105for ( let i = 0 ; i < 10 ; i ++ ) {
98106messages . add ( getSpinnerProgressMessage ( ) ) ;
99107}
@@ -126,6 +134,16 @@ describe('utils', () => {
126134delete process . env . CI ;
127135} ) ;
128136
137+ it ( 'should run function without spinner when stderr is not a TTY' , async ( ) => {
138+ Object . defineProperty ( process . stderr , 'isTTY' , { value : false , configurable : true } ) ;
139+ const args = { } ;
140+ const result = await runAsyncTool ( args , mockFn ) ;
141+
142+ expect ( result ) . toBe ( 'test result' ) ;
143+ expect ( mockFn ) . toHaveBeenCalledWith ( args ) ;
144+ expect ( ora ) . not . toHaveBeenCalled ( ) ;
145+ } ) ;
146+
129147it ( 'should run function without spinner when start flag is true' , async ( ) => {
130148const args = { start : true } ;
131149const result = await runAsyncTool ( args , mockFn ) ;
0 commit comments