@@ -72,8 +72,14 @@ const mockDiskSpace = (available: number) => {
7272 ] ) ;
7373} ;
7474
75- const mockFileSystem = ( { exists = true , writable = true } = { } ) => {
75+ const mockFileSystem = ( { exists = true , writable = true , isDirectory = false , contentLength = 0 } = { } ) => {
7676 vi . mocked ( fs . existsSync ) . mockReturnValue ( exists ) ;
77+ vi . mocked ( fs . statSync ) . mockReturnValue ( {
78+ isDirectory : ( ) => isDirectory ,
79+ } as unknown as fs . Stats ) ;
80+ vi . mocked ( fs . readdirSync ) . mockReturnValue (
81+ Array . from ( { length : contentLength } , ( ) => ( { name : 'mock-file' } ) as fs . Dirent )
82+ ) ;
7783 if ( writable ) {
7884 vi . mocked ( fs . accessSync ) . mockReturnValue ( ) ;
7985 } else {
@@ -126,6 +132,18 @@ describe('PathHandlers', () => {
126132 } ) ;
127133 } ) ;
128134
135+ it ( 'does not exist if directory is empty' , async ( ) => {
136+ mockFileSystem ( { exists : true , writable : true , contentLength : 0 , isDirectory : true } ) ;
137+
138+ const result = await validateHandler ( { } , '/valid/path' ) ;
139+ expect ( result ) . toEqual ( {
140+ isValid : true ,
141+ exists : false ,
142+ freeSpace : DEFAULT_FREE_SPACE ,
143+ requiredSpace : REQUIRED_SPACE ,
144+ } ) ;
145+ } ) ;
146+
129147 it ( 'rejects path with insufficient disk space' , async ( ) => {
130148 mockFileSystem ( { exists : true , writable : true } ) ;
131149 mockDiskSpace ( LOW_FREE_SPACE ) ;
@@ -152,7 +170,7 @@ describe('PathHandlers', () => {
152170 } ) ;
153171
154172 it ( 'rejects non-writable path' , async ( ) => {
155- mockFileSystem ( { exists : true , writable : false } ) ;
173+ mockFileSystem ( { exists : true , writable : false , isDirectory : true , contentLength : 1 } ) ;
156174
157175 const result = await validateHandler ( { } , '/non/writable/path' ) ;
158176 expect ( result ) . toEqual ( {
0 commit comments