brainy/tests/setup.ts
David Snelling 5958502cf3 **test(tests): enhance test clarity, isolation, and robustness**
- **Test Improvements**:
  - Introduced data-clearing steps (`.clear()`) across critical test cases for ensuring better test isolation and preventing state leakage.
  - Extended support for overriding global utilities (`testUtils`) and added fallback behaviors for test vector creation.

- **Configuration Updates**:
  - Added support for `distanceFunction` as an alternative to `metric` in vector operations for consistency.
  - Adjusted and unified asynchronous `timeout` handling across test suites for predictability.

- **Purpose**:
  - These updates improve reliability, maintainability, and clarity in test cases while ensuring compatibility across diverse test environments.
2025-07-16 11:39:53 -07:00

36 lines
874 B
TypeScript

/**
* Simple test setup for Brainy library
* No direct TensorFlow references - patches are handled internally by Brainy
*/
import { beforeEach } from 'vitest'
// Extend global type definitions
declare global {
let testUtils:
| {
createTestVector: (dimensions: number) => number[]
timeout: number
}
| undefined
let __ENV__: any
}
// Clean up between tests
beforeEach(() => {
// Clear any global state that might interfere with tests
if (typeof global !== 'undefined' && global.__ENV__) {
delete global.__ENV__
}
})
// Add simple test utilities
global.testUtils = {
// Create a simple test vector with predictable values
createTestVector: (dimensions: number): number[] => {
return Array.from({ length: dimensions }, (_, i) => (i + 1) / dimensions)
},
// Standard timeout for async operations
timeout: 30000
}