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
95 lines
4.0 KiB
TypeScript
95 lines
4.0 KiB
TypeScript
import fs from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import { searchFiles } from '../../../src/core/file/fileSearch.js';
|
|
import { createMockConfig, writeFixture } from '../../testing/testUtils.js';
|
|
|
|
// Behavior-level regression tests for empty-directory preservation.
|
|
//
|
|
// Empty directories are an opt-in feature (`output.includeEmptyDirectories`).
|
|
// The implementation takes a 2-pass globby path (object mode, then a
|
|
// `findEmptyDirectories` filter) which is more complex than the default
|
|
// onlyFiles path and therefore a tempting target for perf reshuffling.
|
|
//
|
|
// This spec is intentionally single-root only — multi-root empty-directory
|
|
// handling is explicitly NOT implemented (see comment in
|
|
// generateMultiRootSections in fileTreeGenerate.ts: "Empty directories
|
|
// (emptyDirPaths) are not included in multi-root output"). Asserting on it
|
|
// would freeze the current intentional gap as a contract.
|
|
|
|
describe('empty directory preservation spec', () => {
|
|
let tmpDir: string;
|
|
|
|
beforeEach(async () => {
|
|
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'repomix-emptydir-spec-'));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('returns an empty directory in emptyDirPaths when `includeEmptyDirectories: true`', async () => {
|
|
await writeFixture(tmpDir, {
|
|
'src/keep.ts': 'export {};\n',
|
|
});
|
|
await fs.mkdir(path.join(tmpDir, 'docs', 'placeholder'), { recursive: true });
|
|
|
|
const config = createMockConfig({ output: { includeEmptyDirectories: true } });
|
|
const { filePaths, emptyDirPaths } = await searchFiles(tmpDir, config);
|
|
|
|
expect(filePaths).toContain('src/keep.ts');
|
|
expect(emptyDirPaths).toContain('docs/placeholder');
|
|
});
|
|
|
|
it('omits empty directories entirely when `includeEmptyDirectories: false` (the default)', async () => {
|
|
// Negative contract: the default behavior must not start eagerly emitting
|
|
// empty directories as a side effect of a perf change (e.g. one that
|
|
// unifies the two-pass globby into a single pass and forgets to gate the
|
|
// emptyDir collection).
|
|
await writeFixture(tmpDir, {
|
|
'src/keep.ts': 'export {};\n',
|
|
});
|
|
await fs.mkdir(path.join(tmpDir, 'docs', 'placeholder'), { recursive: true });
|
|
|
|
const config = createMockConfig();
|
|
const { filePaths, emptyDirPaths } = await searchFiles(tmpDir, config);
|
|
|
|
expect(filePaths).toContain('src/keep.ts');
|
|
expect(emptyDirPaths).toEqual([]);
|
|
});
|
|
|
|
it('does not report a directory that contains files as empty', async () => {
|
|
// Sanity check on the filter logic: if `findEmptyDirectories` were replaced
|
|
// by a faster but coarser implementation that only checked the directory
|
|
// listing without descending, a directory containing nested files could be
|
|
// wrongly classified as empty.
|
|
await writeFixture(tmpDir, {
|
|
'pkg/util/util.ts': 'export {};\n',
|
|
});
|
|
// pkg has a non-empty subdir, so neither `pkg` nor `pkg/util` should be reported.
|
|
|
|
const config = createMockConfig({ output: { includeEmptyDirectories: true } });
|
|
const { emptyDirPaths } = await searchFiles(tmpDir, config);
|
|
|
|
expect(emptyDirPaths).not.toContain('pkg');
|
|
expect(emptyDirPaths).not.toContain('pkg/util');
|
|
});
|
|
|
|
it('respects gitignore: an empty directory whose path is gitignored is NOT reported', async () => {
|
|
// Empty-dir collection must compose with the ignore engine. If a perf
|
|
// change collected empty dirs from the raw fs walk and bypassed gitignore,
|
|
// an `output/` directory listed in .gitignore would still be emitted.
|
|
await writeFixture(tmpDir, {
|
|
'.gitignore': 'output/\n',
|
|
'src/keep.ts': 'export {};\n',
|
|
});
|
|
await fs.mkdir(path.join(tmpDir, 'output'), { recursive: true });
|
|
|
|
const config = createMockConfig({ output: { includeEmptyDirectories: true } });
|
|
const { emptyDirPaths } = await searchFiles(tmpDir, config);
|
|
|
|
expect(emptyDirPaths).not.toContain('output');
|
|
});
|
|
});
|