11const path = require ( 'path' ) ;
22const { Parser, fromFile } = require ( '@asyncapi/parser' ) ;
3- const { getClientName, getInfo, getTitle, toSnakeCase } = require ( '@asyncapi/generator-helpers' ) ;
3+ const { getClientName, getInfo, getTitle, toSnakeCase, listFiles } = require ( '@asyncapi/generator-helpers' ) ;
4+ const fs = require ( 'fs/promises' ) ;
45
56const parser = new Parser ( ) ;
67const asyncapi_v3_path = path . resolve ( __dirname , './__fixtures__/asyncapi-websocket-query.yml' ) ;
@@ -153,4 +154,35 @@ describe('toSnakeCase integration test with AsyncAPI', () => {
153154 const expectedOperationId = '' ;
154155 expect ( actualOperationId ) . toBe ( expectedOperationId ) ;
155156 } ) ;
156- } ) ;
157+ } ) ;
158+
159+ jest . mock ( 'fs/promises' ) ;
160+ describe ( 'listFiles' , ( ) => {
161+ afterEach ( ( ) => {
162+ jest . clearAllMocks ( ) ;
163+ } ) ;
164+
165+ it ( 'should return only file names from the directory' , async ( ) => {
166+ const mockDirents = [
167+ { name : 'file1.txt' , isFile : ( ) => true } ,
168+ { name : 'file2.js' , isFile : ( ) => true } ,
169+ { name : 'subdir' , isFile : ( ) => false } ,
170+ ] ;
171+
172+ fs . readdir . mockResolvedValue ( mockDirents ) ;
173+ const mockPath = '/mock/path' ;
174+
175+ const result = await listFiles ( mockPath ) ;
176+ expect ( fs . readdir ) . toHaveBeenCalledWith ( mockPath , { withFileTypes : true } ) ;
177+ expect ( result ) . toEqual ( [ 'file1.txt' , 'file2.js' ] ) ;
178+ } ) ;
179+
180+ it ( 'should return an empty array if no files exist' , async ( ) => {
181+ fs . readdir . mockResolvedValue ( [
182+ { name : 'folder' , isFile : ( ) => false } ,
183+ ] ) ;
184+ const mockPath = '/mock/path' ;
185+ const result = await listFiles ( mockPath ) ;
186+ expect ( result ) . toEqual ( [ ] ) ;
187+ } ) ;
188+ } ) ;
0 commit comments