@@ -5,18 +5,15 @@ import { FileRendererAdapter } from '../renderer/file-renderer.adapter.js';
55import { MarkdownFormatterAdapter } from '../formatter/markdown/markdown-formatter.adapter.js' ;
66import { MarkdownTableGenerator } from '../formatter/markdown/markdown-table.generator.js' ;
77import { SectionIdentifier } from '../generator/section-generator.adapter.js' ;
8- import { readableToBuffer } from './reader.adapter.js' ;
9- import { existsSync } from 'node:fs' ;
8+ import { readableToBuffer , readableToString } from './reader.adapter.js' ;
109
1110describe ( 'ReaderAdapter Integration' , ( ) => {
1211 let readerAdapter : FileReaderAdapter ;
13- let rendererService : RendererService ;
1412 let rendererAdapter : FileRendererAdapter ;
1513 let formatterAdapter : MarkdownFormatterAdapter ;
1614
1715 beforeEach ( ( ) => {
1816 readerAdapter = new FileReaderAdapter ( ) ;
19- rendererService = new RendererService ( readerAdapter ) ;
2017 rendererAdapter = new FileRendererAdapter ( ) ;
2118 formatterAdapter = new MarkdownFormatterAdapter ( new MarkdownTableGenerator ( ) ) ;
2219 } ) ;
@@ -42,10 +39,6 @@ describe('ReaderAdapter Integration', () => {
4239 // Verify reading works
4340 expect ( readBuffer . toString ( ) ) . toBe ( existingContent ) ;
4441
45- // Act: Use RendererService to read content (the new way migrations work)
46- const serviceBuffer = await rendererService . readExistingContent ( '/test/document.md' ) ;
47- expect ( serviceBuffer . toString ( ) ) . toBe ( existingContent ) ;
48-
4942 // Act: Write new content using RendererAdapter (existing pattern)
5043 await rendererAdapter . initialize ( '/test/document.md' , formatterAdapter ) ;
5144 const formattedSection = formatterAdapter . section ( SectionIdentifier . Overview , Buffer . from ( newSectionContent ) ) ;
@@ -66,33 +59,45 @@ describe('ReaderAdapter Integration', () => {
6659 // Arrange
6760 mockFs ( { } ) ;
6861
69- // Act & Assert: RendererService should return empty buffer for non-existent files
70- const buffer = await rendererService . readExistingContent ( '/test/nonexistent.md' ) ;
71- expect ( buffer . length ) . toBe ( 0 ) ;
72-
7362 // Act & Assert: ReaderAdapter should let the stream handle the error
7463 const stream = await readerAdapter . getContent ( '/test/nonexistent.md' ) ;
7564 await expect ( readableToBuffer ( stream ) ) . rejects . toThrow ( ) ;
7665 } ) ;
7766
78- it ( 'should maintain consistency between old Buffer-based processing and new stream-based reading ' , async ( ) => {
67+ it ( 'should read content consistently using ReaderAdapter ' , async ( ) => {
7968 // Arrange
8069 const testContent = '# Test Document\n\nSome content here.\n' ;
8170 mockFs ( {
8271 '/test/document.md' : testContent ,
8372 } ) ;
8473
85- // Act: Read using new ReaderAdapter pattern
74+ // Act: Read using ReaderAdapter pattern
8675 const streamContent = await readerAdapter . getContent ( '/test/document.md' ) ;
8776 const streamBuffer = await readableToBuffer ( streamContent ) ;
8877
89- // Act: Read using RendererService (bridge pattern)
90- const serviceBuffer = await rendererService . readExistingContent ( '/test/document.md' ) ;
78+ // Assert: Content should match what was written
79+ expect ( streamBuffer . toString ( ) ) . toBe ( testContent ) ;
80+ } ) ;
81+
82+ it ( 'should convert stream directly to string efficiently' , async ( ) => {
83+ // Arrange
84+ const testContent = '# Test Document\n\nSome content here.\n' ;
85+ mockFs ( {
86+ '/test/document.md' : testContent ,
87+ } ) ;
88+
89+ // Act: Read using readableToString for direct string conversion
90+ const stream1 = await readerAdapter . getContent ( '/test/document.md' ) ;
91+ const directString = await readableToString ( stream1 , 'utf-8' ) ;
92+
93+ // Act: Read using readableToBuffer then convert to string
94+ const stream2 = await readerAdapter . getContent ( '/test/document.md' ) ;
95+ const bufferThenString = ( await readableToBuffer ( stream2 ) ) . toString ( 'utf-8' ) ;
9196
9297 // Assert: Both methods should return identical content
93- expect ( streamBuffer . toString ( ) ) . toBe ( testContent ) ;
94- expect ( serviceBuffer . toString ( ) ) . toBe ( testContent ) ;
95- expect ( streamBuffer . equals ( serviceBuffer ) ) . toBe ( true ) ;
98+ expect ( directString ) . toBe ( testContent ) ;
99+ expect ( bufferThenString ) . toBe ( testContent ) ;
100+ expect ( directString ) . toBe ( bufferThenString ) ;
96101 } ) ;
97102 } ) ;
98103} ) ;
0 commit comments