Overview
Conductor provides comprehensive mocking utilities for testing workflows without external dependencies. Mock AI providers, databases, HTTP clients, Vectorize, and Durable Objects to create isolated, fast, predictable tests.Installation
Context Mocking
mockContext()
Create a complete mock execution context:mockEnv()
Create a mock Cloudflare environment:mockExecutionContext()
Create a mock execution context:AI Mocking
mockAI()
Create a mock AI binding:MockAIProvider
Advanced AI mocking with configurable responses:Database Mocking
mockD1()
Create a mock D1 database:MockDatabase
Advanced database mocking with data manipulation:KV Mocking
mockKV()
Create a mock KV namespace:R2 Mocking
mockR2()
Create a mock R2 bucket:HTTP Mocking
MockHTTPClient
Mock external HTTP/API calls:Vectorize Mocking
MockVectorize
Mock Vectorize vector database:Durable Objects Mocking
MockDurableObject
Mock Durable Object state:Utility Functions
spy()
Simple spy function for tracking calls:Testing Patterns
Basic Mocking
Advanced AI Mocking
Database State Testing
HTTP API Mocking
Error Simulation
Best Practices
- Use appropriate mocks - Choose the right mock for each dependency
- Initialize with data - Pre-populate mocks with realistic test data
- Test error paths - Mock failures to test error handling
- Verify interactions - Check what was called on mocks
- Clean up - Reset mocks between tests
- Use spy functions - Track function calls
- Mock external services - Never make real API calls in tests
- Keep mocks simple - Don’t over-engineer mock implementations
- Test with realistic data - Use production-like test data
- Document mock behavior - Comment complex mock setups

