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
101 lines
3.6 KiB
TypeScript
101 lines
3.6 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import {
|
|
type FilesByRoot,
|
|
generateTreeString,
|
|
generateTreeStringWithRoots,
|
|
} from '../../../src/core/file/fileTreeGenerate.js';
|
|
|
|
describe('fileTreeGenerate', () => {
|
|
describe('generateTreeString', () => {
|
|
test('generates a flat tree for single directory files', () => {
|
|
const files = ['file1.txt', 'file2.txt', 'subdir/nested.txt'];
|
|
const result = generateTreeString(files);
|
|
|
|
expect(result).toContain('file1.txt');
|
|
expect(result).toContain('file2.txt');
|
|
expect(result).toContain('subdir/');
|
|
expect(result).toContain('nested.txt');
|
|
});
|
|
|
|
// globby/buildFileDisplayPath always hand out "/"-separated paths, even on Windows
|
|
// where path.sep is "\\". Backslash input here stands in for that separator/path.sep
|
|
// mismatch: the tree must nest by path segment regardless of the OS separator.
|
|
test('nests paths independently of the OS separator', () => {
|
|
const files = ['src\\index.ts', 'src\\utils\\helper.ts'];
|
|
const result = generateTreeString(files);
|
|
|
|
expect(result).toBe('src/\n utils/\n helper.ts\n index.ts');
|
|
});
|
|
});
|
|
|
|
describe('generateTreeStringWithRoots', () => {
|
|
test('returns standard flat tree for single root', () => {
|
|
const filesByRoot: FilesByRoot[] = [{ rootLabel: 'project', files: ['file1.txt', 'file2.txt'] }];
|
|
|
|
const result = generateTreeStringWithRoots(filesByRoot);
|
|
|
|
// Should not have root label for single root
|
|
expect(result).not.toContain('[project]');
|
|
expect(result).toContain('file1.txt');
|
|
expect(result).toContain('file2.txt');
|
|
});
|
|
|
|
test('generates labeled sections for multiple roots', () => {
|
|
const filesByRoot: FilesByRoot[] = [
|
|
{ rootLabel: 'cli', files: ['cliRun.ts', 'types.ts'] },
|
|
{ rootLabel: 'config', files: ['configLoad.ts', 'configSchema.ts'] },
|
|
];
|
|
|
|
const result = generateTreeStringWithRoots(filesByRoot);
|
|
|
|
// Should have root labels
|
|
expect(result).toContain('[cli]/');
|
|
expect(result).toContain('[config]/');
|
|
|
|
// Should have files under each label
|
|
expect(result).toContain('cliRun.ts');
|
|
expect(result).toContain('types.ts');
|
|
expect(result).toContain('configLoad.ts');
|
|
expect(result).toContain('configSchema.ts');
|
|
});
|
|
|
|
test('generates labeled sections with nested directories', () => {
|
|
const filesByRoot: FilesByRoot[] = [
|
|
{ rootLabel: 'src', files: ['index.ts', 'utils/helper.ts', 'utils/format.ts'] },
|
|
{ rootLabel: 'tests', files: ['index.test.ts'] },
|
|
];
|
|
|
|
const result = generateTreeStringWithRoots(filesByRoot);
|
|
|
|
expect(result).toContain('[src]/');
|
|
expect(result).toContain('[tests]/');
|
|
expect(result).toContain('utils/');
|
|
expect(result).toContain('helper.ts');
|
|
});
|
|
|
|
test('skips empty root sections', () => {
|
|
const filesByRoot: FilesByRoot[] = [
|
|
{ rootLabel: 'cli', files: ['cliRun.ts'] },
|
|
{ rootLabel: 'empty', files: [] },
|
|
{ rootLabel: 'config', files: ['configLoad.ts'] },
|
|
];
|
|
|
|
const result = generateTreeStringWithRoots(filesByRoot);
|
|
|
|
expect(result).toContain('[cli]/');
|
|
expect(result).not.toContain('[empty]/');
|
|
expect(result).toContain('[config]/');
|
|
});
|
|
|
|
test('handles single root falling back to standard behavior', () => {
|
|
const filesByRoot: FilesByRoot[] = [{ rootLabel: 'project', files: ['a.txt', 'b/c.txt'] }];
|
|
|
|
const singleRootResult = generateTreeStringWithRoots(filesByRoot);
|
|
const standardResult = generateTreeString(['a.txt', 'b/c.txt']);
|
|
|
|
// Should be identical
|
|
expect(singleRootResult).toBe(standardResult);
|
|
});
|
|
});
|
|
});
|