65 lines
1.8 KiB
Markdown
65 lines
1.8 KiB
Markdown
# Testing with Bun in Stock Bot Platform
|
|
|
|
The Stock Bot platform uses [Bun Test](https://bun.sh/docs/cli/test) as the primary testing framework (Updated June 2025). Bun Test provides fast, modern testing with Jest-like API compatibility.
|
|
|
|
## Getting Started
|
|
|
|
Run tests using these commands:
|
|
|
|
```cmd
|
|
# 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:
|
|
|
|
```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:
|
|
|
|
1. **Import statements**: Use `import { describe, it, expect } from 'bun:test'` instead of Jest imports
|
|
2. **Mocking**: Use Bun's built-in mocking utilities (see global `spyOn` helper)
|
|
3. **Configuration**: Use `bunfig.toml` instead of Jest config files
|
|
4. **Test helpers**: Test helpers are available globally via `global.testHelpers`
|
|
|
|
## Best Practices
|
|
|
|
- Use `describe` and `it` for test organization
|
|
- Use relative imports (`../src/`) in test files
|
|
- Keep test setup clean with proper `beforeEach` and `afterEach` handlers
|
|
- 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
|