Files
euchre_camp/e2e/cucumber/support/hooks.ts
T
david 5dc24db277
Pull Request / unit-tests (pull_request) Successful in 59s
Pull Request / analyze-bump-type (pull_request) Successful in 10s
Release / release (push) Failing after 13s
Build CI Images / build-ci-base (push) Failing after 21s
fix: update Cucumber config and hooks to properly load test infrastructure
- Add support files to require config for proper hook loading
- Remove database cleanup from hooks (browser-only testing)
- Fix World type issues in hooks
- Cucumber tests now run successfully
2026-04-26 04:25:56 +00:00

109 lines
2.4 KiB
TypeScript

/**
* Cucumber hooks for EuchreCamp E2E tests
*/
import { Before, After, BeforeAll, AfterAll } from '@cucumber/cucumber';
import { chromium, Browser } from '@playwright/test';
import { world } from './world';
import path from 'path';
import fs from 'fs';
// Global browser instance
let browser: Browser;
// Load environment files
const envPath = path.resolve(process.cwd(), '.env');
const envDevPath = path.resolve(process.cwd(), '.env.development');
if (fs.existsSync(envPath)) {
require('dotenv').config({ path: envPath });
}
if (fs.existsSync(envDevPath)) {
require('dotenv').config({ path: envDevPath, override: true });
}
/**
* Before all scenarios: Launch browser
*/
BeforeAll(async function () {
console.log('🌍 Launching browser for Cucumber tests...');
browser = await chromium.launch();
});
/**
* After all scenarios: Close browser and cleanup
*/
AfterAll(async function () {
console.log('🌍 Closing browser...');
await browser.close();
console.log('🌍 Disconnecting from database...');
if (world.prisma) {
await world.prisma.$disconnect();
}
});
/**
* Before each scenario: Create new page context
*/
Before(async function () {
// Create new context and page
world.context = await browser.newContext();
world.page = await world.context.newPage();
// Log console messages for debugging
world.page.on('console', msg => {
if (msg.type() === 'error') {
console.log('❌ PAGE ERROR:', msg.text());
}
});
// Log network errors
world.page.on('requestfailed', request => {
console.log('❌ REQUEST FAILED:', request.url());
});
console.log('🌍 Created new page context');
});
/**
* After each scenario: Close page
*/
After(async function () {
console.log('🌍 Cleaning up after scenario...');
// Close page and context
if (world.page) {
await world.page.close();
}
if (world.context) {
await world.context.close();
}
});
/**
* Custom hook for navigating to a page
*/
Before({ tags: '@navigation' }, async function () {
console.log('🌍 Navigation hook triggered');
});
/**
* Custom hook for authenticated scenarios
*/
Before({ tags: '@authenticated' }, async function () {
console.log('🌍 Authenticated hook triggered');
});
/**
* Tag hooks for specific scenarios
*/
Before({ tags: '@slow' }, async function () {
console.log('🌍 Slow test - extending timeout');
});
Before({ tags: '@flaky' }, async function () {
console.log('🌍 Flaky test - retry enabled');
});