diff --git a/test/edge-cases.test.ts b/test/edge-cases.test.ts index 4ac38399..b24e78b6 100644 --- a/test/edge-cases.test.ts +++ b/test/edge-cases.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest'; import { WebServer } from '../src/web/server.js'; import { existsSync, rmSync } from 'node:fs'; import { join } from 'node:path'; @@ -18,14 +18,19 @@ describe('Edge Cases and Error Handling', () => { baseUrl = `http://localhost:${TEST_PORT}`; }); - afterAll(async () => { - await server.stop(); - for (const caseName of createdCases) { + afterEach(() => { + // Clean up cases created during this test + while (createdCases.length > 0) { + const caseName = createdCases.pop()!; const casePath = join(CASES_DIR, caseName); if (existsSync(casePath)) { rmSync(casePath, { recursive: true, force: true }); } } + }); + + afterAll(async () => { + await server.stop(); }, 30000); describe('Session Edge Cases', () => { diff --git a/test/integration-flows.test.ts b/test/integration-flows.test.ts index 090b88ef..6a2c3a4e 100644 --- a/test/integration-flows.test.ts +++ b/test/integration-flows.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest'; import { WebServer } from '../src/web/server.js'; import { existsSync, rmSync } from 'node:fs'; import { join } from 'node:path'; @@ -23,6 +23,17 @@ describe('Integration Flows', () => { baseUrl = `http://localhost:${TEST_PORT}`; }); + afterEach(() => { + // Clean up cases created during this test + while (createdCases.length > 0) { + const caseName = createdCases.pop()!; + const casePath = join(CASES_DIR, caseName); + if (existsSync(casePath)) { + rmSync(casePath, { recursive: true, force: true }); + } + } + }); + afterAll(async () => { // Cleanup sessions for (const sessionId of createdSessions) { @@ -30,13 +41,6 @@ describe('Integration Flows', () => { await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' }); } catch {} } - // Cleanup cases - for (const caseName of createdCases) { - const casePath = join(CASES_DIR, caseName); - if (existsSync(casePath)) { - rmSync(casePath, { recursive: true, force: true }); - } - } await server.stop(); }, 60000); diff --git a/test/quick-start.test.ts b/test/quick-start.test.ts index 38098643..099fb146 100644 --- a/test/quick-start.test.ts +++ b/test/quick-start.test.ts @@ -18,16 +18,20 @@ describe('Quick Start API', () => { baseUrl = `http://localhost:${TEST_PORT}`; }); - afterAll(async () => { - await server.stop(); - // Cleanup created test cases - for (const caseName of createdCases) { + afterEach(() => { + // Clean up cases created during this test + while (createdCases.length > 0) { + const caseName = createdCases.pop()!; const casePath = join(CASES_DIR, caseName); if (existsSync(casePath)) { rmSync(casePath, { recursive: true, force: true }); } } - }, 30000); // Increase timeout since server.stop() kills screen sessions + }); + + afterAll(async () => { + await server.stop(); + }, 30000); describe('POST /api/quick-start', () => { it('should create default testcase and start interactive session', async () => { diff --git a/test/ralph-integration.test.ts b/test/ralph-integration.test.ts index e48c761c..bafd2ef0 100644 --- a/test/ralph-integration.test.ts +++ b/test/ralph-integration.test.ts @@ -11,7 +11,7 @@ * Test port: 3125 */ -import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest'; import { WebServer } from '../src/web/server.js'; import { existsSync, rmSync } from 'node:fs'; import { join } from 'node:path'; @@ -32,6 +32,17 @@ describe('Ralph Integration Tests', () => { baseUrl = `http://localhost:${TEST_PORT}`; }); + afterEach(() => { + // Clean up cases created during this test + while (createdCases.length > 0) { + const caseName = createdCases.pop()!; + const casePath = join(CASES_DIR, caseName); + if (existsSync(casePath)) { + rmSync(casePath, { recursive: true, force: true }); + } + } + }); + afterAll(async () => { // Cleanup sessions for (const sessionId of createdSessions) { @@ -39,13 +50,6 @@ describe('Ralph Integration Tests', () => { await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' }); } catch {} } - // Cleanup cases - for (const caseName of createdCases) { - const casePath = join(CASES_DIR, caseName); - if (existsSync(casePath)) { - rmSync(casePath, { recursive: true, force: true }); - } - } await server.stop(); }, 60000); diff --git a/test/session-cleanup.test.ts b/test/session-cleanup.test.ts index 48696e9f..f1e7a07d 100644 --- a/test/session-cleanup.test.ts +++ b/test/session-cleanup.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll, afterEach, vi } from 'vitest'; import { WebServer } from '../src/web/server.js'; import { existsSync, rmSync } from 'node:fs'; import { join } from 'node:path'; @@ -24,6 +24,17 @@ describe('Session Cleanup', () => { baseUrl = `http://localhost:${TEST_PORT}`; }); + afterEach(() => { + // Clean up cases created during this test + while (createdCases.length > 0) { + const caseName = createdCases.pop()!; + const casePath = join(CASES_DIR, caseName); + if (existsSync(casePath)) { + rmSync(casePath, { recursive: true, force: true }); + } + } + }); + afterAll(async () => { // Cleanup all sessions for (const sessionId of createdSessions) { @@ -31,13 +42,6 @@ describe('Session Cleanup', () => { await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' }); } catch {} } - // Cleanup all cases - for (const caseName of createdCases) { - const casePath = join(CASES_DIR, caseName); - if (existsSync(casePath)) { - rmSync(casePath, { recursive: true, force: true }); - } - } await server.stop(); }, 60000);