import { beforeAll, afterAll, beforeEach, afterEach } from 'vitest'; import { IntegrationTestHarness, createTestHarness } from './index'; import { ApiClient } from './api-client'; import { DatabaseManager } from './database-manager'; import { DataFactory } from './data-factory'; /** * Shared test context for harness-related integration tests. * Provides a DRY setup for tests that verify the harness infrastructure itself. */ export class HarnessTestContext { private harness: IntegrationTestHarness; constructor() { this.harness = createTestHarness(); } get api(): ApiClient { return this.harness.getApi(); } get db(): DatabaseManager { return this.harness.getDatabase(); } get factory(): DataFactory { return this.harness.getFactory(); } get testHarness(): IntegrationTestHarness { return this.harness; } /** * Standard setup for harness tests */ async setup() { await this.harness.beforeAll(); } /** * Standard teardown for harness tests */ async teardown() { await this.harness.afterAll(); } /** * Standard per-test setup */ async reset() { await this.harness.beforeEach(); } } /** * Helper to create and register a HarnessTestContext with Vitest hooks */ export function setupHarnessTest() { const context = new HarnessTestContext(); beforeAll(async () => { await context.setup(); }); afterAll(async () => { await context.teardown(); }); beforeEach(async () => { await context.reset(); }); return context; }