18 KiB
Playwright Tests Investigation - Progress Update
Problem Statement
Do playwright tests actually work?
Answer: PARTIAL PROGRESS - Application starts but database adapter issues prevent full functionality
Latest Status (After Commit 7a1b44b)
✅ Application Starts Successfully
The Next.js dev server now starts without crashing and responds on http://localhost:3000
⚠️ Pages Return 500 Errors
While the server runs, database operations fail causing pages to return HTTP 500 errors
🔍 Root Cause
Prisma adapter errors logged as warnings:
prisma:error: Cannot read properties of undefined (reading 'replace')
clientVersion: '7.2.0', digest: '1318283539'
Work Completed
1. Test Infrastructure Analysis ✅
Finding: Playwright tests are correctly configured
- Test files are well-written
- Configuration in
e2e/playwright.config.tsis proper - Browsers can be installed successfully
2. Prisma Client Generation Fix ✅
Commit: 651083e
Change: Updated e2e/playwright.config.ts webServer command:
command: 'npm run db:generate && npm run dev'
Result: Prisma client now generates automatically before dev server starts
3. Next.js Prisma Adapter Implementation ✅
Commits: 9f37692, 878f06b
Changes:
- Created
createProductionPrisma()function infrontends/nextjs/src/lib/config/prisma.ts - Uses
better-sqlite3with@prisma/adapter-better-sqlite3 - Handles DATABASE_URL environment variable with fallback
- Fixed undefined DATABASE_URL error handling
4. DBAL Prisma Adapter Implementation ✅
Commits: f19d044, 7a1b44b
Changes:
- Installed
@prisma/adapter-better-sqlite3andbetter-sqlite3in DBAL - Modified
dbal/development/src/adapters/prisma/context.ts - Added SQLite dialect detection and adapter initialization
- Fixed fallback logic to use SQLite adapter when dialect is undefined
- Prevents attempting to use unsupported Prisma 6 syntax for unknown databases
5. Documentation Updates ✅
Files Created/Modified:
docs/playwright-tests-investigation.md- Complete investigation reportREADME.md- Updated E2E test instructions with prerequisites
Current Status: IMPROVED BUT BLOCKED
Progress Made
- ✅ Application starts successfully (no longer crashes on startup)
- ✅ Server stays running and responds to requests
- ✅ Prisma errors are logged but non-fatal
Remaining Issue
Database Operations Fail:
- Prisma adapter errors prevent database queries from completing
- Pages return HTTP 500 Internal Server Error
- Error originates from Prisma's internal adapter code
- Suggests configuration mismatch between Prisma client and adapter setup
Error Analysis
The error "Cannot read properties of undefined (reading 'replace')" occurs:
- Inside Prisma's generated client code ("ignore-listed frames")
- When attempting database operations
- Consistently with same digest: 1318283539
- Multiple times per page request
Possible Causes
- Adapter Configuration Mismatch: The PrismaClient and adapter may not be fully compatible
- Database Path Issue: The SQLite database path may not be resolving correctly
- Missing Configuration: Prisma 7 may require additional configuration not yet provided
- Multiple Client Instances: Different parts of the code may be creating incompatible Prisma clients
Testing Status
What Works
- ✅ Dependencies install successfully
- ✅ Playwright browsers install successfully
- ✅ Prisma client generates successfully
- ✅ Dev server command starts successfully
- ✅ Server stays running and responds to HTTP requests
- ✅ No TypeScript compilation errors
What Doesn't Work
- ❌ Database operations fail with adapter errors
- ❌ Pages return HTTP 500 errors
- ❌ Playwright tests cannot complete due to 500 errors
Next Steps for Resolution
Immediate Investigation Needed
-
Verify SQLite Database
- Confirm
prisma/prisma/dev.dbexists and is accessible - Check file permissions
- Test direct database connection with better-sqlite3
- Confirm
-
Debug Adapter Initialization
- Add logging to see what parameters are being passed to adapters
- Verify DATABASE_URL is being read correctly
- Check if database path resolution is working
-
Test Prisma Client Directly
- Create a simple script to test PrismaClient with adapter
- Verify basic CRUD operations work outside Next.js
- Isolate whether issue is in Prisma setup or Next.js integration
-
Review Prisma 7 Migration
- Check if additional Prisma 7 configuration files are needed
- Review Prisma 7 changelog for SQLite adapter requirements
- Consider if schema needs updates for Prisma 7 compatibility
Files Modified
Configuration
e2e/playwright.config.ts- Added Prisma generation to webServerprisma/schema.prisma- No changes (using adapter approach)
Application Code
frontends/nextjs/src/lib/config/prisma.ts- Added SQLite adapter for productiondbal/development/src/adapters/prisma/context.ts- Added SQLite adapter with fallback
Dependencies
dbal/development/package.json- Added SQLite adapter packages
Documentation
README.md- Updated E2E testing instructionsdocs/playwright-tests-investigation.md- This comprehensive report
Conclusion
Significant Progress Made: The application now starts and runs, which is a major improvement from the initial state where it crashed immediately.
Remaining Challenge: Database operations fail due to Prisma adapter configuration issues. The errors suggest a deeper compatibility problem between Prisma 7's adapter requirements and how the application is configured.
Path Forward: This requires debugging the Prisma adapter initialization to understand why the adapter is receiving undefined values or malformed parameters. Once database operations work, the Playwright test infrastructure is ready to run.
Test Execution Commands
Once the database issue is resolved:
# Prerequisites
npm install
npx playwright install chromium
# Run tests (Prisma client generation now automatic)
npm run test:e2e
npm run test:e2e:ui # With Playwright UI
npm run test:e2e:headed # With visible browser
npm run test:e2e:debug # Debug mode
Root Cause Identified
Prisma 7 Breaking Changes: Prisma 7 removed support for url in datasource blocks. Applications must now use:
- Driver adapters (e.g.,
@prisma/adapter-better-sqlite3for SQLite), OR - Prisma Accelerate with
accelerateUrl
This affects the entire MetaBuilder codebase which uses SQLite.
Work Completed
1. Test Infrastructure Analysis ✅
Finding: Playwright tests are correctly configured
- Test files are well-written
- Configuration in
e2e/playwright.config.tsis proper - Browsers can be installed successfully
2. Prisma Client Generation Fix ✅
Commit: 651083e
Change: Updated e2e/playwright.config.ts webServer command:
command: 'npm run db:generate && npm run dev'
Result: Prisma client now generates automatically before dev server starts
3. Next.js Prisma Adapter Implementation ✅
Commits: 9f37692, 878f06b
Changes:
- Created
createProductionPrisma()function infrontends/nextjs/src/lib/config/prisma.ts - Uses
better-sqlite3with@prisma/adapter-better-sqlite3 - Handles DATABASE_URL environment variable with fallback
- Fixed undefined DATABASE_URL error handling
4. DBAL Prisma Adapter Implementation ✅
Commit: f19d044
Changes:
- Installed
@prisma/adapter-better-sqlite3andbetter-sqlite3in DBAL - Modified
dbal/development/src/adapters/prisma/context.ts - Added SQLite dialect detection and adapter initialization
- Maintained compatibility with PostgreSQL/MySQL
5. Documentation Updates ✅
Files Created/Modified:
docs/playwright-tests-investigation.md- Complete investigation reportREADME.md- Updated E2E test instructions with prerequisites
Current Status: BLOCKED
Remaining Issue
Application still fails to start with error:
TypeError: Cannot read properties of undefined (reading 'replace')
at ignore-listed frames {
clientVersion: '7.2.0',
digest: '1521421786'
}
Analysis
- The error originates from Prisma's internal code (ignore-listed frames)
- The digest changes between runs (1318283539 → 1521421786), suggesting multiple Prisma client initializations
- Despite adding adapters to both Next.js app and DBAL, an additional Prisma client may be created elsewhere
- The error occurs during application startup, preventing any pages from loading
Possible Causes
- Hidden Prisma Client: Another Prisma client initialization in the codebase not using adapters
- Build Cache: Next.js build cache may contain old Prisma client references
- Import Order: Prisma client might be imported before environment variables are loaded
- Nested Dependencies: A package dependency might be creating its own Prisma client
Testing Attempted
What Works
- ✅ Dependencies install successfully
- ✅ Playwright browsers install successfully
- ✅ Prisma client generates successfully
- ✅ Dev server command starts
- ✅ No TypeScript compilation errors
What Doesn't Work
- ❌ Application crashes immediately on startup
- ❌ Cannot load any pages (including homepage)
- ❌ All Playwright tests fail due to application not starting
Next Steps for Resolution
Immediate Actions Needed
-
Search for All Prisma Client Instantiations
grep -r "new PrismaClient" --include="*.ts" --include="*.tsx" -
Check for Dynamic Imports
- Look for
import('@prisma/client') - Check middleware, API routes, server components
- Look for
-
Review Build Output
- Examine
.next/directory for cached Prisma references - Consider adding Prisma adapter to Next.js webpack config
- Examine
-
Test with Explicit Environment Variables
DATABASE_URL="file:./prisma/prisma/dev.db" npm run dev
Long-term Solutions
- Upgrade Path: Consider if Prisma 6 would be more compatible
- Alternative Approach: Use Prisma Accelerate instead of driver adapters
- Configuration File: Create
prisma.config.tsas mentioned in Prisma 7 docs
Files Modified
Configuration
e2e/playwright.config.ts- Added Prisma generation to webServerprisma/schema.prisma- Attempted URL addition (reverted due to Prisma 7 requirements)
Application Code
frontends/nextjs/src/lib/config/prisma.ts- Added SQLite adapter for productiondbal/development/src/adapters/prisma/context.ts- Added SQLite adapter for DBAL
Dependencies
dbal/development/package.json- Added SQLite adapter packages
Documentation
README.md- Updated E2E testing instructionsdocs/playwright-tests-investigation.md- This comprehensive report
Conclusion
The Playwright test infrastructure is properly configured and would work correctly if the Next.js application could start. The blocking issue is a deeper application architecture problem related to Prisma 7's breaking changes that affects database connectivity throughout the codebase.
Recommendation: This issue requires investigation by someone with deep knowledge of the MetaBuilder codebase to:
- Locate all Prisma client instantiations
- Ensure all use proper adapters for Prisma 7
- Verify the application can start successfully
- Then the existing Playwright tests should run correctly
Test Execution Commands
Once the application issue is resolved:
# Prerequisites
npm install
npx playwright install chromium
# Run tests (Prisma client generation now automatic)
npm run test:e2e
npm run test:e2e:ui # With Playwright UI
npm run test:e2e:headed # With visible browser
npm run test:e2e:debug # Debug mode
Test Infrastructure
- Location:
/e2e/directory - Configuration:
e2e/playwright.config.ts - Test Files:
e2e/smoke.spec.ts- Basic smoke testse2e/login.spec.ts- Authentication flow testse2e/navigation.spec.ts- Navigation and routing testse2e/crud.spec.ts- CRUD operation tests- Additional tests in subdirectories
Configuration Analysis
The Playwright configuration includes:
- Base URL:
http://localhost:3000 - Web Server: Configured to run
npm run devbefore tests - Timeout: 300 seconds (5 minutes) for server startup
- Browser: Chromium (Desktop Chrome)
- Retry Strategy: 2 retries on CI, 0 locally
Issues Found
1. Missing Prisma Client Generation ❌
Severity: CRITICAL - Blocks all tests
Error:
Error: Cannot find module '.prisma/client/default'
Root Cause:
- The web server attempts to start via
npm run dev - Next.js application tries to load Prisma client
- Prisma client has not been generated
- Application cannot start, causing all tests to fail
Impact:
- Dev server fails to start properly
- All Playwright tests fail with "Cannot navigate to invalid URL"
- Tests cannot connect to the application
Solution Required:
npm run db:generate # Generate Prisma client before running tests
2. Prisma Client Configuration Error ❌
Severity: CRITICAL - Blocks all tests
Error:
Error [PrismaClientConstructorValidationError]: Using engine type "client" requires either "adapter" or "accelerateUrl" to be provided to PrismaClient constructor.
Root Cause:
- The Prisma schema is configured for SQLite
- The application code at
frontends/nextjs/src/lib/config/prisma.ts:52creates a PrismaClient instance - However, the Prisma client requires either:
- A database adapter parameter, OR
- An accelerateUrl for Prisma Accelerate
- Neither is provided in the current configuration
Impact:
- Dev server starts but crashes immediately when trying to access any page
- Application cannot render any pages
- All Playwright tests fail because the application is not functional
This is an APPLICATION BUG, not a test configuration issue.
Test Execution Results
Without Prisma Client:
Running 7 tests using 2 workers
✘ All 7 tests FAILED
Failure reason: "Protocol error (Page.navigate): Cannot navigate to invalid URL"
The webServer configuration tries to start but fails repeatedly with Prisma client errors, preventing Playwright from navigating to any pages.
Recommendations
Immediate Fixes
-
Add Prisma Generation Step
- Update test documentation to require
npm run db:generate - Consider adding to playwright webServer command or globalSetup
- Update test documentation to require
-
Update Playwright Configuration
webServer: { command: 'npm run db:generate && npm run dev', // Generate before starting url: 'http://localhost:3000', reuseExistingServer: !process.env.CI, timeout: 300 * 1000, } -
Add Global Setup Script Create
e2e/global-setup.ts:import { execSync } from 'child_process'; export default async function globalSetup() { console.log('Generating Prisma client...'); execSync('npm run db:generate', { stdio: 'inherit' }); console.log('Prisma client generated successfully'); } -
Document Prerequisites Update testing documentation to clearly state:
- Run
npm installfirst - Run
npm run db:generatebefore tests - Ensure database is accessible
- Run
npx playwright install chromiumfor browsers
- Run
Long-term Improvements
-
Add Pre-Test Validation
- Check if Prisma client exists
- Verify database connection
- Confirm server can start
- Provide helpful error messages
-
CI/CD Integration
- Ensure CI pipeline runs
db:generate - Set up test database properly
- Cache Playwright browsers
- Ensure CI pipeline runs
-
Better Error Messages
- Make Playwright config fail fast with clear messages
- Add healthcheck endpoint to verify server readiness
Conclusion
Answer to "Do playwright tests actually work?"
NO - The Playwright tests cannot run successfully due to two issues:
- FIXED: Missing Prisma client generation - Now automatically handled by updated webServer command
- BLOCKING: Prisma Client configuration error in the application
Issue 1: Prisma Client Generation (FIXED ✅)
- Root Cause: Prisma client not generated before dev server start
- Solution Applied: Updated
e2e/playwright.config.tswebServer command tonpm run db:generate && npm run dev - Status: Fixed - Prisma client now generates automatically before tests
Issue 2: Prisma Client Configuration Error (BLOCKING ❌)
- Error:
PrismaClientConstructorValidationError: Using engine type "client" requires either "adapter" or "accelerateUrl" - Location:
frontends/nextjs/src/lib/config/prisma.ts:52 - Root Cause: The Prisma schema is configured to use SQLite, but the PrismaClient initialization at runtime requires either:
- A database adapter to be provided, OR
- An accelerateUrl for Prisma Accelerate
- Impact: The Next.js application cannot start, preventing all E2E tests from running
- Status: This is an application bug, not a testing infrastructure issue
Test Infrastructure Assessment
✅ Working Correctly:
- Playwright installation and configuration
- Browser (Chromium) installation
- Test file structure and quality
- WebServer configuration with auto-generation
- Documentation and instructions
❌ Blocked By:
- Application-level Prisma configuration error
- Cannot be fixed in test configuration alone
Next Steps to Enable Tests:
- Fix the Prisma Client initialization in
frontends/nextjs/src/lib/config/prisma.ts - Ensure the application can start successfully with the SQLite database
- Once the application runs, the existing test infrastructure should work correctly
Test Execution Commands (Corrected)
# Install dependencies
npm install
# Install Playwright browsers
npx playwright install chromium
# Generate Prisma client (CRITICAL STEP)
npm run db:generate
# Run tests
npm run test:e2e
# Or with UI
npm run test:e2e:ui
Files Requiring Changes
e2e/playwright.config.ts- Add Prisma generation to webServer command or globalSetupdocs/TESTING_GUIDE.md- Update prerequisites sectionREADME.md- Update E2E test instructions.github/workflows/*.yml- Ensure CI runs db:generate before tests