This commit is contained in:
2025-12-04 17:07:59 +01:00
parent 60a3c82cd9
commit 88c6befc7c
33 changed files with 602 additions and 261 deletions

View File

@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest';

View File

@@ -1,4 +1,4 @@
import { describe, test, expect, beforeEach, afterEach } from 'vitest';
import { test, expect } from '@playwright/test';
import { execSync } from 'child_process';
/**
@@ -12,7 +12,7 @@ import { execSync } from 'child_process';
* RED Phase: This test MUST FAIL due to externalized modules
*/
describe('Electron Build Smoke Tests', () => {
test.describe('Electron Build Smoke Tests', () => {
test('should build Electron app without browser context errors', () => {
// When: Building the Electron companion app
let buildOutput: string;

View File

@@ -1,205 +1,34 @@
import { test, expect, Page, Request, Response } from '@playwright/test';
import * as fs from 'fs';
import * as path from 'path';
import { test, expect } from '@playwright/test';
interface RouteIssue {
route: string;
consoleErrors: string[];
consoleWarnings: string[];
networkFailures: Array<{
url: string;
status?: number;
failure?: string;
}>;
}
/**
* Recursively scans the Next.js app directory to discover all routes.
* Dynamic segments like [id] are replaced with "demo".
*/
function discoverRoutes(appDir: string): string[] {
const routes: Set<string> = new Set();
function scanDirectory(dir: string, routePrefix: string = ''): void {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
// Handle dynamic segments: [id] -> demo
const segment = entry.name.match(/^\[(.+)\]$/)
? 'demo'
: entry.name;
// Skip special Next.js directories
if (!entry.name.startsWith('_') && !entry.name.startsWith('.')) {
const newPrefix = routePrefix + '/' + segment;
scanDirectory(fullPath, newPrefix);
}
} else if (entry.isFile() && entry.name === 'page.tsx') {
// Found a page component - this defines a route
const route = routePrefix === '' ? '/' : routePrefix;
routes.add(route);
}
}
}
scanDirectory(appDir);
// Return sorted, deduplicated list
return Array.from(routes).sort();
}
/**
* Attaches listeners to capture console errors/warnings and network failures
* for a specific route visit.
*/
function setupIssueCapture(page: Page, issues: RouteIssue): void {
// Capture console errors and warnings
page.on('console', (msg) => {
const type = msg.type();
if (type === 'error') {
issues.consoleErrors.push(msg.text());
} else if (type === 'warning') {
issues.consoleWarnings.push(msg.text());
}
});
// Capture request failures
page.on('requestfailed', (request: Request) => {
issues.networkFailures.push({
url: request.url(),
failure: request.failure()?.errorText || 'Request failed',
});
});
// Capture non-2xx/3xx responses
page.on('response', (response: Response) => {
const status = response.status();
// Consider 4xx and 5xx as failures
if (status >= 400) {
issues.networkFailures.push({
url: response.url(),
status,
});
}
});
}
/**
* Formats aggregated issues into a readable failure report.
*/
function formatFailureReport(failedRoutes: RouteIssue[]): string {
const lines: string[] = [
'',
'========================================',
'SMOKE TEST FAILURES',
'========================================',
'',
test.describe('Website smoke - core pages render', () => {
const routes = [
{ path: '/', name: 'landing' },
{ path: '/dashboard', name: 'dashboard' },
{ path: '/drivers', name: 'drivers list' },
{ path: '/leagues', name: 'leagues list' },
{ path: '/profile', name: 'profile' },
{ path: '/teams', name: 'teams list' },
];
for (const issue of failedRoutes) {
lines.push(`Route: ${issue.route}`);
lines.push('----------------------------------------');
for (const route of routes) {
test(`renders ${route.name} page without console errors (${route.path})`, async ({ page }) => {
const consoleMessages: string[] = [];
if (issue.consoleErrors.length > 0) {
lines.push('Console Errors:');
issue.consoleErrors.forEach((err) => {
lines.push(` - ${err}`);
page.on('console', (msg) => {
const type = msg.type();
if (type === 'error') {
consoleMessages.push(`[${type}] ${msg.text()}`);
}
});
lines.push('');
}
if (issue.consoleWarnings.length > 0) {
lines.push('Console Warnings:');
issue.consoleWarnings.forEach((warn) => {
lines.push(` - ${warn}`);
});
lines.push('');
}
await page.goto(route.path, { waitUntil: 'networkidle' });
if (issue.networkFailures.length > 0) {
lines.push('Network Failures:');
issue.networkFailures.forEach((fail) => {
const statusPart = fail.status ? ` [${fail.status}]` : '';
const failurePart = fail.failure ? ` (${fail.failure})` : '';
lines.push(` - ${fail.url}${statusPart}${failurePart}`);
});
lines.push('');
}
await expect(page).toHaveTitle(/GridPilot/i);
lines.push('');
expect(
consoleMessages.length,
`Console errors on route ${route.path}:\n${consoleMessages.join('\n')}`,
).toBe(0);
});
}
lines.push('========================================');
return lines.join('\n');
}
test.describe('Website Smoke Test', () => {
test.describe.configure({ mode: 'serial' });
let allRoutes: string[];
test.beforeAll(() => {
// Discover all routes from the app directory
const appDir = path.resolve(process.cwd(), 'apps/website/app');
allRoutes = discoverRoutes(appDir);
console.log(`Discovered ${allRoutes.length} routes:`);
allRoutes.forEach((route) => console.log(` ${route}`));
});
test('all pages load without console errors or network failures', async ({ page }) => {
const failedRoutes: RouteIssue[] = [];
for (const route of allRoutes) {
const issues: RouteIssue = {
route,
consoleErrors: [],
consoleWarnings: [],
networkFailures: [],
};
// Setup listeners before navigation
setupIssueCapture(page, issues);
try {
// Navigate to the route and wait for network to settle
await page.goto(route, {
waitUntil: 'networkidle',
timeout: 30000,
});
// Small delay to catch any late console messages
await page.waitForTimeout(500);
} catch (error) {
// Navigation failure itself
issues.networkFailures.push({
url: route,
failure: `Navigation error: ${error instanceof Error ? error.message : String(error)}`,
});
}
// Remove listeners for next iteration
page.removeAllListeners('console');
page.removeAllListeners('requestfailed');
page.removeAllListeners('response');
// Check if this route had any issues
const hasIssues =
issues.consoleErrors.length > 0 ||
issues.consoleWarnings.length > 0 ||
issues.networkFailures.length > 0;
if (hasIssues) {
failedRoutes.push(issues);
}
}
// Report all failures at once
if (failedRoutes.length > 0) {
const report = formatFailureReport(failedRoutes);
expect(failedRoutes, report).toHaveLength(0);
}
});
});

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { Result } from '@/packages/shared/result/Result';
import { Result } from '@gridpilot/shared-result';
import { CheckoutConfirmation } from '@gridpilot/automation/domain/value-objects/CheckoutConfirmation';
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
import { CheckoutState } from '@gridpilot/automation/domain/value-objects/CheckoutState';

View File

@@ -1,11 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { ConfirmCheckoutUseCase } from '@/packages/automation/application/use-cases/ConfirmCheckoutUseCase';
import { Result } from '@/packages/shared/result/Result';
import { ConfirmCheckoutUseCase } from '@gridpilot/automation/application/use-cases/ConfirmCheckoutUseCase';
import { Result } from '@gridpilot/shared-result';
import { CheckoutPrice } from '@gridpilot/automation/domain/value-objects/CheckoutPrice';
import { CheckoutState } from '@gridpilot/automation/domain/value-objects/CheckoutState';
import { CheckoutConfirmation } from '@gridpilot/automation/domain/value-objects/CheckoutConfirmation';
import type { ICheckoutService } from '@/packages/automation/application/ports/ICheckoutService';
import type { ICheckoutConfirmationPort } from '@/packages/automation/application/ports/ICheckoutConfirmationPort';
import type { ICheckoutService } from '@gridpilot/automation/application/ports/ICheckoutService';
import type { ICheckoutConfirmationPort } from '@gridpilot/automation/application/ports/ICheckoutConfirmationPort';
describe('ConfirmCheckoutUseCase - Enhanced with Confirmation Port', () => {
let mockCheckoutService: ICheckoutService;

View File

@@ -1,6 +1,6 @@
import { describe, test, expect, beforeEach, vi } from 'vitest';
import type { Page } from 'playwright';
import { AuthenticationGuard } from 'packages/automation/infrastructure/adapters/automation/auth/AuthenticationGuard';
import { AuthenticationGuard } from '@gridpilot/automation/infrastructure/adapters/automation/auth/AuthenticationGuard';
describe('AuthenticationGuard', () => {
let mockPage: Page;

View File

@@ -1,5 +1,5 @@
import { describe, test, expect, beforeEach } from 'vitest';
import { SessionCookieStore } from 'packages/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
import { SessionCookieStore } from '@gridpilot/automation/infrastructure/adapters/automation/auth/SessionCookieStore';
import type { Cookie } from 'playwright';
describe('SessionCookieStore - Cookie Validation', () => {

View File

@@ -51,13 +51,13 @@ describe('InMemoryAuthService', () => {
expect(session.user.primaryDriverId).not.toBe('');
});
it('logout does not attempt to modify cookies directly', async () => {
it('logout clears the demo session cookie via adapter', async () => {
const service = new InMemoryAuthService();
await service.logout();
expect(cookieStore.get).not.toHaveBeenCalled();
expect(cookieStore.set).not.toHaveBeenCalled();
expect(cookieStore.delete).not.toHaveBeenCalled();
expect(cookieStore.delete).toHaveBeenCalledWith('gp_demo_session');
});
});