Overview
These tests verify that bot commands work correctly in a real Discord environment by:- Creating test channels and messages
- Invoking bot commands via Discord API
- Verifying bot responses (reactions, embeds, database changes)
Tech Stack
- discord.js-selfbot-v13 - Selfbot client for simulating user actions
- Effect - Functional effects for composable test operations
- Vitest with @effect/vitest - Test framework with Effect integration
- Convex - Database verification
Project Structure
Selfbot Service
Location:src/core/selfbot-service.ts
The selfbot service wraps discord.js-selfbot-v13 with Effect for functional composition.
Key Features
- Guild Operations
- Message Operations
- Command Invocation
- Channel Management
Error Handling
The selfbot service uses typed Effect errors:Writing Tests
Mark Solution Test
Location:tests/mark-solution.test.ts
Smoke Test
Location:tests/smoke.test.ts
Basic connectivity test to verify the bot is running:
Assertions
Location:src/core/assertions.ts
Custom Effect-based assertions for async operations:
Test Configuration
File:vitest.config.mts
Test Channels
Location:src/core/test-channels.ts
Defines the test channel structure:
Setup & Teardown Scripts
Setup Server
Creates test guild with all required channels:Script:
src/scripts/setup-server.ts- Creates category “E2E Tests”
- Creates text channels for each test scenario
- Creates forum channels
- Configures channel settings in database
Wipe Server
Deletes all test channels but keeps the guild:Script:
src/scripts/wipe-server.tsUseful for cleaning up after failed tests.Running Tests
Environment Variables
.env.production
Continuous Integration
The tests run automatically on Railway: File:railway.toml
Test Schedule
Tests run on a cron schedule to continuously verify bot functionality:run-tests.ts
Best Practices
- Test Isolation
- Waiting for Bot
- Error Messages
- Rate Limits
- Use unique timestamps in test data
- Clean up resources after tests
- Don’t rely on test execution order
Debugging Tests
Enable Verbose Logging
Run Single Test
Check Database State
Query Convex directly to verify database changes:Related Resources
- Discord Bot - The bot being tested
- Database Package - Database queries for verification
- Vitest Docs - Test framework documentation
- Effect Docs - Effect library documentation