import { mockProcessExit , mockProcessStderr , mockProcessStdout } from 'jest-mock-process' ; import { Listr } from '@root/index' ; describe ( 'fallback renderer' , ( ) => { let mockExit ; let mockStdout ; let mockStderr ; process . stdout . isTTY = true ; beforeEach ( async ( ) => { mockExit = mockProcessExit ( ) ; mockStdout = mockProcessStdout ( ) ; mockStderr = mockProcessStderr ( ) ; } ) ; afterEach ( async ( ) => { mockExit . mockRestore ( ) ; mockStdout . mockRestore ( ) ; mockStderr . mockRestore ( ) ; jest . clearAllMocks ( ) ; } ) ; it ( 'should fallback renderer with function' , async ( ) => { const task = new Listr ( [ { title : 'This task will execute.' , task : async ( ) : Promise < void > => { } , options : { persistentOutput : true } } ] , { concurrent : false , renderer : 'default' , nonTTYRenderer : 'verbose' , ctx : { test : true } , rendererFallback : ( ) : boolean => 3 > 0 } ) ; expect ( task . rendererClass . name ) . toMatchInlineSnapshot ( '"VerboseRenderer"' ) ; } ) ; it ( 'should fallback renderer with boolean' , async ( ) => { const task = new Listr ( [ { title : 'This task will execute.' , task : async ( ) : Promise < void > => { } , options : { persistentOutput : true } } ] , { concurrent : false , renderer : 'default' , nonTTYRenderer : 'verbose' , ctx : { test : true } , rendererFallback : true } ) ; expect ( task . rendererClass . name ) . toMatchInlineSnapshot ( '"VerboseRenderer"' ) ; } ) ; it ( 'should be silent renderer with function' , async ( ) => { const task = new Listr ( [ { title : 'This task will execute.' , task : async ( ) : Promise < void > => { } , options : { persistentOutput : true } } ] , { concurrent : false , renderer : 'default' , nonTTYRenderer : 'verbose' , ctx : { test : true } , rendererSilent : ( ) : boolean => 3 > 0 } ) ; expect ( task . rendererClass . name ) . toMatchInlineSnapshot ( '"SilentRenderer"' ) ; } ) ; it ( 'should be silent renderer with boolean' , async ( ) => { const task = new Listr ( [ { title : 'This task will execute.' , task : async ( ) : Promise < void > => { } , options : { persistentOutput : true } } ] , { concurrent : false , renderer : 'default' , nonTTYRenderer : 'verbose' , ctx : { test : true } , rendererSilent : true } ) ; expect ( task . rendererClass . name ) . toMatchInlineSnapshot ( '"SilentRenderer"' ) ; } ) ; } ) ;