- **Core Improvements**: - Refactored logging functions into a unified `logger` method for consistent output across the library. - Enabled the `forceMemoryStorage` option in `BrainyData` initialization for improved storage flexibility in tests and specific use cases. - **TensorFlow.js and Environment Updates**: - Clarified the dependency structure in `README.md` to emphasize bundled dependencies and remove legacy peer dependency instructions. - Simplified and reformatted environment detection logic for better maintainability and readability. - **Testing Enhancements**: - Added `tests/package-size-limit.test.ts` to monitor and validate npm package size against defined thresholds. - Updated `tests/environment.node.test.ts` and core tests to leverage `forceMemoryStorage` for better test setup standardization. - Improved test isolation with expanded `globalThis` utility definitions and cleanup logic. - **Documentation**: - Added detailed best practices for debugging and organizing tests in `DEVELOPERS.md`. - Removed outdated installation hints from `package.json` and streamlined scripts by including `test:size` for package size validation. **Purpose**: These changes unify core logging mechanisms, expand configurability of storage options, and improve testing reliability and coverage. Documentation and clarity are enhanced to align with updated functionality and best practices.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
/**
|
|
* Simple test setup for Brainy library
|
|
* No direct TensorFlow references - patches are handled internally by Brainy
|
|
*/
|
|
|
|
import { beforeEach } from 'vitest'
|
|
|
|
// Define the test utilities type for reuse
|
|
type TestUtilsType = {
|
|
createTestVector: (dimensions: number) => number[]
|
|
timeout: number
|
|
}
|
|
|
|
// Extend global type definitions for both global and globalThis
|
|
declare global {
|
|
let testUtils: TestUtilsType | undefined
|
|
let __ENV__: any
|
|
}
|
|
|
|
// Explicitly declare globalThis interface to ensure TypeScript recognizes these properties
|
|
declare global {
|
|
interface globalThis {
|
|
testUtils?: TestUtilsType | undefined
|
|
__ENV__?: any
|
|
}
|
|
}
|
|
|
|
// Clean up between tests
|
|
beforeEach(() => {
|
|
// Clear any global state that might interfere with tests
|
|
if (typeof globalThis !== 'undefined' && globalThis.__ENV__) {
|
|
delete globalThis.__ENV__
|
|
}
|
|
if (typeof global !== 'undefined' && global.__ENV__) {
|
|
delete global.__ENV__
|
|
}
|
|
})
|
|
|
|
// Add simple test utilities to both global and globalThis for compatibility
|
|
const testUtilsObject = {
|
|
// 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
|
|
}
|
|
|
|
global.testUtils = testUtilsObject
|
|
globalThis.testUtils = testUtilsObject
|