Skip to content

Commit 66f9859

Browse files
test: add boundary unit test case in FileServiceClient
1 parent 04beae2 commit 66f9859

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/file-service/__tests__/browser/file-service-client.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ describe('FileServiceClient should be work', () => {
290290
expect(streamProvider.readFile).not.toHaveBeenCalled();
291291
});
292292

293+
it('reads via stream when size equals threshold', async () => {
294+
configureStreamPreferences(10, true);
295+
streamProvider.stat.mockResolvedValue(createStreamStat(streamResourceUri, 10));
296+
const chunk = new Uint8Array([11]);
297+
streamProvider.readFileStream.mockImplementation(async () => createReadableStream([chunk]));
298+
299+
const result = await fileServiceClient.readFile(streamResourceUri);
300+
301+
expect(streamProvider.readFileStream).toHaveBeenCalledTimes(1);
302+
expect(streamProvider.readFile).not.toHaveBeenCalled();
303+
expect(Array.from(result.content.buffer)).toEqual([11]);
304+
});
305+
293306
it('falls back to readFile when stream reading fails', async () => {
294307
configureStreamPreferences(10, true);
295308
streamProvider.stat.mockResolvedValue(createStreamStat(streamResourceUri, 50));
@@ -318,5 +331,18 @@ describe('FileServiceClient should be work', () => {
318331
expect(streamProvider.readFile).toHaveBeenCalledTimes(1);
319332
expect(Array.from(result.content.buffer)).toEqual([5, 6]);
320333
});
334+
335+
it('uses readFile when size is below threshold even if streaming enabled', async () => {
336+
configureStreamPreferences(10, true);
337+
streamProvider.stat.mockResolvedValue(createStreamStat(streamResourceUri, 5));
338+
const smallContent = new Uint8Array([8, 9]);
339+
streamProvider.readFile.mockResolvedValue(smallContent);
340+
341+
const result = await fileServiceClient.readFile(streamResourceUri);
342+
343+
expect(streamProvider.readFileStream).not.toHaveBeenCalled();
344+
expect(streamProvider.readFile).toHaveBeenCalledTimes(1);
345+
expect(Array.from(result.content.buffer)).toEqual([8, 9]);
346+
});
321347
});
322348
});

0 commit comments

Comments
 (0)