fix: Address code review feedback
- Added explanation for logger mocking in tests/setup.ts - Removed test files from coverage collection in jest.config.js - Updated tests/README.md to clarify coverage approach and remove outdated threshold reference Co-authored-by: mindesbunister <32161838+mindesbunister@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,6 @@ const config = {
|
|||||||
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
|
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
|
||||||
collectCoverageFrom: [
|
collectCoverageFrom: [
|
||||||
'lib/trading/position-manager.ts',
|
'lib/trading/position-manager.ts',
|
||||||
'tests/**/*.ts',
|
|
||||||
],
|
],
|
||||||
coverageReporters: ['text', 'text-summary', 'html'],
|
coverageReporters: ['text', 'text-summary', 'html'],
|
||||||
verbose: true,
|
verbose: true,
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ These tests verify the **logic** of Position Manager functions in isolation:
|
|||||||
- Token vs USD conversion requirements
|
- Token vs USD conversion requirements
|
||||||
- Price verification requirements
|
- Price verification requirements
|
||||||
|
|
||||||
|
**Note:** Coverage metrics are calculated against `lib/trading/position-manager.ts` but will be low because tests extract and validate logic patterns without importing the file directly. This avoids complex mocking while still validating critical trading logic.
|
||||||
|
|
||||||
The tests extract and validate the pure calculation logic without importing the actual Position Manager, avoiding complex mocking of:
|
The tests extract and validate the pure calculation logic without importing the actual Position Manager, avoiding complex mocking of:
|
||||||
- Drift blockchain connections
|
- Drift blockchain connections
|
||||||
- Pyth price feeds
|
- Pyth price feeds
|
||||||
@@ -208,17 +210,15 @@ npm test -- tests/integration/position-manager/
|
|||||||
Tests run automatically in CI with:
|
Tests run automatically in CI with:
|
||||||
- JUnit XML reports for test results
|
- JUnit XML reports for test results
|
||||||
- Coverage reports in HTML and text formats
|
- Coverage reports in HTML and text formats
|
||||||
- Failure threshold of 60% coverage
|
|
||||||
|
|
||||||
Configure in `jest.config.js`:
|
Run tests with coverage report:
|
||||||
|
|
||||||
```javascript
|
```bash
|
||||||
coverageThreshold: {
|
npm run test:coverage
|
||||||
global: {
|
```
|
||||||
branches: 60,
|
|
||||||
functions: 60,
|
Run tests in CI mode with JUnit reporter:
|
||||||
lines: 60,
|
|
||||||
statements: 60,
|
```bash
|
||||||
},
|
npm run test:ci
|
||||||
},
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mock logger to reduce noise during tests
|
// Mock logger to reduce noise during tests
|
||||||
|
// Logger is mocked to:
|
||||||
|
// 1. Prevent console output during test runs
|
||||||
|
// 2. Isolate tests from external I/O operations
|
||||||
|
// 3. Enable verification of logging calls if needed
|
||||||
jest.mock('../lib/utils/logger', () => ({
|
jest.mock('../lib/utils/logger', () => ({
|
||||||
logger: {
|
logger: {
|
||||||
log: jest.fn(),
|
log: jest.fn(),
|
||||||
|
|||||||
Reference in New Issue
Block a user