Overview
The plugin-bootstrap package includes a comprehensive test suite that demonstrates how to test:- Actions
- Providers
- Evaluators
- Services
- Event Handlers
- Message Processing Logic
Test Setup
Test Framework
This plugin uses Bun’s built-in test runner, not Vitest. Bun provides a Jest-compatible testing API with excellent TypeScript support and fast execution.Using the Standard Test Utilities
The package provides robust test utilities insrc/__tests__/test-utils.ts
:
Available Mock Factories
Testing Patterns
Testing Actions
Basic Action Test
Testing Action with Dependencies
Testing Providers
Testing Evaluators
Testing Message Processing
Testing Services
Testing Best Practices
1. Use Standard Test Setup
Always use the provided test utilities for consistency:2. Test Edge Cases
3. Mock External Dependencies
4. Test Async Operations
5. Verify State Changes
Common Testing Scenarios
Testing Room Type Behavior
Testing Provider Context
Testing Error Recovery
Running Tests
Bun Test Features
Bun’s test runner provides several advantages:- Fast execution - Tests run directly in Bun’s runtime
- Built-in TypeScript - No compilation step needed
- Jest compatibility - Familiar API for developers
- Built-in mocking - The
mock()
function is built-in - Snapshot testing - Built-in support for snapshots
- Watch mode - Automatic re-running on file changes
Bun Mock API
Tips for Writing Tests
- Start with the happy path - Test normal operation first
- Add edge cases - Empty arrays, null values, errors
- Test async behavior - Timeouts, retries, concurrent operations
- Verify side effects - Database updates, event emissions
- Keep tests focused - One concept per test
- Use descriptive names - Should describe what is being tested
- Mock at boundaries - Mock external services, not internal logic
Debugging Tests
Differences from Vitest
If you’re familiar with Vitest, here are the key differences:- Import from
bun:test
instead ofvitest
- No need for
vi
prefix - Just usemock()
directly - No configuration file - Bun test works out of the box
- Different CLI commands - Use
bun test
instead ofvitest