44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import { vi , describe , it , expect , beforeEach , afterEach } from 'vitest' ;
8- import { coreEvents , type Config } from '@google/gemini-cli-core' ;
7+ import {
8+ vi ,
9+ describe ,
10+ it ,
11+ expect ,
12+ beforeEach ,
13+ afterEach ,
14+ type MockInstance ,
15+ } from 'vitest' ;
16+ import { type Config } from '@google/gemini-cli-core' ;
917import { handleList , listCommand } from './list.js' ;
1018import { loadSettings , type LoadedSettings } from '../../config/settings.js' ;
1119import { loadCliConfig } from '../../config/config.js' ;
@@ -32,12 +40,16 @@ vi.mock('../utils.js', () => ({
3240describe ( 'skills list command' , ( ) => {
3341 const mockLoadSettings = vi . mocked ( loadSettings ) ;
3442 const mockLoadCliConfig = vi . mocked ( loadCliConfig ) ;
43+ let stdoutWriteSpy : MockInstance < typeof process . stdout . write > ;
3544
3645 beforeEach ( async ( ) => {
3746 vi . clearAllMocks ( ) ;
3847 mockLoadSettings . mockReturnValue ( {
3948 merged : { } ,
4049 } as unknown as LoadedSettings ) ;
50+ stdoutWriteSpy = vi
51+ . spyOn ( process . stdout , 'write' )
52+ . mockImplementation ( ( ) => true ) ;
4153 } ) ;
4254
4355 afterEach ( ( ) => {
@@ -56,10 +68,7 @@ describe('skills list command', () => {
5668
5769 await handleList ( { } ) ;
5870
59- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
60- 'log' ,
61- 'No skills discovered.' ,
62- ) ;
71+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith ( 'No skills discovered.\n' ) ;
6372 } ) ;
6473
6574 it ( 'should list all discovered skills' , async ( ) => {
@@ -87,24 +96,19 @@ describe('skills list command', () => {
8796
8897 await handleList ( { } ) ;
8998
90- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
91- 'log' ,
92- chalk . bold ( 'Discovered Agent Skills:' ) ,
99+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
100+ chalk . bold ( 'Discovered Agent Skills:' ) + '\n\n' ,
93101 ) ;
94- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
95- 'log' ,
102+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
96103 expect . stringContaining ( 'skill1' ) ,
97104 ) ;
98- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
99- 'log' ,
105+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
100106 expect . stringContaining ( chalk . green ( '[Enabled]' ) ) ,
101107 ) ;
102- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
103- 'log' ,
108+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
104109 expect . stringContaining ( 'skill2' ) ,
105110 ) ;
106- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
107- 'log' ,
111+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
108112 expect . stringContaining ( chalk . red ( '[Disabled]' ) ) ,
109113 ) ;
110114 } ) ;
@@ -135,29 +139,24 @@ describe('skills list command', () => {
135139
136140 // Default
137141 await handleList ( { all : false } ) ;
138- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
139- 'log' ,
142+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
140143 expect . stringContaining ( 'regular' ) ,
141144 ) ;
142- expect ( coreEvents . emitConsoleLog ) . not . toHaveBeenCalledWith (
143- 'log' ,
145+ expect ( stdoutWriteSpy ) . not . toHaveBeenCalledWith (
144146 expect . stringContaining ( 'builtin' ) ,
145147 ) ;
146148
147149 vi . clearAllMocks ( ) ;
148150
149151 // With all: true
150152 await handleList ( { all : true } ) ;
151- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
152- 'log' ,
153+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
153154 expect . stringContaining ( 'regular' ) ,
154155 ) ;
155- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
156- 'log' ,
156+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
157157 expect . stringContaining ( 'builtin' ) ,
158158 ) ;
159- expect ( coreEvents . emitConsoleLog ) . toHaveBeenCalledWith (
160- 'log' ,
159+ expect ( stdoutWriteSpy ) . toHaveBeenCalledWith (
161160 expect . stringContaining ( chalk . gray ( ' [Built-in]' ) ) ,
162161 ) ;
163162 } ) ;
0 commit comments