77import  {  jest  }  from  "@jest/globals" ; 
88import  {  cmdList  }  from  "../list" ; 
99import  *  as  utils  from  "../utils" ; 
10- import  *  as  fs  from  "fs" ; 
11- import  *  as  path  from  "path" ; 
1210import  list  from  "../../list" ; 
1311
1412// Mock dependencies 
@@ -18,10 +16,21 @@ jest.mock("../utils", () => ({
1816    return  message ; 
1917  } ) , 
2018} ) ) ; 
21- jest . mock ( "fs" ) ; 
22- jest . mock ( "path" ) ; 
2319jest . mock ( "../../list" ) ; 
2420
21+ // Create mock functions for fs and path 
22+ const  mockExistsSync  =  jest . fn ( ) ; 
23+ const  mockResolve  =  jest . fn ( ) ; 
24+ 
25+ // Mock fs and path modules 
26+ jest . mock ( "fs" ,  ( )  =>  ( { 
27+   existsSync : mockExistsSync , 
28+ } ) ) ; 
29+ 
30+ jest . mock ( "path" ,  ( )  =>  ( { 
31+   resolve : mockResolve , 
32+ } ) ) ; 
33+ 
2534/** 
2635 * Test suite for the list command 
2736 * Verifies command-line argument handling, help display, validation, 
@@ -30,18 +39,14 @@ jest.mock("../../list");
3039describe ( "cmdList" ,  ( )  =>  { 
3140  // Store original console.log 
3241  const  originalConsoleLog  =  console . log ; 
33-   let  mockExistsSync : jest . SpiedFunction < typeof  fs . existsSync > ; 
34-   let  mockResolve : jest . SpiedFunction < typeof  path . resolve > ; 
3542
3643  beforeEach ( ( )  =>  { 
3744    // Reset all mocks before each test 
3845    jest . clearAllMocks ( ) ; 
3946
40-     // Setup fs.existsSync mock 
41-     mockExistsSync  =  jest . spyOn ( fs ,  "existsSync" ) . mockReturnValue ( true ) ; 
42- 
43-     // Setup path.resolve mock 
44-     mockResolve  =  jest . spyOn ( path ,  "resolve" ) . mockImplementation ( ( ...args )  =>  args . join ( "/" ) ) ; 
47+     // Setup default mock implementations 
48+     mockExistsSync . mockReturnValue ( true ) ; 
49+     mockResolve . mockImplementation ( ( ...args )  =>  args . join ( "/" ) ) ; 
4550
4651    // Mock console.log 
4752    console . log  =  jest . fn ( ) ; 
@@ -50,8 +55,6 @@ describe("cmdList", () => {
5055  afterEach ( ( )  =>  { 
5156    // Restore console.log after each test 
5257    console . log  =  originalConsoleLog ; 
53-     mockExistsSync . mockRestore ( ) ; 
54-     mockResolve . mockRestore ( ) ; 
5558  } ) ; 
5659
5760  afterAll ( ( )  =>  { 
@@ -72,7 +75,7 @@ describe("cmdList", () => {
7275  } ) ; 
7376
7477  /** 
75-    * Verify that the output  directory exists when specified 
78+    * Verify that the out  directory exists when specified 
7679   * The command should exit with an error if the specified directory doesn't exist 
7780   */ 
7881  test ( "validates out directory exists when specified" ,  ( )  =>  { 
@@ -86,27 +89,29 @@ describe("cmdList", () => {
8689
8790  /** 
8891   * Verify that the list function is called with correct parameters 
89-    * Tests the proper parsing and forwarding of output directory argument  
92+    * Tests the proper parsing and forwarding of all command line arguments  
9093   */ 
9194  test ( "calls list with correct parameters" ,  ( )  =>  { 
9295    const  mockList  =  list  as  jest . MockedFunction < typeof  list > ; 
93-     const  outDir  =  " /output/dir"; 
96+     const  args  =  [ "--out-dir" ,   " /output/dir"] ; 
9497
95-     cmdList ( [ "--out-dir" ,   outDir ] ) ; 
98+     cmdList ( args ) ; 
9699
97-     expect ( mockList ) . toHaveBeenCalledWith ( outDir ) ; 
100+     expect ( mockList ) . toHaveBeenCalledWith ( { 
101+       outDir : "/output/dir" , 
102+     } ) ; 
98103  } ) ; 
99104
100105  /** 
101-    * Verify that the list function is called without outDir  when not  specified 
102-    * Tests the default behavior when no  output directory is provided  
106+    * Verify that the list function is called with undefined  when no out-dir is  specified 
107+    * Tests the default behavior for  output directory 
103108   */ 
104109  test ( "calls list with undefined when no out-dir specified" ,  ( )  =>  { 
105110    const  mockList  =  list  as  jest . MockedFunction < typeof  list > ; 
106111
107112    cmdList ( [ ] ) ; 
108113
109-     expect ( mockList ) . toHaveBeenCalledWith ( undefined ) ; 
114+     expect ( mockList ) . toHaveBeenCalledWith ( { } ) ; 
110115  } ) ; 
111116
112117  /** 
0 commit comments