Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .github/workflows/playwright_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Playwright Tests

on:
workflow_call:
inputs:
environment:
description: 'Environment to run tests against'
required: false
type: string
default: 'test'
push:
branches:
- main
pull_request:
types: [opened, synchronize]

env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/coreyja_test
APP_BASE_URL: http://localhost:3000
SQLX_OFFLINE: true
# Required environment variables for app startup (using test/fake values)
OPEN_AI_API_KEY: test-openai-api-key
ANTHROPIC_API_KEY: test-anthropic-api-key
GITHUB_APP_ID: 123456
GITHUB_APP_CLIENT_ID: test-github-client-id
GITHUB_APP_CLIENT_SECRET: test-github-client-secret
GITHUB_PERSONAL_ACCESS_TOKEN: test-github-pat
GITHUB_APP_PRIVATE_KEY: |
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA0Z3VS0JJcds3xg
-----END RSA PRIVATE KEY-----
TWITCH_CLIENT_ID: test-twitch-client-id
TWITCH_CLIENT_SECRET: test-twitch-client-secret
TWITCH_BOT_USER_ID: 123456789
TWITCH_CHANNEL_USER_ID: 987654321
ENCRYPTION_SECRET_KEY: test-encryption-secret-key-32-bytes-long!
GOOGLE_CLIENT_ID: test-google-client-id
GOOGLE_CLIENT_SECRET: test-google-client-secret
DISCORD_TOKEN: test-discord-token
DISCORD_BOT_DISABLED: true
COOKIE_KEY: test-cookie-key-32-bytes-long!!!!

jobs:
playwright:
name: E2E Tests
runs-on: ubuntu-latest
timeout-minutes: 30

services:
postgres:
image: postgres:15
env:
POSTGRES_DB: coreyja_test
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: |
thread-frontend/package-lock.json
e2e/package-lock.json

- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

- name: Install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: protobuf-compiler libasound2-dev
version: v0

- name: Install Tailwind CSS
run: |
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \
chmod +x tailwindcss-linux-x64 && \
mv tailwindcss-linux-x64 tailwindcss && \
./tailwindcss -i server/src/styles/tailwind.css -o target/tailwind.css

- name: Install frontend dependencies
run: |
cd thread-frontend
npm ci

- name: Build frontend
run: ./scripts/build-frontend.sh

- name: Run database migrations
run: |
cargo install sqlx-cli --no-default-features --features postgres || true
sqlx migrate run --source db/migrations

- name: Build server (debug mode for speed)
run: cargo build --bin server

- name: Install Playwright dependencies
run: |
cd e2e
npm ci

- name: Install Playwright browsers
run: |
cd e2e
npx playwright install --with-deps chromium

- name: Run Playwright tests
run: |
cd e2e
npx playwright test
env:
CI: true

- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: e2e/test-results/
retention-days: 30
5 changes: 5 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
playwright-report/
test-results/
.DS_Store
*.log
51 changes: 51 additions & 0 deletions e2e/auth/github-oauth-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Page } from '@playwright/test';

export interface MockUser {
login: string;
node_id: string;
id: number;
email: string;
name: string;
}

export async function setupGitHubOAuthMock(page: Page, user: MockUser) {
// Intercept GitHub OAuth authorization
await page.route('https://github.com/login/oauth/authorize**', async route => {
const url = new URL(route.request().url());
const redirectUri = url.searchParams.get('redirect_uri');
const state = url.searchParams.get('state');

// Immediately redirect back with mock code
await route.fulfill({
status: 302,
headers: {
'Location': `${redirectUri}?code=mock_code_${Date.now()}&state=${state}`
}
});
});

// Mock token exchange
await page.route('https://github.com/login/oauth/access_token', async route => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
access_token: `mock_token_${Date.now()}`,
expires_in: 28800,
refresh_token: `mock_refresh_${Date.now()}`,
refresh_token_expires_in: 15897600,
scope: 'read:user user:email',
token_type: 'bearer'
})
});
});

// Mock user API
await page.route('https://api.github.com/user', async route => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(user)
});
});
}
16 changes: 16 additions & 0 deletions e2e/fixtures/test-users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const testUsers = {
admin: {
login: 'test_admin',
node_id: 'MDQ6VXNlcjE=',
id: 1,
email: '[email protected]',
name: 'Test Admin'
},
regular: {
login: 'test_user',
node_id: 'MDQ6VXNlcjI=',
id: 2,
email: '[email protected]',
name: 'Test User'
}
};
97 changes: 97 additions & 0 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "e2e",
"version": "1.0.0",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "playwright test",
"test:ui": "playwright test --ui",
"test:debug": "playwright test --debug",
"test:headed": "playwright test --headed",
"test:report": "playwright show-report"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.54.2",
"@types/node": "^24.2.1"
}
}
35 changes: 35 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: './tests',
timeout: 30000,
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',

use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],

webServer: {
command: process.env.CI
? 'cd .. && ./target/debug/server'
: 'cd .. && ./scripts/dev-build.sh && ./target/debug/server',
port: 3000,
reuseExistingServer: !process.env.CI,
timeout: 120000,
stdout: 'pipe',
stderr: 'pipe',
},
});
Loading
Loading