Test Debugging Guide
Overview
Tests are configured with minimal logging by default for clean output. When debugging is needed, there's a simple, unified approach using the standard LOG_LEVEL
environment variable.
Quick Debugging Commands
1. Enable Verbose Test Logging
# Enable detailed logging and verbose reporter (recommended)
pnpm test:debug
# Run specific test with debug logging
pnpm test:debug tests/path/to/specific.test.ts
# Or enable debug logging with regular test command
LOG_LEVEL=debug pnpm test tests/path/to/specific.test.ts
2. Run Tests with Maximum Verbosity
# Full verbose output with reporter details
cd apps/web && LOG_LEVEL=debug vitest run --reporter=verbose tests/path/to/test.ts
3. Watch Mode for Development
# Watch tests with debugging enabled
LOG_LEVEL=debug pnpm test:watch
Unified Logging with LOG_LEVEL
The system uses a single LOG_LEVEL
environment variable for all logging across development, production, and tests:
Environment | Default Level | Override | Effect |
---|---|---|---|
Development | debug | LOG_LEVEL=info | All logs visible by default |
Production | info | LOG_LEVEL=error | Info+ logs visible by default |
Tests | silent | LOG_LEVEL=debug | No logs unless explicitly enabled |
Available Log Levels
silent
- No logserror
- Only errorswarn
- Warnings and errorsinfo
- Info, warnings, and errorsdebug
- All logs including debug infotrace
- Maximum verbosity
What Gets Logged with LOG_LEVEL=debug
- Payload Startup Logs: Email adapter warnings, migration info, sharp warnings, etc.
- Application Logs: All pino logger output from the application (database operations, seeding, etc.)
- Test Setup Details: Test environment creation, cleanup operations
- Database Operations: Table truncation, seeding operations
Default Behavior (No Debug Flags)
- All logs: Suppressed (level: "silent")
- Test output: Only test results and failures
- Node.js warnings: Suppressed via
NODE_OPTIONS="--no-warnings"
Common Debugging Scenarios
Database Issues
# See database operations and seeding
LOG_LEVEL=debug pnpm test tests/integration/services/seed-config.test.ts
Import/Processing Issues
# Debug import job processing
LOG_LEVEL=debug pnpm test tests/integration/import/
Payload Configuration Issues
# See Payload startup logs (email adapter, sharp warnings, migration info)
LOG_LEVEL=debug pnpm test tests/integration/
Application Logic Issues
# See all application logger output
LOG_LEVEL=debug pnpm test tests/integration/
Cross-Environment Usage
The same LOG_LEVEL
variable works consistently across all environments:
# Development server with debug logs
LOG_LEVEL=debug pnpm dev
# Tests with debug logs
LOG_LEVEL=debug pnpm test
# Production with error-only logs
LOG_LEVEL=error pnpm start
Files with Logging Capabilities
lib/logger.ts
- Central logger configuration respectingLOG_LEVEL
tests/setup/setup.ts
- Test setup respectingLOG_LEVEL
tests/setup/test-helpers.ts
- Test helpers with unified loggingtests/setup/TestEnvironmentBuilder.ts
- Test environment builder
Package.json Scripts
test:debug
- SetsLOG_LEVEL=debug
and uses--reporter=verbose
dev:debug
- SetsLOG_LEVEL=debug
for development servertest:watch
- Watch mode (setLOG_LEVEL=debug
for verbose output)test
- Minimal output with--reporter=basic --silent
Benefits of Unified Logging
✅ Consistent: Same variable works everywhere
✅ Simple: One concept to remember (LOG_LEVEL
)
✅ Standard: Follows common logging conventions
✅ Flexible: Works across all environments and tools
✅ Predictable: Same behavior whether in dev, test, or production
Notes
- Clean by default: Tests produce minimal output unless
LOG_LEVEL
is set - Error logs always visible: Critical errors show regardless of log level
- Test failures show details: Full error information always available
- Migration errors always displayed: Critical for debugging database issues