Files
repomix-mirror/tests/cli/cliReport.binaryFiles.test.ts
Kazuki YamadaandClaude Opus 5.5 0fbf578630 test(config): Restore and clear mocks globally via Vitest config
intent(test-hygiene): stop repeating mock cleanup by hand in 60 test files
decision(vitest-config): enable restoreMocks and clearMocks; both run before each test, ahead of beforeEach hooks, so every vi.spyOn() is back on the original method and every mock starts with empty call history
decision(mock-reset): keep mockReset off; it would rewind vi.fn() doubles configured once at module or describe scope (e.g. createMcpServerDouble, file-level deps objects)
decision(reset-calls): keep vi.resetAllMocks() in configLoad, globalDirectory, packageJsonParse, fileProcessContent, fileSearch, permissionCheck and sandbox.contract, whose file-scoped vi.fn() doubles get persistent or possibly unconsumed Once implementations inside tests; drop it where doubles are rebuilt in beforeEach or per test
constraint(vitest-5): clearMocks already defaults to true and restoreAllMocks only touches vi.spyOn(), not vi.fn(), so removing the manual calls does not change behaviour of vi.fn() doubles
learned(logger-doubles): silenceLogger() spies are restored before every test now, so they must be (re)created in beforeEach, after any vi.resetAllMocks()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 00:14:46 +09:00

66 lines
2.8 KiB
TypeScript

import { beforeEach, describe, expect, test } from 'vitest';
import { reportSkippedFiles } from '../../src/cli/cliReport.js';
import type { SkippedFileInfo } from '../../src/core/file/fileCollect.js';
import { logger } from '../../src/shared/logger.js';
import { silenceLogger } from '../testing/loggerDoubles.js';
describe('reportSkippedFiles', () => {
beforeEach(() => {
silenceLogger();
});
test('should not report anything when there are no binary-content files', () => {
const skippedFiles: SkippedFileInfo[] = [
{ path: 'large.txt', reason: 'size-limit' },
{ path: 'binary.bin', reason: 'binary-extension' },
{ path: 'error.txt', reason: 'encoding-error' },
];
reportSkippedFiles('/root', skippedFiles);
expect(logger.log).not.toHaveBeenCalled();
});
test('should report single binary-content file', () => {
const skippedFiles: SkippedFileInfo[] = [{ path: '/root/dir/malformed.txt', reason: 'binary-content' }];
reportSkippedFiles('/root', skippedFiles);
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('📄 Binary Files Detected:'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('1 file detected as binary'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('/root/dir/malformed.txt'));
});
test('should report multiple binary-content files', () => {
const skippedFiles: SkippedFileInfo[] = [
{ path: '/root/file1.txt', reason: 'binary-content' },
{ path: '/root/dir/file2.md', reason: 'binary-content' },
{ path: '/root/normal.bin', reason: 'binary-extension' }, // Should be ignored
];
reportSkippedFiles('/root', skippedFiles);
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('📄 Binary Files Detected:'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('2 files detected as binary'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('/root/file1.txt'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('/root/dir/file2.md'));
});
test('should show full paths correctly', () => {
const skippedFiles: SkippedFileInfo[] = [{ path: '/root/src/components/app.tsx', reason: 'binary-content' }];
reportSkippedFiles('/root', skippedFiles);
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('/root/src/components/app.tsx'));
});
test('should show warning messages about excluded files', () => {
const skippedFiles: SkippedFileInfo[] = [{ path: '/root/file.txt', reason: 'binary-content' }];
reportSkippedFiles('/root', skippedFiles);
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('These files have been excluded'));
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('Please review these files if you expected'));
});
});