@@ -12,6 +12,7 @@ import { config } from '../../services/Config.js'
1212import type { LeonInstanceOptions } from '../../services/LeonInstance.js'
1313import { LeonInstance } from '../../services/LeonInstance.js'
1414import { Log } from '../../services/Log.js'
15+ import { isExistingPath } from '../../utils/isExistingPath.js'
1516
1617const leonInstanceOptions : LeonInstanceOptions = {
1718 name : 'random-name' ,
@@ -57,32 +58,56 @@ await tap.test('leon info', async (t) => {
5758 const exitCode = await command . execute ( )
5859 t . equal ( exitCode , 0 )
5960 t . equal ( consoleLogSpy . calledWith ( chalk . cyan ( '\nLeon instances:\n' ) ) , true )
61+ let infoResult = table ( [
62+ [ chalk . bold ( 'Name' ) , leonInstance . name ] ,
63+ [ chalk . bold ( 'Path' ) , leonInstance . path ] ,
64+ [ chalk . bold ( 'Mode' ) , leonInstance . mode ] ,
65+ [ chalk . bold ( 'Birth date' ) , birthDayString ] ,
66+ [ chalk . bold ( 'Version' ) , version ]
67+ ] )
68+ infoResult += '\n------------------------------\n\n'
69+ t . equal ( consoleLogSpy . calledWith ( infoResult ) , true )
70+ }
71+ )
72+
73+ await t . test (
74+ 'should succeeds and advise the user to create an instance' ,
75+ async ( t ) => {
76+ sinon . stub ( console , 'log' ) . value ( ( ) => { } )
77+ const consoleLogSpy = sinon . spy ( console , 'log' )
78+ fsMock ( {
79+ [ config . path ] : JSON . stringify ( { instances : [ ] } )
80+ } )
81+ const command = cli . process ( [ 'info' ] )
82+ const exitCode = await command . execute ( )
83+ t . equal ( exitCode , 0 )
84+ t . equal (
85+ consoleLogSpy . calledWith ( chalk . bold ( 'No Leon instances found.' ) ) ,
86+ true
87+ )
6088 t . equal (
6189 consoleLogSpy . calledWith (
62- table ( [
63- [ chalk . bold ( 'Name' ) , leonInstance . name ] ,
64- [ chalk . bold ( 'Path' ) , leonInstance . path ] ,
65- [ chalk . bold ( 'Mode' ) , leonInstance . mode ] ,
66- [ chalk . bold ( 'Birth date' ) , birthDayString ] ,
67- [ chalk . bold ( 'Version' ) , version ]
68- ] )
90+ 'You can give birth to a Leon instance using:'
6991 ) ,
7092 true
7193 )
94+ t . equal ( consoleLogSpy . calledWith ( chalk . cyan ( 'leon create birth' ) ) , true )
7295 }
7396 )
7497
7598 await t . test (
76- 'should succeeds and advise the user to create an instance' ,
99+ 'should succeeds and advise the user to create an instance with instance path not found ' ,
77100 async ( t ) => {
78101 sinon . stub ( console , 'log' ) . value ( ( ) => { } )
79102 const consoleLogSpy = sinon . spy ( console , 'log' )
80103 fsMock ( {
81- [ config . path ] : JSON . stringify ( { instances : [ ] } )
104+ [ config . path ] : JSON . stringify ( configData )
82105 } )
83106 const command = cli . process ( [ 'info' ] )
84107 const exitCode = await command . execute ( )
85108 t . equal ( exitCode , 0 )
109+ t . equal ( await isExistingPath ( leonInstance . path ) , false )
110+ t . strictSame ( config . get ( 'instances' , [ ] ) , [ ] )
86111 t . equal (
87112 consoleLogSpy . calledWith ( chalk . bold ( 'No Leon instances found.' ) ) ,
88113 true
@@ -110,18 +135,15 @@ await tap.test('leon info', async (t) => {
110135 const exitCode = await command . execute ( )
111136 t . equal ( exitCode , 0 )
112137 t . equal ( consoleLogSpy . calledWith ( chalk . cyan ( '\nLeon instances:\n' ) ) , true )
113- t . equal (
114- consoleLogSpy . calledWith (
115- table ( [
116- [ chalk . bold ( 'Name' ) , leonInstance . name ] ,
117- [ chalk . bold ( 'Path' ) , `${ leonInstance . path } ` ] ,
118- [ chalk . bold ( 'Mode' ) , leonInstance . mode ] ,
119- [ chalk . bold ( 'Birth date' ) , birthDayString ] ,
120- [ chalk . bold ( 'Version' ) , '0.0.0' ]
121- ] )
122- ) ,
123- true
124- )
138+ let infoResult = table ( [
139+ [ chalk . bold ( 'Name' ) , leonInstance . name ] ,
140+ [ chalk . bold ( 'Path' ) , leonInstance . path ] ,
141+ [ chalk . bold ( 'Mode' ) , leonInstance . mode ] ,
142+ [ chalk . bold ( 'Birth date' ) , birthDayString ] ,
143+ [ chalk . bold ( 'Version' ) , '0.0.0' ]
144+ ] )
145+ infoResult += '\n------------------------------\n\n'
146+ t . equal ( consoleLogSpy . calledWith ( infoResult ) , true )
125147 }
126148 )
127149
0 commit comments