56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env';
|
|
import { runTakt } from '../helpers/takt-runner';
|
|
|
|
function createLocalRepo(): { path: string; cleanup: () => void } {
|
|
const repoPath = mkdtempSync(join(tmpdir(), 'takt-e2e-clear-'));
|
|
execFileSync('git', ['init'], { cwd: repoPath, stdio: 'pipe' });
|
|
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: repoPath, stdio: 'pipe' });
|
|
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: repoPath, stdio: 'pipe' });
|
|
writeFileSync(join(repoPath, 'README.md'), '# test\n');
|
|
execFileSync('git', ['add', '.'], { cwd: repoPath, stdio: 'pipe' });
|
|
execFileSync('git', ['commit', '-m', 'init'], { cwd: repoPath, stdio: 'pipe' });
|
|
return {
|
|
path: repoPath,
|
|
cleanup: () => {
|
|
try { rmSync(repoPath, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
},
|
|
};
|
|
}
|
|
|
|
// E2E更新時は docs/testing/e2e.md も更新すること
|
|
describe('E2E: Clear sessions command (takt clear)', () => {
|
|
let isolatedEnv: IsolatedEnv;
|
|
let repo: { path: string; cleanup: () => void };
|
|
|
|
beforeEach(() => {
|
|
isolatedEnv = createIsolatedEnv();
|
|
repo = createLocalRepo();
|
|
});
|
|
|
|
afterEach(() => {
|
|
try { repo.cleanup(); } catch { /* best-effort */ }
|
|
try { isolatedEnv.cleanup(); } catch { /* best-effort */ }
|
|
});
|
|
|
|
it('should clear sessions without error', () => {
|
|
// Given: a local repo with isolated env
|
|
|
|
// When: running takt clear
|
|
const result = runTakt({
|
|
args: ['clear'],
|
|
cwd: repo.path,
|
|
env: isolatedEnv.env,
|
|
});
|
|
|
|
// Then: exits cleanly
|
|
expect(result.exitCode).toBe(0);
|
|
const output = result.stdout.toLowerCase();
|
|
expect(output).toMatch(/clear|session|removed|no session/);
|
|
});
|
|
});
|