Skip to main content
This guide covers testing strategies, patterns, and best practices for the @elizaos/plugin-discord package.

Test Environment Setup

Prerequisites

  1. Test Discord Server
    • Create a dedicated Discord server for testing
    • Set up test channels (text, voice, etc.)
    • Configure appropriate permissions
  2. Test Bot Application
    • Create a separate bot application for testing
    • Generate test credentials
    • Add bot to test server with full permissions
  3. Environment Configuration

Unit Testing

Testing Message Manager

Testing Voice Manager

Integration Testing

Testing Discord Service

Testing Message Flow

E2E Testing

Complete Bot Test Suite

Performance Testing

Load Testing

Memory Usage Testing

Mock Utilities

Discord.js Mocks

Test Helpers

Debug Logging

Enable Detailed Logging

Test Configuration

vitest.config.ts

Test Setup

Continuous Integration

GitHub Actions Workflow

Best Practices

  1. Test Isolation
    • Each test should be independent
    • Clean up resources after tests
    • Use separate test channels/servers
  2. Mock External Services
    • Mock Discord API calls for unit tests
    • Use real Discord for integration tests only
    • Mock transcription/vision services
  3. Error Scenarios
    • Test network failures
    • Test permission errors
    • Test rate limiting
  4. Performance Monitoring
    • Track response times
    • Monitor memory usage
    • Check for connection stability
  5. Security Testing
    • Test token validation
    • Test permission checks
    • Test input sanitization