A comprehensive end-to-end testing suite has been implemented for OpenSaaS Stack using Playwright. The test suite validates builds, authentication, access control, CRUD operations, and admin UI functionality.
playwright.config.ts- Main Playwright configuratione2e/- Test directory structure.gitignore- Updated to exclude test artifacts
e2e/utils/auth.ts- Authentication helper functions (signUp, signIn, etc.)e2e/utils/db.ts- Database setup and cleanup utilitiese2e/global-setup.ts- Pre-test environment setupe2e/global-teardown.ts- Post-test cleanup
e2e/README.md- Comprehensive testing guideE2E_TESTING_SUMMARY.md- This summary document
Tests that ensure the example builds correctly:
- ✅ Project builds without errors
- ✅ Schema and types generate successfully
- ✅ No TypeScript compilation errors
- ✅ Required dependencies are installed
- ✅ Valid environment configuration
- ✅ Valid Next.js and OpenSaaS configuration
Comprehensive authentication flow testing:
Sign Up Tests:
- Successful user registration
- Email validation (invalid format)
- Password validation (minimum 8 characters)
- Duplicate email prevention
Sign In Tests:
- Successful login with correct credentials
- Error handling for incorrect password
- Error handling for non-existent user
Password Reset Tests:
- Password reset page display
- Email submission for reset link
Session Management:
- Session persistence across page reloads
- Session persistence across navigation
Tests validating the core access control system:
Unauthenticated Access:
- Prevents post creation without authentication
- Shows only published posts to public users
Post Creation (CRUD):
- Authenticated users can create posts
- Required field validation
- Custom validation (spam detection in title)
- Unique slug constraint enforcement
- Auto-set publishedAt timestamp on status change
Update Access Control:
- Authors can update their own posts
- Non-authors cannot update others' posts
Delete Access Control:
- Authors can delete their own posts
Field-level Access Control:
- Only authors can read the internalNotes field
- Non-authors cannot see private fields
Tests for the admin interface functionality:
Navigation:
- Admin UI accessible at /admin
- Navigation between lists (Post, User)
List Table View:
- Empty state display
- Posts appear after creation
- Multiple columns render correctly
Create Form:
- All fields render (text, textarea, select)
- Field labels display correctly
- Proper field types and options
Edit Form:
- Form populates with existing data
- Changes save successfully
Form Validation UI:
- Inline validation errors display
- Errors clear when fields are corrected
Auto-generated Lists:
- User list displays (from authPlugin)
- User fields render in table
Added npm scripts to root package.json:
{
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:headed": "playwright test --headed",
"test:e2e:debug": "playwright test --debug",
"test:e2e:codegen": "playwright codegen http://localhost:3000"
}# 1. Install dependencies (if not already done)
pnpm install
# 2. Install Playwright browsers (first time only)
pnpm exec playwright install
# 3. Build required packages
pnpm --filter @opensaas/stack-core build
pnpm --filter @opensaas/stack-auth build
pnpm --filter @opensaas/stack-ui build
pnpm --filter @opensaas/stack-cli build
# 4. Run all E2E tests
pnpm test:e2e# Run tests with UI (recommended for development)
pnpm test:e2e:ui
# Run tests in headed mode (see browser)
pnpm test:e2e:headed
# Debug specific test
pnpm test:e2e:debug
# Generate test code by recording interactions
pnpm test:e2e:codegen# Run only authentication tests
pnpm exec playwright test e2e/starter-auth/01-auth.spec.ts
# Run a specific test by name
pnpm exec playwright test -g "should successfully sign up"
# Run only build validation
pnpm exec playwright test e2e/starter-auth/00-build.spec.ts-
Before Tests (
global-setup.ts):- Creates
.envfile from.env.exampleif needed - Sets test environment variables
- Runs database setup (generate schema, db push)
- Creates
-
Test Execution:
- Playwright starts Next.js dev server automatically
- Each test file runs with fresh browser context
- Tests share database state from global setup
-
After Tests (
global-teardown.ts):- Cleans up test database
- Playwright stops dev server
Authentication Helpers (e2e/utils/auth.ts):
import { signUp, signIn, testUser } from '../utils/auth.js'
// Sign up a new user
await signUp(page, testUser)
// Sign in existing user
await signIn(page, { email: 'user@example.com', password: 'pass123' })Database Utilities (e2e/utils/db.ts):
import { setupDatabase, cleanupDatabase } from '../utils/db.js'
// Setup fresh database
setupDatabase('examples/starter-auth')
// Clean up after tests
cleanupDatabase('examples/starter-auth')- Build Validation: 7 tests
- Authentication: 13 tests
- CRUD & Access Control: 10 tests
- Admin UI: 15 tests
- ✅ Project builds and TypeScript compilation
- ✅ Schema generation and database setup
- ✅ User registration and sign-in flows
- ✅ Password validation and reset
- ✅ Session management and persistence
- ✅ Operation-level access control (query, create, update, delete)
- ✅ Field-level access control (read, create, update)
- ✅ CRUD operations (Create, Read, Update, Delete)
- ✅ Data validation (required fields, custom validators, constraints)
- ✅ Hooks (resolveInput, validateInput)
- ✅ Admin UI rendering and navigation
- ✅ Form functionality (create, edit, validation)
- ✅ Table views and data display
- ✅ Auto-generated lists from plugins
E2E tests are fully integrated into the main GitHub Actions test workflow (.github/workflows/test.yml).
Runs on all pull requests to main:
- Executes E2E tests as part of the main test suite
- Runs alongside unit tests, linting, and formatting checks
- 30-minute timeout for long-running tests
- Uploads test reports and artifacts (screenshots, traces)
When CI=true is set, Playwright will:
- ✅ Use GitHub Actions reporter for better CI output
- ✅ Retry failed tests twice automatically
- ✅ Run with single worker (no parallelization)
- ✅ Not reuse existing dev servers
- ✅ Upload screenshots and traces on failure
On test completion:
- playwright-report/ - HTML test report
- test-results/ - Raw test results
On test failure:
- playwright-screenshots/ - Screenshots of failures
- playwright-traces/ - Execution traces for debugging
- In GitHub Actions: Navigate to the Actions tab, select the workflow run
- Download artifacts: Click on uploaded artifacts to download
- View traces: Download trace files and view at trace.playwright.dev
To add E2E tests for additional examples (e.g., blog, composable-dashboard):
-
Create test directory:
mkdir -p e2e/blog
-
Copy and adapt test files:
cp e2e/starter-auth/*.spec.ts e2e/blog/ -
Update
global-setup.tsto handle the new example -
Update
playwright.config.tswebServer command if needed
Consider adding tests for:
- OAuth authentication flows
- File upload functionality
- Rich text editor (Tiptap)
- Search and filtering
- Pagination
- Relationship fields (complex scenarios)
- Custom field types
- Plugin-specific features (RAG, MCP)
Playwright can also be used for performance testing:
- Measure page load times
- Track API response times
- Monitor bundle sizes
- Validate Core Web Vitals
Issue: Dev server doesn't start Solution: Ensure packages are built:
pnpm buildIssue: Database errors Solution: Clean and regenerate:
cd examples/starter-auth
rm -f dev.db dev.db-journal
pnpm generate
pnpm db:pushIssue: Timing issues Solution: Increase timeouts in specific tests:
test('slow test', async ({ page }) => {
test.setTimeout(60000) // 60 seconds
// ... test code
})Issue: Network delays
Solution: Use waitForLoadState('networkidle'):
await page.goto('/admin/post')
await page.waitForLoadState('networkidle')-
View HTML Report:
pnpm exec playwright show-report -
View Traces:
pnpm exec playwright show-trace test-results/.../trace.zip -
Run in Debug Mode:
pnpm exec playwright test --debug -g "failing test name"
-
Screenshots: Failed tests automatically save screenshots to
test-results/
- E2E Testing Guide - Detailed testing documentation
- Playwright Documentation - Official Playwright docs
- Playwright Best Practices
- OpenSaaS Stack Docs - Stack documentation
playwright.config.tse2e/utils/auth.tse2e/utils/db.tse2e/global-setup.tse2e/global-teardown.tse2e/starter-auth/00-build.spec.tse2e/starter-auth/01-auth.spec.tse2e/starter-auth/02-posts-access-control.spec.tse2e/starter-auth/03-admin-ui.spec.tse2e/README.mdE2E_TESTING_SUMMARY.md
package.json- Added E2E test scripts.gitignore- Added Playwright artifacts
@playwright/testplaywright
The E2E test suite provides comprehensive coverage of the OpenSaaS Stack's core features:
- Authentication - Complete user flows
- Authorization - Access control at all levels
- CRUD Operations - Full data lifecycle
- Admin UI - User interface validation
- Build Process - Ensures examples work correctly
This foundation enables:
- ✅ Confident refactoring and feature development
- ✅ Regression prevention
- ✅ Documentation through tests (living examples)
- ✅ CI/CD integration
- ✅ Quality assurance before releases
The test suite can be easily extended to cover additional examples and features as the stack evolves.