mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
fix(tests): improve test reliability and performance (#8395)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
} from 'vitest';
|
||||
|
||||
import * as actualNodeFs from 'node:fs'; // For setup/teardown
|
||||
import fs from 'node:fs';
|
||||
import fsPromises from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
@@ -954,22 +955,30 @@ describe('fileUtils', () => {
|
||||
});
|
||||
|
||||
it('should return an error if the file size exceeds 20MB', async () => {
|
||||
// Create a file just over 20MB
|
||||
const twentyOneMB = 21 * 1024 * 1024;
|
||||
const buffer = Buffer.alloc(twentyOneMB, 0x61); // Fill with 'a'
|
||||
actualNodeFs.writeFileSync(testTextFilePath, buffer);
|
||||
// Create a small test file
|
||||
actualNodeFs.writeFileSync(testTextFilePath, 'test content');
|
||||
|
||||
const result = await processSingleFileContent(
|
||||
testTextFilePath,
|
||||
tempRootDir,
|
||||
new StandardFileSystemService(),
|
||||
);
|
||||
// Spy on fs.promises.stat to return a large file size
|
||||
const statSpy = vi.spyOn(fs.promises, 'stat').mockResolvedValueOnce({
|
||||
size: 21 * 1024 * 1024,
|
||||
isDirectory: () => false,
|
||||
} as fs.Stats);
|
||||
|
||||
expect(result.error).toContain('File size exceeds the 20MB limit');
|
||||
expect(result.returnDisplay).toContain(
|
||||
'File size exceeds the 20MB limit',
|
||||
);
|
||||
expect(result.llmContent).toContain('File size exceeds the 20MB limit');
|
||||
try {
|
||||
const result = await processSingleFileContent(
|
||||
testTextFilePath,
|
||||
tempRootDir,
|
||||
new StandardFileSystemService(),
|
||||
);
|
||||
|
||||
expect(result.error).toContain('File size exceeds the 20MB limit');
|
||||
expect(result.returnDisplay).toContain(
|
||||
'File size exceeds the 20MB limit',
|
||||
);
|
||||
expect(result.llmContent).toContain('File size exceeds the 20MB limit');
|
||||
} finally {
|
||||
statSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user