feat: Add comprehensive testing infrastructure
Implements robust testing setup with Playwright global auth, reusable test helpers, Docker support, and CI/CD integration with Gitea Actions. ## Changes ### Playwright Setup - Add global auth setup with storage state reuse (tests/playwright/auth.setup.ts) - Fix auth setup to clear existing state before fresh login - Create reusable performOAuthLogin helper (tests/playwright/helpers.ts) - Configure dotenv loading for environment variables in playwright.config.ts ### Magnitude Configuration - Update to use Claude Sonnet 4.5 (claude-sonnet-4-5-20250514) - Create reusable loginFlow helper (tests/magnitude/helpers.ts) - Fix smoke test to check login page instead of non-existent homepage ### Docker Support - Add Dockerfile.playwright with non-root user (pwuser) for security - Uses official Playwright Docker image (mcr.microsoft.com/playwright:v1.49.1-noble) - Provides consistent testing environment across users and CI/CD ### CI/CD Integration - Add Gitea Actions workflow (.gitea/workflows/magnitude.yml) - Runs Magnitude tests on every push and PR - Starts SurrealDB and Next.js dev server automatically - Uploads test results as artifacts (30-day retention) ### Documentation - Add comprehensive testing setup docs to AGENTS.md: - Playwright Docker setup instructions - CI/CD with Gitea Actions - Testing framework separation (Playwright vs Magnitude) - Required secrets for CI/CD ### Testing Best Practices - Separate Playwright (manual + global auth) from Magnitude (automated E2E) - Reusable helpers reduce code duplication - Both frameworks work independently ## Testing - ✅ Playwright auth setup test passes (5.6s) - ✅ Magnitude smoke test passes - ✅ OAuth flow works correctly with helper function 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
import { test as setup, expect } from '@playwright/test';
|
||||
import { test as setup } from '@playwright/test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { performOAuthLogin } from './helpers';
|
||||
|
||||
const authFile = 'tests/playwright/.auth/user.json';
|
||||
|
||||
setup('authenticate', async ({ page }) => {
|
||||
// For now, just create an empty auth file
|
||||
// TODO: Implement actual OAuth flow when test credentials are available
|
||||
console.log('[Auth Setup] Skipping authentication - implement OAuth flow with test credentials');
|
||||
console.log('[Auth Setup] Starting OAuth authentication flow');
|
||||
|
||||
// Save empty state for now
|
||||
// Clear any existing auth state file to ensure fresh login
|
||||
if (fs.existsSync(authFile)) {
|
||||
fs.unlinkSync(authFile);
|
||||
console.log('[Auth Setup] Cleared existing auth state');
|
||||
}
|
||||
|
||||
// Perform OAuth login using reusable helper
|
||||
await performOAuthLogin(page);
|
||||
|
||||
// Ensure the auth directory exists
|
||||
const authDir = path.dirname(authFile);
|
||||
if (!fs.existsSync(authDir)) {
|
||||
fs.mkdirSync(authDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Save authenticated state
|
||||
await page.context().storageState({ path: authFile });
|
||||
console.log(`[Auth Setup] Saved authentication state to ${authFile}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user