From 025b195800026d85b1590c5bc7b3e84e0df56ec9 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Sun, 29 Mar 2026 19:24:52 -0700 Subject: [PATCH] ci: add test configuration files for Playwright and Vitest --- playwright.config.ts | 74 ++++++++++++++++++++++++++++++++++++++++++++ vitest.config.mts | 18 +++++++++++ vitest.setup.ts | 1 + 3 files changed, 93 insertions(+) create mode 100644 playwright.config.ts create mode 100644 vitest.config.mts create mode 100644 vitest.setup.ts diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..d4c8ea2 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,74 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './src/__tests__/e2e', + timeout: 30000, + expect: { + timeout: 5000 + }, + // Run tests sequentially to avoid database conflicts with SQLite + fullyParallel: false, + // Fail the build on CI if you accidentally left test.only in the source code. + forbidOnly: !!process.env.CI, + // Retry on CI only. + retries: process.env.CI ? 2 : 0, + // Always run with 1 worker to avoid database conflicts with SQLite + workers: 1, + // Reporter to use + reporter: 'html', + // Global setup and teardown + globalSetup: require.resolve('./src/__tests__/e2e/global.setup'), + // Use base URL for relative navigation + use: { + baseURL: 'http://localhost:3000', + // Collect trace when retrying the failed test. + trace: 'on-first-retry', + // Capture screenshot only on failure + screenshot: 'only-on-failure', + }, + // Configure projects + projects: [ + // Setup project - runs before all other projects + { + name: 'setup', + testMatch: /global\.setup\.ts/, + }, + // Main Chromium project with regular user authentication + { + name: 'chromium', + use: { + ...devices['Desktop Chrome'], + // Use prepared auth state for regular user tests + storageState: 'playwright/.auth/user.json', + }, + dependencies: ['setup'], + }, + // Admin user project + { + name: 'chromium-admin', + use: { + ...devices['Desktop Chrome'], + // Use prepared auth state for admin tests + storageState: 'playwright/.auth/admin.json', + }, + dependencies: ['setup'], + }, + // Unauthenticated project - for tests that don't require login + { + name: 'chromium-unauth', + use: { + ...devices['Desktop Chrome'], + // No authentication state + storageState: undefined, + }, + dependencies: ['setup'], + }, + ], + // Run your local dev server before starting the tests + webServer: { + command: 'npm run dev', + url: 'http://localhost:3000', + timeout: 120000, + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/vitest.config.mts b/vitest.config.mts new file mode 100644 index 0000000..1264c35 --- /dev/null +++ b/vitest.config.mts @@ -0,0 +1,18 @@ +import { defineConfig } from 'vitest/config' +import react from '@vitejs/plugin-react' +import path from 'path' + +export default defineConfig({ + plugins: [react()], + test: { + environment: 'jsdom', + setupFiles: ['./vitest.setup.ts'], + globals: true, + exclude: ['**/e2e/**', '**/node_modules/**'], + }, + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, +}) diff --git a/vitest.setup.ts b/vitest.setup.ts new file mode 100644 index 0000000..c44951a --- /dev/null +++ b/vitest.setup.ts @@ -0,0 +1 @@ +import '@testing-library/jest-dom'