**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.
This commit is contained in:
David Snelling 2025-07-16 11:39:53 -07:00
parent 387179f370
commit bcbaf4a678
5 changed files with 170 additions and 126 deletions

View file

@ -5,6 +5,17 @@
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
@ -13,16 +24,8 @@ beforeEach(() => {
}
})
// Simple test utilities focused on Brainy usage patterns
declare global {
let testUtils: {
createTestVector: (dimensions: number) => number[]
timeout: number
}
}
// Add simple test utilities
globalThis.testUtils = {
global.testUtils = {
// Create a simple test vector with predictable values
createTestVector: (dimensions: number): number[] => {
return Array.from({ length: dimensions }, (_, i) => (i + 1) / dimensions)