From 55aeeab4ec9462e303779827c8246c1716f96850 Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Tue, 10 Feb 2026 07:30:33 +0900 Subject: [PATCH] fix e2e --- e2e/specs/add.e2e.ts | 15 +++++++-------- e2e/specs/watch.e2e.ts | 29 +++++++++++++++++++---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/e2e/specs/add.e2e.ts b/e2e/specs/add.e2e.ts index 6cb0f92..a4bb031 100644 --- a/e2e/specs/add.e2e.ts +++ b/e2e/specs/add.e2e.ts @@ -1,8 +1,9 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { execFileSync } from 'node:child_process'; -import { readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import { readFileSync, writeFileSync } from 'node:fs'; import { join, dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; +import { parse as parseYaml } from 'yaml'; import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env'; import { createTestRepo, type TestRepo } from '../helpers/test-repo'; import { runTakt } from '../helpers/takt-runner'; @@ -84,12 +85,10 @@ describe('E2E: Add task from GitHub issue (takt add)', () => { expect(result.exitCode).toBe(0); - const tasksDir = join(testRepo.path, '.takt', 'tasks'); - const files = readdirSync(tasksDir).filter((file) => file.endsWith('.yaml')); - expect(files.length).toBe(1); - - const taskFile = join(tasksDir, files[0] ?? ''); - const content = readFileSync(taskFile, 'utf-8'); - expect(content).toContain('issue:'); + const tasksFile = join(testRepo.path, '.takt', 'tasks.yaml'); + const content = readFileSync(tasksFile, 'utf-8'); + const parsed = parseYaml(content) as { tasks?: Array<{ issue?: number }> }; + expect(parsed.tasks?.length).toBe(1); + expect(parsed.tasks?.[0]?.issue).toBe(Number(issueNumber)); }, 240_000); }); diff --git a/e2e/specs/watch.e2e.ts b/e2e/specs/watch.e2e.ts index 3cb2162..29e0c18 100644 --- a/e2e/specs/watch.e2e.ts +++ b/e2e/specs/watch.e2e.ts @@ -1,8 +1,9 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { spawn } from 'node:child_process'; -import { mkdirSync, writeFileSync, existsSync } from 'node:fs'; +import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join, resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; +import { parse as parseYaml } from 'yaml'; import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env'; import { createTestRepo, type TestRepo } from '../helpers/test-repo'; @@ -51,16 +52,21 @@ describe('E2E: Watch tasks (takt watch)', () => { stdout += chunk.toString(); }); - const tasksDir = join(testRepo.path, '.takt', 'tasks'); - mkdirSync(tasksDir, { recursive: true }); - + const taktDir = join(testRepo.path, '.takt'); + mkdirSync(taktDir, { recursive: true }); + const tasksFile = join(taktDir, 'tasks.yaml'); + const createdAt = new Date().toISOString(); const taskYaml = [ - 'task: "Add a single line \\\"watch test\\\" to README.md"', - `piece: "${piecePath}"`, + 'tasks:', + ' - name: watch-task', + ' status: pending', + ' content: "Add a single line \\"watch test\\" to README.md"', + ` piece: "${piecePath}"`, + ` created_at: "${createdAt}"`, + ' started_at: null', + ' completed_at: null', ].join('\n'); - - const taskPath = join(tasksDir, 'watch-task.yaml'); - writeFileSync(taskPath, taskYaml, 'utf-8'); + writeFileSync(tasksFile, taskYaml, 'utf-8'); const completed = await new Promise((resolvePromise) => { const timeout = setTimeout(() => resolvePromise(false), 240_000); @@ -87,6 +93,9 @@ describe('E2E: Watch tasks (takt watch)', () => { }); expect(completed).toBe(true); - expect(existsSync(taskPath)).toBe(false); + const tasksRaw = readFileSync(tasksFile, 'utf-8'); + const parsed = parseYaml(tasksRaw) as { tasks?: Array<{ name?: string; status?: string }> }; + const watchTask = parsed.tasks?.find((task) => task.name === 'watch-task'); + expect(watchTask?.status).toBe('completed'); }, 240_000); });