Skip to main content
This guide covers testing patterns and best practices for developing with the plugin-bootstrap package.

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 in src/__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:
  1. Fast execution - Tests run directly in Bun’s runtime
  2. Built-in TypeScript - No compilation step needed
  3. Jest compatibility - Familiar API for developers
  4. Built-in mocking - The mock() function is built-in
  5. Snapshot testing - Built-in support for snapshots
  6. Watch mode - Automatic re-running on file changes

Bun Mock API

Tips for Writing Tests

  1. Start with the happy path - Test normal operation first
  2. Add edge cases - Empty arrays, null values, errors
  3. Test async behavior - Timeouts, retries, concurrent operations
  4. Verify side effects - Database updates, event emissions
  5. Keep tests focused - One concept per test
  6. Use descriptive names - Should describe what is being tested
  7. 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:
  1. Import from bun:test instead of vitest
  2. No need for vi prefix - Just use mock() directly
  3. No configuration file - Bun test works out of the box
  4. Different CLI commands - Use bun test instead of vitest
Remember: Good tests make development faster and more confident. The test suite is your safety net when making changes!