mirror of
https://github.com/yamadashy/repomix.git
synced 2026-05-30 11:18:53 +02:00
7649725a21
Aligns with files.md pattern (## File: <path>). Each package is now a ## section under a single # Tech Stacks heading, with ### subsections for Languages, Frameworks, Dependencies, etc. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
125 lines
4.4 KiB
TypeScript
125 lines
4.4 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import type { RenderContext } from '../../../src/core/output/outputGeneratorTypes.js';
|
|
import {
|
|
generateFilesSection,
|
|
generateStructureSection,
|
|
generateSummarySection,
|
|
} from '../../../src/core/skill/skillSectionGenerators.js';
|
|
|
|
const createMockContext = (overrides: Partial<RenderContext> = {}): RenderContext => ({
|
|
generationHeader: 'Generated by Repomix',
|
|
summaryPurpose: 'This file contains a packed representation of the entire repository.',
|
|
summaryFileFormat: 'The content is organized as follows...',
|
|
summaryUsageGuidelines: 'Use this file as context for AI assistants.',
|
|
summaryNotes: 'Some files may have been excluded.',
|
|
headerText: '',
|
|
instruction: '',
|
|
treeString: 'src/\n index.ts\n utils.ts',
|
|
processedFiles: [
|
|
{ path: 'src/index.ts', content: 'console.log("hello");' },
|
|
{ path: 'src/utils.ts', content: 'export const sum = (a, b) => a + b;' },
|
|
],
|
|
fileLineCounts: {
|
|
'src/index.ts': 1,
|
|
'src/utils.ts': 1,
|
|
},
|
|
fileSummaryEnabled: true,
|
|
directoryStructureEnabled: true,
|
|
filesEnabled: true,
|
|
escapeFileContent: false,
|
|
markdownCodeBlockDelimiter: '```',
|
|
gitDiffEnabled: false,
|
|
gitDiffWorkTree: undefined,
|
|
gitDiffStaged: undefined,
|
|
gitLogEnabled: false,
|
|
gitLogContent: undefined,
|
|
gitLogCommits: undefined,
|
|
...overrides,
|
|
});
|
|
|
|
describe('skillSectionGenerators', () => {
|
|
describe('generateSummarySection', () => {
|
|
test('should generate summary section with all fields', () => {
|
|
const context = createMockContext();
|
|
const result = generateSummarySection(context);
|
|
|
|
expect(result).toContain('Generated by Repomix');
|
|
expect(result).toContain('# Summary');
|
|
expect(result).toContain('## Purpose');
|
|
expect(result).toContain('reference codebase organized into multiple files');
|
|
expect(result).toContain('## File Structure');
|
|
expect(result).toContain('project-structure.md');
|
|
expect(result).toContain('files.md');
|
|
expect(result).toContain('tech-stacks.md');
|
|
expect(result).toContain('summary.md');
|
|
expect(result).toContain('## Usage Guidelines');
|
|
expect(result).toContain('## Notes');
|
|
});
|
|
|
|
test('should include statistics section when provided', () => {
|
|
const context = createMockContext();
|
|
const statisticsSection = '## Statistics\n\n10 files | 500 lines';
|
|
const result = generateSummarySection(context, statisticsSection);
|
|
|
|
expect(result).toContain('## Statistics');
|
|
expect(result).toContain('10 files | 500 lines');
|
|
});
|
|
});
|
|
|
|
describe('generateStructureSection', () => {
|
|
test('should generate structure section with tree string', () => {
|
|
const context = createMockContext();
|
|
const result = generateStructureSection(context);
|
|
|
|
expect(result).toContain('# Directory Structure');
|
|
expect(result).toContain('```');
|
|
expect(result).toContain('src/');
|
|
expect(result).toContain('index.ts');
|
|
});
|
|
|
|
test('should return empty string when directory structure is disabled', () => {
|
|
const context = createMockContext({ directoryStructureEnabled: false });
|
|
const result = generateStructureSection(context);
|
|
|
|
expect(result).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('generateFilesSection', () => {
|
|
test('should generate files section with all files', () => {
|
|
const context = createMockContext();
|
|
const result = generateFilesSection(context);
|
|
|
|
expect(result).toContain('# Files');
|
|
expect(result).toContain('## File: src/index.ts');
|
|
expect(result).toContain('console.log("hello");');
|
|
expect(result).toContain('## File: src/utils.ts');
|
|
expect(result).toContain('export const sum');
|
|
});
|
|
|
|
test('should include syntax highlighting language', () => {
|
|
const context = createMockContext();
|
|
const result = generateFilesSection(context);
|
|
|
|
expect(result).toContain('```typescript');
|
|
});
|
|
|
|
test('should return empty string when files are disabled', () => {
|
|
const context = createMockContext({ filesEnabled: false });
|
|
const result = generateFilesSection(context);
|
|
|
|
expect(result).toBe('');
|
|
});
|
|
|
|
test('should handle files without known extensions', () => {
|
|
const context = createMockContext({
|
|
processedFiles: [{ path: 'Dockerfile', content: 'FROM node:18' }],
|
|
});
|
|
const result = generateFilesSection(context);
|
|
|
|
expect(result).toContain('## File: Dockerfile');
|
|
expect(result).toContain('FROM node:18');
|
|
});
|
|
});
|
|
});
|