Testing
Testing utilities for workflows
Testing
Worlds Engine provides utilities for deterministic testing of workflows.
Test Harness
Creates an isolated World instance with memory storage and controlled time.
import { TestHarness } from 'worlds-engine/test';
const harness = new TestHarness({
initialTime: 1000000,
autoProgress: true
});
await harness.start();
Time Skipper
Overrides global time functions (Date.now, setTimeout, setInterval) for deterministic testing.
Time Control Methods
// Advance time by 1 hour
await harness.advance(3600000);
// Advance to specific timestamp
await harness.advanceTo(2000000);
// Run until workflow completes
await harness.runUntilComplete('workflow-id');
Example Test
test('approval workflow expires after timeout', async () => {
const harness = new TestHarness();
await harness.start();
// Start workflow
const handle = await harness.world.execute('approval-workflow', {
timeout: '24h'
});
// Advance time past timeout (24h + 1ms)
await harness.advance(86400001);
// Verify result
const result = await handle.result();
expect(result.status).toBe('expired');
});
Timer Management
- Stores callback and execution time
advance()advances virtual time- Executes callbacks when their time is reached
- Reschedules intervals automatically