3.7 KiB
3.7 KiB
Test Commands - Quick Reference
Run Tests by Category
npm run test:all # All tests (61 files across 8 categories)
npm run test:promo # Promotion/coupon tests (13 files)
npm run test:satloc # SatLoc partner integration (13 files)
npm run test:job # Job processing (9 files)
npm run test:payment # Payment & billing (4 files)
npm run test:dlq # Dead Letter Queue (3 files)
npm run test:parsing # Log parsing (7 files)
npm run test:integration # Integration tests (2 files)
npm run test:utils # Utility tests (9 files)
Run Single Test
npm run test:single tests/promo/test_promo_details.js
# OR
node tests/promo/test_promo_details.js
Run with Options
npm run test:verbose # Show all output (not just failures)
npm run test:bail # Stop on first failure
# Custom patterns
npm run test:file 'promo/test_priority*.js'
node tests/run_all_tests.js --pattern 'job/test_*.js' --verbose
Understanding Results
Exit Codes
- 0 = Test PASSED ✅
- 1 = Test FAILED ❌
Output Format
✅ PASSED: test_name.js (1234ms) # Success
❌ FAILED: test_name.js (5678ms) # Failure
Summary
📊 TEST SUMMARY
✅ Passed: 10/13 # 10 passed out of 13 total
❌ Failed: 3/13 # 3 failed
⏱️ Total Duration: 72.00s # Total time
When Tests Fail
- Check output preview (shows last 5 lines of error)
- Run with verbose:
npm run test:verbose - Run single test:
node tests/category/test_file.js - Check services: MongoDB, Redis, RabbitMQ running?
- Verify env vars: Stripe keys, API credentials correct?
Common Failures
| Error | Cause | Fix |
|---|---|---|
| Exit code 1 | Test logic failed | Check assertions in test file |
| ECONNREFUSED | Service not running | Start MongoDB/Redis/RabbitMQ |
| 401 Unauthorized | Invalid credentials | Check environment.env |
| ENOTFOUND | DNS/network issue | Check internet connection |
| Rate limit | Too many API calls | Add delays between calls |
Debugging Commands
# See full output for failing test
node tests/dlq/test_dlq_routes.js
# Run one category with verbose output
node tests/run_all_tests.js --pattern 'payment/test_*.js' --verbose
# Stop on first failure to save time
npm run test:bail
Test File Naming
test_*.js- Regular tests (included in runs)*.spec.js- Mocha tests (run separately withnpm test)manual_*.js- Manual scripts (excluded from test runs)
Environment
Tests use environment.env by default:
# Use different environment
node tests/run_all_tests.js --env ./environment_prod.env
Test Categories Summary
| Category | Files | Description |
|---|---|---|
| promo | 13 | Promotion codes, coupons, validation |
| satloc | 13 | Partner integration, log parsing, API sync |
| job | 9 | Job processing, queueing, uploads |
| utils | 9 | Helper functions, utilities |
| parsing | 7 | Log file parsing, data extraction |
| payment | 4 | Stripe integration, subscriptions |
| dlq | 3 | Dead letter queue management |
| integration | 2 | Cross-feature integration tests |
Quick Start
# 1. Run all tests to see overall status
npm run test:all
# 2. Run specific category if failures
npm run test:promo
# 3. Debug individual test
node tests/promo/test_promo_details.js
Notes
- Tests are integration tests (not unit tests)
- Connect to real services (MongoDB, Stripe, RabbitMQ)
- Require services to be running and accessible
- Each test runs in separate process (isolated)
- Results based on exit codes (0 = pass, non-zero = fail)
More Info
- Complete guide:
docs/TEST_RUNNER_GUIDE.md - Test organization:
TESTS_ORGANIZED.md