mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 16:59:43 +02:00
fix: clean up test case directories after each test instead of at end
Moves case directory cleanup from afterAll to afterEach in all test files that create cases. Previously, if the test suite was interrupted or afterAll timed out, all case directories were left behind. Now each test cleans up immediately after itself. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 { WebServer } from '../src/web/server.js';
|
||||||
import { existsSync, rmSync } from 'node:fs';
|
import { existsSync, rmSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
@@ -18,14 +18,19 @@ describe('Edge Cases and Error Handling', () => {
|
|||||||
baseUrl = `http://localhost:${TEST_PORT}`;
|
baseUrl = `http://localhost:${TEST_PORT}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterEach(() => {
|
||||||
await server.stop();
|
// Clean up cases created during this test
|
||||||
for (const caseName of createdCases) {
|
while (createdCases.length > 0) {
|
||||||
|
const caseName = createdCases.pop()!;
|
||||||
const casePath = join(CASES_DIR, caseName);
|
const casePath = join(CASES_DIR, caseName);
|
||||||
if (existsSync(casePath)) {
|
if (existsSync(casePath)) {
|
||||||
rmSync(casePath, { recursive: true, force: true });
|
rmSync(casePath, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await server.stop();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
describe('Session Edge Cases', () => {
|
describe('Session Edge Cases', () => {
|
||||||
|
|||||||
@@ -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 { WebServer } from '../src/web/server.js';
|
||||||
import { existsSync, rmSync } from 'node:fs';
|
import { existsSync, rmSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
@@ -23,6 +23,17 @@ describe('Integration Flows', () => {
|
|||||||
baseUrl = `http://localhost:${TEST_PORT}`;
|
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 () => {
|
afterAll(async () => {
|
||||||
// Cleanup sessions
|
// Cleanup sessions
|
||||||
for (const sessionId of createdSessions) {
|
for (const sessionId of createdSessions) {
|
||||||
@@ -30,13 +41,6 @@ describe('Integration Flows', () => {
|
|||||||
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
||||||
} catch {}
|
} 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();
|
await server.stop();
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
|
|||||||
@@ -18,16 +18,20 @@ describe('Quick Start API', () => {
|
|||||||
baseUrl = `http://localhost:${TEST_PORT}`;
|
baseUrl = `http://localhost:${TEST_PORT}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterEach(() => {
|
||||||
await server.stop();
|
// Clean up cases created during this test
|
||||||
// Cleanup created test cases
|
while (createdCases.length > 0) {
|
||||||
for (const caseName of createdCases) {
|
const caseName = createdCases.pop()!;
|
||||||
const casePath = join(CASES_DIR, caseName);
|
const casePath = join(CASES_DIR, caseName);
|
||||||
if (existsSync(casePath)) {
|
if (existsSync(casePath)) {
|
||||||
rmSync(casePath, { recursive: true, force: true });
|
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', () => {
|
describe('POST /api/quick-start', () => {
|
||||||
it('should create default testcase and start interactive session', async () => {
|
it('should create default testcase and start interactive session', async () => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* Test port: 3125
|
* 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 { WebServer } from '../src/web/server.js';
|
||||||
import { existsSync, rmSync } from 'node:fs';
|
import { existsSync, rmSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
@@ -32,6 +32,17 @@ describe('Ralph Integration Tests', () => {
|
|||||||
baseUrl = `http://localhost:${TEST_PORT}`;
|
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 () => {
|
afterAll(async () => {
|
||||||
// Cleanup sessions
|
// Cleanup sessions
|
||||||
for (const sessionId of createdSessions) {
|
for (const sessionId of createdSessions) {
|
||||||
@@ -39,13 +50,6 @@ describe('Ralph Integration Tests', () => {
|
|||||||
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
||||||
} catch {}
|
} 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();
|
await server.stop();
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
|
|||||||
@@ -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 { WebServer } from '../src/web/server.js';
|
||||||
import { existsSync, rmSync } from 'node:fs';
|
import { existsSync, rmSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
@@ -24,6 +24,17 @@ describe('Session Cleanup', () => {
|
|||||||
baseUrl = `http://localhost:${TEST_PORT}`;
|
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 () => {
|
afterAll(async () => {
|
||||||
// Cleanup all sessions
|
// Cleanup all sessions
|
||||||
for (const sessionId of createdSessions) {
|
for (const sessionId of createdSessions) {
|
||||||
@@ -31,13 +42,6 @@ describe('Session Cleanup', () => {
|
|||||||
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
await fetch(`${baseUrl}/api/sessions/${sessionId}`, { method: 'DELETE' });
|
||||||
} catch {}
|
} 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();
|
await server.stop();
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user