@@ -37,13 +37,31 @@ const mockDocxParseFile = vi.fn().mockResolvedValue({
3737 } ,
3838} )
3939
40+ const mockTxtParseFile = vi . fn ( ) . mockResolvedValue ( {
41+ content : 'Parsed TXT content' ,
42+ metadata : {
43+ characterCount : 100 ,
44+ tokenCount : 10 ,
45+ } ,
46+ } )
47+
48+ const mockMdParseFile = vi . fn ( ) . mockResolvedValue ( {
49+ content : 'Parsed MD content' ,
50+ metadata : {
51+ characterCount : 100 ,
52+ tokenCount : 10 ,
53+ } ,
54+ } )
55+
4056// Create mock module implementation
4157const createMockModule = ( ) => {
4258 // Create mock parsers
4359 const mockParsers : Record < string , FileParser > = {
4460 pdf : { parseFile : mockPdfParseFile } ,
4561 csv : { parseFile : mockCsvParseFile } ,
4662 docx : { parseFile : mockDocxParseFile } ,
63+ txt : { parseFile : mockTxtParseFile } ,
64+ md : { parseFile : mockMdParseFile } ,
4765 }
4866
4967 // Create the mock module implementation
@@ -122,6 +140,18 @@ describe('File Parsers', () => {
122140 } ) ) ,
123141 } ) )
124142
143+ vi . doMock ( './txt-parser' , ( ) => ( {
144+ TxtParser : vi . fn ( ) . mockImplementation ( ( ) => ( {
145+ parseFile : mockTxtParseFile ,
146+ } ) ) ,
147+ } ) )
148+
149+ vi . doMock ( './md-parser' , ( ) => ( {
150+ MdParser : vi . fn ( ) . mockImplementation ( ( ) => ( {
151+ parseFile : mockMdParseFile ,
152+ } ) ) ,
153+ } ) )
154+
125155 // Silence console output during tests
126156 global . console = {
127157 ...console ,
@@ -211,6 +241,40 @@ describe('File Parsers', () => {
211241 expect ( result ) . toEqual ( expectedResult )
212242 } )
213243
244+ it ( 'should parse TXT files successfully' , async ( ) => {
245+ const expectedResult = {
246+ content : 'Parsed TXT content' ,
247+ metadata : {
248+ characterCount : 100 ,
249+ tokenCount : 10 ,
250+ } ,
251+ }
252+
253+ mockTxtParseFile . mockResolvedValueOnce ( expectedResult )
254+ mockExistsSync . mockReturnValue ( true )
255+
256+ const { parseFile } = await import ( './index' )
257+ const result = await parseFile ( '/test/files/document.txt' )
258+
259+ expect ( result ) . toEqual ( expectedResult )
260+ } )
261+
262+ it ( 'should parse MD files successfully' , async ( ) => {
263+ const expectedResult = {
264+ content : 'Parsed MD content' ,
265+ metadata : {
266+ characterCount : 100 ,
267+ tokenCount : 10 ,
268+ } ,
269+ }
270+
271+ mockMdParseFile . mockResolvedValueOnce ( expectedResult )
272+ mockExistsSync . mockReturnValue ( true )
273+
274+ const { parseFile } = await import ( './index' )
275+ const result = await parseFile ( '/test/files/document.md' )
276+ } )
277+
214278 it ( 'should throw error for unsupported file types' , async ( ) => {
215279 // Make sure the file "exists" for this test
216280 mockExistsSync . mockReturnValue ( true )
@@ -240,13 +304,14 @@ describe('File Parsers', () => {
240304 expect ( isSupportedFileType ( 'pdf' ) ) . toBe ( true )
241305 expect ( isSupportedFileType ( 'csv' ) ) . toBe ( true )
242306 expect ( isSupportedFileType ( 'docx' ) ) . toBe ( true )
307+ expect ( isSupportedFileType ( 'txt' ) ) . toBe ( true )
308+ expect ( isSupportedFileType ( 'md' ) ) . toBe ( true )
243309 } )
244310
245311 it ( 'should return false for unsupported file types' , async ( ) => {
246312 const { isSupportedFileType } = await import ( './index' )
247313
248314 expect ( isSupportedFileType ( 'png' ) ) . toBe ( false )
249- expect ( isSupportedFileType ( 'txt' ) ) . toBe ( false )
250315 expect ( isSupportedFileType ( 'unknown' ) ) . toBe ( false )
251316 } )
252317
@@ -255,6 +320,8 @@ describe('File Parsers', () => {
255320
256321 expect ( isSupportedFileType ( 'PDF' ) ) . toBe ( true )
257322 expect ( isSupportedFileType ( 'CSV' ) ) . toBe ( true )
323+ expect ( isSupportedFileType ( 'TXT' ) ) . toBe ( true )
324+ expect ( isSupportedFileType ( 'MD' ) ) . toBe ( true )
258325 } )
259326
260327 it ( 'should handle errors gracefully' , async ( ) => {
0 commit comments