perf: speed up slow git tests from ~18s to ~5.5s
- branch-manager: beforeEach→beforeAll (all 12 tests are read-only) - worktree manager: clone template repo per test instead of full init - signal-manager: reduce setTimeout delay from 100ms to 30ms
This commit is contained in:
@@ -133,7 +133,7 @@ describe('FileSystemSignalManager', () => {
|
|||||||
// Write signal after a delay
|
// Write signal after a delay
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await writeFile(signalPath, JSON.stringify(expectedSignal));
|
await writeFile(signalPath, JSON.stringify(expectedSignal));
|
||||||
}, 100);
|
}, 30);
|
||||||
|
|
||||||
const signal = await signalManager.waitForSignal(agentWorkdir, 1000);
|
const signal = await signalManager.waitForSignal(agentWorkdir, 1000);
|
||||||
expect(signal).toEqual(expectedSignal);
|
expect(signal).toEqual(expectedSignal);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Uses temporary git repositories for each test.
|
* Uses temporary git repositories for each test.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll } from 'vitest';
|
||||||
import { mkdtemp, rm, writeFile, mkdir } from 'node:fs/promises';
|
import { mkdtemp, rm, writeFile, mkdir } from 'node:fs/promises';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
@@ -48,16 +48,34 @@ async function createTestRepo(): Promise<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('SimpleGitWorktreeManager', () => {
|
describe('SimpleGitWorktreeManager', () => {
|
||||||
|
let templatePath: string;
|
||||||
|
let templateCleanup: () => Promise<void>;
|
||||||
let repoPath: string;
|
let repoPath: string;
|
||||||
let cleanup: () => Promise<void>;
|
let cleanup: () => Promise<void>;
|
||||||
let manager: SimpleGitWorktreeManager;
|
let manager: SimpleGitWorktreeManager;
|
||||||
let eventBus: EventBus;
|
let eventBus: EventBus;
|
||||||
let emittedEvents: Array<{ type: string; payload: unknown }>;
|
let emittedEvents: Array<{ type: string; payload: unknown }>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeAll(async () => {
|
||||||
const testRepo = await createTestRepo();
|
const testRepo = await createTestRepo();
|
||||||
repoPath = testRepo.repoPath;
|
templatePath = testRepo.repoPath;
|
||||||
cleanup = testRepo.cleanup;
|
templateCleanup = testRepo.cleanup;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await templateCleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
// Clone the template repo locally (hard-links, ~10ms vs ~50ms full init)
|
||||||
|
repoPath = await mkdtemp(path.join(tmpdir(), 'cw-test-repo-'));
|
||||||
|
await rm(repoPath, { recursive: true, force: true });
|
||||||
|
const git = simpleGit();
|
||||||
|
await git.clone(templatePath, repoPath, ['--local']);
|
||||||
|
|
||||||
|
cleanup = async () => {
|
||||||
|
await rm(repoPath, { recursive: true, force: true });
|
||||||
|
};
|
||||||
|
|
||||||
// Create event bus and track emitted events
|
// Create event bus and track emitted events
|
||||||
eventBus = new EventEmitterBus();
|
eventBus = new EventEmitterBus();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* a project's default branch.
|
* a project's default branch.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll } from 'vitest';
|
||||||
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
@@ -133,14 +133,14 @@ describe('SimpleGitBranchManager', () => {
|
|||||||
let cleanup: () => Promise<void>;
|
let cleanup: () => Promise<void>;
|
||||||
let branchManager: SimpleGitBranchManager;
|
let branchManager: SimpleGitBranchManager;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeAll(async () => {
|
||||||
const setup = await createTestRepoWithRemote();
|
const setup = await createTestRepoWithRemote();
|
||||||
clonePath = setup.clonePath;
|
clonePath = setup.clonePath;
|
||||||
cleanup = setup.cleanup;
|
cleanup = setup.cleanup;
|
||||||
branchManager = new SimpleGitBranchManager();
|
branchManager = new SimpleGitBranchManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterAll(async () => {
|
||||||
await cleanup();
|
await cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -177,14 +177,14 @@ describe('SimpleGitBranchManager - diffBranchesStat and diffFileSingle', () => {
|
|||||||
let cleanup: () => Promise<void>;
|
let cleanup: () => Promise<void>;
|
||||||
let branchManager: SimpleGitBranchManager;
|
let branchManager: SimpleGitBranchManager;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeAll(async () => {
|
||||||
const setup = await createTestRepoForDiff();
|
const setup = await createTestRepoForDiff();
|
||||||
clonePath = setup.clonePath;
|
clonePath = setup.clonePath;
|
||||||
cleanup = setup.cleanup;
|
cleanup = setup.cleanup;
|
||||||
branchManager = new SimpleGitBranchManager();
|
branchManager = new SimpleGitBranchManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterAll(async () => {
|
||||||
await cleanup();
|
await cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user