Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/cli/actions/defaultAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@ describe('defaultAction', () => {
expect(config.ignore?.useDefaultPatterns).toBe(false);
});

it('should handle --no-files flag', () => {
const options = {
files: false,
};
const config = buildCliConfig(options);

expect(config.output?.files).toBe(false);
});

it('should not set files in config when files option is true (Commander default)', () => {
const options = {
files: true,
};
const config = buildCliConfig(options);

expect(config.output?.files).toBeUndefined();
});
Comment on lines +308 to +324

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two tests for the files option can be combined into a single parameterized test using it.each. This makes the test cases more explicit and reduces boilerplate, improving maintainability.

    it.each([
      { files: false, expected: false, description: 'should handle --no-files flag' },
      {
        files: true,
        expected: undefined,
        description: 'should not set files in config when files option is true (Commander default)',
      },
    ])('$description', ({ files, expected }) => {
      const options = {
        files,
      };
      const config = buildCliConfig(options);

      expect(config.output?.files).toBe(expected);
    });


it('should handle --skill-generate with string name', () => {
const options: CliOptions = {
skillGenerate: 'my-skill',
Expand Down
20 changes: 20 additions & 0 deletions tests/config/configLoad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,25 @@ describe('configLoad', () => {
const merged = mergeConfigs(process.cwd(), {}, { skillGenerate: 'from-cli' });
expect(merged.skillGenerate).toBe('from-cli');
});

test('should respect files: false from CLI config', () => {
const merged = mergeConfigs(process.cwd(), {}, { output: { files: false } });
expect(merged.output.files).toBe(false);
});

test('should respect files: false from file config', () => {
const merged = mergeConfigs(process.cwd(), { output: { files: false } }, {});
expect(merged.output.files).toBe(false);
});

test('should let CLI files: false override file config files: true', () => {
const merged = mergeConfigs(process.cwd(), { output: { files: true } }, { output: { files: false } });
expect(merged.output.files).toBe(false);
});

test('should default files to true when not set in any config', () => {
const merged = mergeConfigs(process.cwd(), {}, {});
expect(merged.output.files).toBe(true);
});
});
});
71 changes: 71 additions & 0 deletions tests/core/output/outputGenerate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,77 @@ describe('outputGenerate', () => {
expect(output).not.toContain('content1');
});

test('generateOutput should exclude files section in xml style when files is false', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.xml',
style: 'xml',
files: false,
},
});
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];

const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);

expect(output).not.toContain('file1.txt');
expect(output).not.toContain('content1');
expect(output).not.toContain('<file path=');
});

test('generateOutput should exclude files section in parsable xml style when files is false', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.xml',
style: 'xml',
parsableStyle: true,
files: false,
},
});
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: '<div>foo</div>' }];

const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);

const parser = new XMLParser({ ignoreAttributes: false });
const parsedOutput = parser.parse(output);
expect(parsedOutput.repomix.files).toBeUndefined();
});

test('generateOutput should exclude files section in markdown style when files is false', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.md',
style: 'markdown',
files: false,
},
});
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];

const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);

expect(output).not.toContain('## File: file1.txt');
expect(output).not.toContain('content1');
expect(output).not.toContain('# Files');
});

test('generateOutput should exclude files section in json style when files is false', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.json',
style: 'json',
files: false,
},
});
const mockProcessedFiles: ProcessedFile[] = [
{ path: 'file1.txt', content: 'content1' },
{ path: 'file2.txt', content: 'content2' },
];

const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);

const parsed = JSON.parse(output);
expect(parsed).not.toHaveProperty('files');
});
Comment on lines +296 to +365

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These four new tests are very similar in structure. They can be consolidated into a single parameterized test using test.each to reduce code duplication and improve maintainability.

  test.each([
    {
      description: 'xml style',
      config: { filePath: 'output.xml', style: 'xml' as const },
      processedFiles: [{ path: 'file1.txt', content: 'content1' }],
      check: (output: string) => {
        expect(output).not.toContain('file1.txt');
        expect(output).not.toContain('content1');
        expect(output).not.toContain('<files>');
      },
    },
    {
      description: 'parsable xml style',
      config: { filePath: 'output.xml', style: 'xml' as const, parsableStyle: true },
      processedFiles: [{ path: 'file1.txt', content: '<div>foo</div>' }],
      check: (output: string) => {
        const parser = new XMLParser({ ignoreAttributes: false });
        const parsedOutput = parser.parse(output);
        expect(parsedOutput.repomix.files).toBeUndefined();
      },
    },
    {
      description: 'markdown style',
      config: { filePath: 'output.md', style: 'markdown' as const },
      processedFiles: [{ path: 'file1.txt', content: 'content1' }],
      check: (output: string) => {
        expect(output).not.toContain('## File: file1.txt');
        expect(output).not.toContain('content1');
        expect(output).not.toContain('# Files');
      },
    },
    {
      description: 'json style',
      config: { filePath: 'output.json', style: 'json' as const },
      processedFiles: [
        { path: 'file1.txt', content: 'content1' },
        { path: 'file2.txt', content: 'content2' },
      ],
      check: (output: string) => {
        const parsed = JSON.parse(output);
        expect(parsed).not.toHaveProperty('files');
      },
    },
  ])(
    'generateOutput should exclude files section in $description when files is false',
    async ({ config, processedFiles, check }) => {
      const mockConfig = createMockConfig({
        output: {
          ...config,
          files: false,
        },
      });

      const output = await generateOutput([process.cwd()], mockConfig, processedFiles, []);

      check(output);
    },
  );


test('generateOutput should exclude directory structure when disabled', async () => {
const mockConfig = createMockConfig({
output: {
Expand Down