1.7 KiB
1.7 KiB
Testing with Bun in Stock Bot Platform
This project uses Bun Test for all testing needs. Bun Test provides a fast, modern testing experience with Jest-like API compatibility.
Getting Started
To run tests:
# Run all tests (using Turbo)
bun test
# Run tests in watch mode
bun test:watch
# Run tests with coverage
bun test:coverage
# Run specific test types
bun test:unit
bun test:integration
bun test:e2e
Library-specific Testing
Each library has its own testing configuration in a bunfig.toml file. This allows for library-specific test settings while maintaining consistent patterns across the codebase.
Example bunfig.toml:
[test]
preload = ["./test/setup.ts"]
timeout = 5000
[test.env]
NODE_ENV = "test"
[bun]
paths = {
"@/*" = ["./src/*"]
}
Migration from Jest
This project has been fully migrated from Jest to Bun Test. Some key differences:
- Import statements: Use
import { describe, it, expect } from 'bun:test'instead of Jest imports - Mocking: Use Bun's built-in mocking utilities (see global
spyOnhelper) - Configuration: Use
bunfig.tomlinstead of Jest config files - Test helpers: Test helpers are available globally via
global.testHelpers
Best Practices
- Use
describeanditfor test organization - Use relative imports (
../src/) in test files - Keep test setup clean with proper
beforeEachandafterEachhandlers - For complex test scenarios, create dedicated setup files
Test Environment
- All tests run with
NODE_ENV=test - Console output is silenced by default (restore with
testHelpers.restoreConsole()) - Default timeout is 30 seconds for integration tests, 5 seconds for unit tests