wip
This commit is contained in:
@@ -41,6 +41,9 @@ import { permissionGuard, shouldSkipRealAutomationTests } from './support/Permis
|
||||
const IRACING_URL = 'https://members-ng.iracing.com/web/racing/hosted/browse-sessions';
|
||||
const WINDOW_TITLE_PATTERN = 'iRacing';
|
||||
|
||||
const RUN_REAL_AUTOMATION_SMOKE = process.env.RUN_REAL_AUTOMATION_SMOKE === '1';
|
||||
const describeSmoke = RUN_REAL_AUTOMATION_SMOKE ? describe : describe.skip;
|
||||
|
||||
let skipReason: string | null = null;
|
||||
let browserProcess: ChildProcess | null = null;
|
||||
|
||||
@@ -85,7 +88,7 @@ async function closeBrowser(): Promise<void> {
|
||||
browserProcess = null;
|
||||
}
|
||||
|
||||
describe('E2E Real Automation Tests - REAL iRacing Website', () => {
|
||||
describeSmoke('Real automation smoke – REAL iRacing Website', () => {
|
||||
beforeAll(async () => {
|
||||
// Check permissions first
|
||||
skipReason = await shouldSkipRealAutomationTests() ?? null;
|
||||
|
||||
153
tests/e2e/workflows/full-hosted-session.workflow.e2e.test.ts
Normal file
153
tests/e2e/workflows/full-hosted-session.workflow.e2e.test.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import {
|
||||
PlaywrightAutomationAdapter,
|
||||
FixtureServer,
|
||||
} from 'packages/infrastructure/adapters/automation';
|
||||
import { InMemorySessionRepository } from 'packages/infrastructure/repositories/InMemorySessionRepository';
|
||||
import { MockAutomationEngineAdapter } from 'packages/infrastructure/adapters/automation/engine/MockAutomationEngineAdapter';
|
||||
import { MockBrowserAutomationAdapter } from 'packages/infrastructure/adapters/automation/engine/MockBrowserAutomationAdapter';
|
||||
import { StartAutomationSessionUseCase } from 'packages/application/use-cases/StartAutomationSessionUseCase';
|
||||
import { StepId } from 'packages/domain/value-objects/StepId';
|
||||
|
||||
describe('Workflow – hosted session end-to-end (fixture-backed)', () => {
|
||||
let server: FixtureServer;
|
||||
let adapter: PlaywrightAutomationAdapter;
|
||||
let baseUrl: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
server = new FixtureServer();
|
||||
const info = await server.start();
|
||||
baseUrl = info.url;
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter(
|
||||
{
|
||||
headless: true,
|
||||
timeout: 10_000,
|
||||
baseUrl,
|
||||
mode: 'mock',
|
||||
},
|
||||
);
|
||||
const connectResult = await adapter.connect();
|
||||
expect(connectResult.success).toBe(true);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await adapter.disconnect();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
function createFixtureEngine() {
|
||||
const repository = new InMemorySessionRepository();
|
||||
const engine = new MockAutomationEngineAdapter(adapter, repository);
|
||||
const useCase = new StartAutomationSessionUseCase(engine, adapter, repository);
|
||||
return { repository, engine, useCase };
|
||||
}
|
||||
|
||||
it('runs 1–18 from use case to STOPPED_AT_STEP_18', async () => {
|
||||
const { repository, engine, useCase } = createFixtureEngine();
|
||||
|
||||
const config: any = {
|
||||
sessionName: 'Fixture E2E – full workflow',
|
||||
trackId: 'spa',
|
||||
carIds: ['dallara-f3'],
|
||||
};
|
||||
|
||||
const dto = await useCase.execute(config);
|
||||
|
||||
expect(dto.state).toBe('PENDING');
|
||||
expect(dto.currentStep).toBe(1);
|
||||
|
||||
await engine.executeStep(StepId.create(1), config);
|
||||
|
||||
const deadline = Date.now() + 60_000;
|
||||
let finalSession = null;
|
||||
|
||||
// Poll repository until automation loop completes
|
||||
// MockAutomationEngineAdapter drives the step orchestrator internally.
|
||||
// Session should end in STOPPED_AT_STEP_18 when step 18 completes.
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const sessions = await repository.findAll();
|
||||
finalSession = sessions[0] ?? null;
|
||||
|
||||
if (finalSession && (finalSession.state.isStoppedAtStep18() || finalSession.state.isFailed())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (Date.now() > deadline) {
|
||||
throw new Error('Timed out waiting for automation workflow to complete');
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
}
|
||||
|
||||
expect(finalSession).not.toBeNull();
|
||||
expect(finalSession!.state.isStoppedAtStep18()).toBe(true);
|
||||
expect(finalSession!.currentStep.value).toBe(18);
|
||||
expect(finalSession!.startedAt).toBeInstanceOf(Date);
|
||||
expect(finalSession!.completedAt).toBeInstanceOf(Date);
|
||||
expect(finalSession!.errorMessage).toBeUndefined();
|
||||
});
|
||||
|
||||
it('marks session as FAILED on mid-flow automation error with diagnostics', async () => {
|
||||
const repository = new InMemorySessionRepository();
|
||||
const failingAdapter = new MockBrowserAutomationAdapter({
|
||||
simulateFailures: true,
|
||||
failureRate: 1.0,
|
||||
});
|
||||
await failingAdapter.connect();
|
||||
|
||||
const engine = new MockAutomationEngineAdapter(
|
||||
failingAdapter as any,
|
||||
repository,
|
||||
);
|
||||
const useCase = new StartAutomationSessionUseCase(
|
||||
engine,
|
||||
failingAdapter as any,
|
||||
repository,
|
||||
);
|
||||
|
||||
const config: any = {
|
||||
sessionName: 'Fixture E2E – failure workflow',
|
||||
trackId: 'spa',
|
||||
carIds: ['dallara-f3'],
|
||||
};
|
||||
|
||||
const dto = await useCase.execute(config);
|
||||
|
||||
expect(dto.state).toBe('PENDING');
|
||||
expect(dto.currentStep).toBe(1);
|
||||
|
||||
await engine.executeStep(StepId.create(1), config);
|
||||
|
||||
const deadline = Date.now() + 30_000;
|
||||
let finalSession = null;
|
||||
|
||||
// Poll for failure state
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const sessions = await repository.findAll();
|
||||
finalSession = sessions[0] ?? null;
|
||||
|
||||
if (finalSession && (finalSession.state.isFailed() || finalSession.state.isStoppedAtStep18())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (Date.now() > deadline) {
|
||||
throw new Error('Timed out waiting for automation workflow to fail');
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
}
|
||||
|
||||
await failingAdapter.disconnect();
|
||||
|
||||
expect(finalSession).not.toBeNull();
|
||||
expect(
|
||||
finalSession!.state.isFailed() || finalSession!.state.isStoppedAtStep18(),
|
||||
).toBe(true);
|
||||
if (finalSession!.state.isFailed()) {
|
||||
expect(finalSession!.errorMessage).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,28 +1,35 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import path from 'path';
|
||||
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
|
||||
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/infrastructure/adapters/automation';
|
||||
import { StepId } from 'packages/domain/value-objects/StepId';
|
||||
|
||||
describe('Workflow – steps 7–9 cars flow', () => {
|
||||
describe('Workflow – steps 7–9 cars flow (fixture-backed)', () => {
|
||||
let adapter: PlaywrightAutomationAdapter;
|
||||
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
|
||||
let server: FixtureServer;
|
||||
let baseUrl: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
adapter = new PlaywrightAutomationAdapter({
|
||||
headless: true,
|
||||
timeout: 5000,
|
||||
baseUrl: fixtureBaseUrl,
|
||||
mode: 'mock',
|
||||
});
|
||||
server = new FixtureServer();
|
||||
const info = await server.start();
|
||||
baseUrl = info.url;
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter(
|
||||
{
|
||||
headless: true,
|
||||
timeout: 5000,
|
||||
baseUrl,
|
||||
mode: 'mock',
|
||||
}
|
||||
);
|
||||
await adapter.connect();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await adapter.disconnect();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('executes time limits, cars, and add car in sequence', async () => {
|
||||
await adapter.navigateToPage(`${fixtureBaseUrl}/step-07-time-limits.html`);
|
||||
it('executes time limits, cars, and add car in sequence using fixtures', async () => {
|
||||
await adapter.navigateToPage(server.getFixtureUrl(7));
|
||||
const step7Result = await adapter.executeStep(StepId.create(7), {
|
||||
practice: 10,
|
||||
qualify: 10,
|
||||
@@ -30,11 +37,11 @@ describe('Workflow – steps 7–9 cars flow', () => {
|
||||
});
|
||||
expect(step7Result.success).toBe(true);
|
||||
|
||||
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
|
||||
await adapter.navigateToPage(server.getFixtureUrl(8));
|
||||
const step8Result = await adapter.executeStep(StepId.create(8), {});
|
||||
expect(step8Result.success).toBe(true);
|
||||
|
||||
await adapter.navigateToPage(`${fixtureBaseUrl}/step-09-add-car.html`);
|
||||
await adapter.navigateToPage(server.getFixtureUrl(9));
|
||||
const step9Result = await adapter.executeStep(StepId.create(9), {
|
||||
carSearch: 'Porsche 911 GT3 R',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user