719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
149 lines
4.3 KiB
TypeScript
149 lines
4.3 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import type { RepomixConfigMerged } from '../../../../src/config/configSchema.js';
|
|
import type { ProcessedFile } from '../../../../src/core/file/fileTypes.js';
|
|
import { generateOutput } from '../../../../src/core/output/outputGenerate.js';
|
|
|
|
const createMockConfig = (overrides: Partial<RepomixConfigMerged> = {}): RepomixConfigMerged => ({
|
|
cwd: '/test',
|
|
input: { maxFileSize: 1024 * 1024 },
|
|
output: {
|
|
filePath: 'test-output.json',
|
|
style: 'json' as const,
|
|
filePathStyle: 'target-relative',
|
|
parsableStyle: false,
|
|
headerText: undefined,
|
|
instructionFilePath: undefined,
|
|
fileSummary: true,
|
|
directoryStructure: true,
|
|
files: true,
|
|
removeComments: false,
|
|
removeEmptyLines: false,
|
|
compress: false,
|
|
topFilesLength: 5,
|
|
showLineNumbers: false,
|
|
truncateBase64: false,
|
|
copyToClipboard: false,
|
|
includeEmptyDirectories: false,
|
|
includeFullDirectoryStructure: false,
|
|
tokenCountTree: false,
|
|
git: {
|
|
sortByChanges: false,
|
|
sortByChangesMaxCommits: 10,
|
|
includeDiffs: false,
|
|
includeLogs: false,
|
|
includeLogsCount: 5,
|
|
},
|
|
},
|
|
include: [],
|
|
ignore: {
|
|
useGitignore: true,
|
|
useDotIgnore: true,
|
|
useDefaultPatterns: true,
|
|
customPatterns: [],
|
|
},
|
|
security: {
|
|
enableSecurityCheck: true,
|
|
},
|
|
tokenCount: {
|
|
encoding: 'cl100k_base',
|
|
},
|
|
...overrides,
|
|
});
|
|
|
|
const createMockProcessedFiles = (): ProcessedFile[] => [
|
|
{
|
|
path: 'src/index.ts',
|
|
content: 'console.log("Hello");',
|
|
},
|
|
{
|
|
path: 'package.json',
|
|
content: '{"name": "test"}',
|
|
},
|
|
];
|
|
|
|
describe('JSON Output Style', () => {
|
|
test('should generate valid JSON output', async () => {
|
|
const config = createMockConfig();
|
|
const processedFiles = createMockProcessedFiles();
|
|
const allFilePaths = processedFiles.map((f) => f.path);
|
|
|
|
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
|
|
|
|
// Should be valid JSON
|
|
expect(() => JSON.parse(result)).not.toThrow();
|
|
|
|
const parsed = JSON.parse(result);
|
|
expect(parsed).toBeDefined();
|
|
});
|
|
|
|
test('should include fileSummary when enabled', async () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
...createMockConfig().output,
|
|
fileSummary: true,
|
|
},
|
|
});
|
|
const processedFiles = createMockProcessedFiles();
|
|
const allFilePaths = processedFiles.map((f) => f.path);
|
|
|
|
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
|
|
const parsed = JSON.parse(result);
|
|
|
|
expect(parsed.fileSummary).toBeDefined();
|
|
expect(parsed.fileSummary.purpose).toBeDefined();
|
|
});
|
|
|
|
test('should not include fileSummary when disabled', async () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
...createMockConfig().output,
|
|
fileSummary: false,
|
|
},
|
|
});
|
|
const processedFiles = createMockProcessedFiles();
|
|
const allFilePaths = processedFiles.map((f) => f.path);
|
|
|
|
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
|
|
const parsed = JSON.parse(result);
|
|
|
|
expect(parsed.fileSummary).toBeUndefined();
|
|
});
|
|
|
|
test('should include files when enabled', async () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
...createMockConfig().output,
|
|
files: true,
|
|
},
|
|
});
|
|
const processedFiles = createMockProcessedFiles();
|
|
const allFilePaths = processedFiles.map((f) => f.path);
|
|
|
|
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
|
|
const parsed = JSON.parse(result);
|
|
|
|
expect(parsed.files).toBeDefined();
|
|
expect(parsed.files['src/index.ts']).toBe('console.log("Hello");');
|
|
expect(parsed.files['package.json']).toBe('{"name": "test"}');
|
|
});
|
|
|
|
test('should handle special characters in file content', async () => {
|
|
const config = createMockConfig();
|
|
const processedFiles: ProcessedFile[] = [
|
|
{
|
|
path: 'test.js',
|
|
content: 'const str = "Hello "world"\nNew line\tTab";',
|
|
},
|
|
];
|
|
const allFilePaths = processedFiles.map((f) => f.path);
|
|
|
|
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
|
|
|
|
// Should be valid JSON
|
|
expect(() => JSON.parse(result)).not.toThrow();
|
|
|
|
const parsed = JSON.parse(result);
|
|
expect(parsed.files['test.js']).toBe('const str = "Hello "world"\nNew line\tTab";');
|
|
});
|
|
});
|