**test(tests): add comprehensive test suite for Brainy functionality**
- **New Tests Added**:
- Introduced multiple test suites covering core functionalities (`core.test.ts`), vector operations (`vector-operations.test.ts`), Node.js environment (`environment.node.test.ts`), browser setup (`environment.browser.test.ts`), and TensorFlow.js-specific behaviors (`tensorflow-patch.test.ts`).
- Added performance, scalability, and error-handling tests to ensure robust validation of vector addition, search, and text embedding functionalities.
- Introduced setup utilities (`tests/setup.ts`) and standardized test utilities for creating predictable test cases.
- **Configuration**:
- Created `vitest.config.ts` for custom test configurations, including support for modern test environments (`jsdom`, `happy-dom`) and extended timeouts for asynchronous operations.
- **Validation**:
- Includes compatibility checks for TensorFlow.js imports and ensures proper handling of `TextEncoder`/`TextDecoder` in Node.js environments.
This commit significantly enhances the testing coverage and structure, ensuring Brainy functionality is robust, cross-platform, and aligned with evolving reliability standards.
2025-07-15 11:56:16 -07:00
|
|
|
/**
|
|
|
|
|
* Simple test setup for Brainy library
|
|
|
|
|
* No direct TensorFlow references - patches are handled internally by Brainy
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { beforeEach } from 'vitest'
|
|
|
|
|
|
2025-07-17 10:00:28 -07:00
|
|
|
// Define the test utilities type for reuse
|
|
|
|
|
type TestUtilsType = {
|
|
|
|
|
createTestVector: (dimensions: number) => number[]
|
|
|
|
|
timeout: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extend global type definitions for both global and globalThis
|
2025-07-16 11:39:53 -07:00
|
|
|
declare global {
|
2025-07-17 10:00:28 -07:00
|
|
|
let testUtils: TestUtilsType | undefined
|
2025-07-16 11:39:53 -07:00
|
|
|
let __ENV__: any
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 10:00:28 -07:00
|
|
|
// Explicitly declare globalThis interface to ensure TypeScript recognizes these properties
|
|
|
|
|
declare global {
|
|
|
|
|
interface globalThis {
|
|
|
|
|
testUtils?: TestUtilsType | undefined
|
|
|
|
|
__ENV__?: any
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
**test(tests): add comprehensive test suite for Brainy functionality**
- **New Tests Added**:
- Introduced multiple test suites covering core functionalities (`core.test.ts`), vector operations (`vector-operations.test.ts`), Node.js environment (`environment.node.test.ts`), browser setup (`environment.browser.test.ts`), and TensorFlow.js-specific behaviors (`tensorflow-patch.test.ts`).
- Added performance, scalability, and error-handling tests to ensure robust validation of vector addition, search, and text embedding functionalities.
- Introduced setup utilities (`tests/setup.ts`) and standardized test utilities for creating predictable test cases.
- **Configuration**:
- Created `vitest.config.ts` for custom test configurations, including support for modern test environments (`jsdom`, `happy-dom`) and extended timeouts for asynchronous operations.
- **Validation**:
- Includes compatibility checks for TensorFlow.js imports and ensures proper handling of `TextEncoder`/`TextDecoder` in Node.js environments.
This commit significantly enhances the testing coverage and structure, ensuring Brainy functionality is robust, cross-platform, and aligned with evolving reliability standards.
2025-07-15 11:56:16 -07:00
|
|
|
// Clean up between tests
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
// Clear any global state that might interfere with tests
|
2025-07-17 10:00:28 -07:00
|
|
|
if (typeof globalThis !== 'undefined' && globalThis.__ENV__) {
|
|
|
|
|
delete globalThis.__ENV__
|
|
|
|
|
}
|
**test(tests): add comprehensive test suite for Brainy functionality**
- **New Tests Added**:
- Introduced multiple test suites covering core functionalities (`core.test.ts`), vector operations (`vector-operations.test.ts`), Node.js environment (`environment.node.test.ts`), browser setup (`environment.browser.test.ts`), and TensorFlow.js-specific behaviors (`tensorflow-patch.test.ts`).
- Added performance, scalability, and error-handling tests to ensure robust validation of vector addition, search, and text embedding functionalities.
- Introduced setup utilities (`tests/setup.ts`) and standardized test utilities for creating predictable test cases.
- **Configuration**:
- Created `vitest.config.ts` for custom test configurations, including support for modern test environments (`jsdom`, `happy-dom`) and extended timeouts for asynchronous operations.
- **Validation**:
- Includes compatibility checks for TensorFlow.js imports and ensures proper handling of `TextEncoder`/`TextDecoder` in Node.js environments.
This commit significantly enhances the testing coverage and structure, ensuring Brainy functionality is robust, cross-platform, and aligned with evolving reliability standards.
2025-07-15 11:56:16 -07:00
|
|
|
if (typeof global !== 'undefined' && global.__ENV__) {
|
|
|
|
|
delete global.__ENV__
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2025-07-17 10:00:28 -07:00
|
|
|
// Add simple test utilities to both global and globalThis for compatibility
|
|
|
|
|
const testUtilsObject = {
|
**test(tests): add comprehensive test suite for Brainy functionality**
- **New Tests Added**:
- Introduced multiple test suites covering core functionalities (`core.test.ts`), vector operations (`vector-operations.test.ts`), Node.js environment (`environment.node.test.ts`), browser setup (`environment.browser.test.ts`), and TensorFlow.js-specific behaviors (`tensorflow-patch.test.ts`).
- Added performance, scalability, and error-handling tests to ensure robust validation of vector addition, search, and text embedding functionalities.
- Introduced setup utilities (`tests/setup.ts`) and standardized test utilities for creating predictable test cases.
- **Configuration**:
- Created `vitest.config.ts` for custom test configurations, including support for modern test environments (`jsdom`, `happy-dom`) and extended timeouts for asynchronous operations.
- **Validation**:
- Includes compatibility checks for TensorFlow.js imports and ensures proper handling of `TextEncoder`/`TextDecoder` in Node.js environments.
This commit significantly enhances the testing coverage and structure, ensuring Brainy functionality is robust, cross-platform, and aligned with evolving reliability standards.
2025-07-15 11:56:16 -07:00
|
|
|
// 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
|
|
|
|
|
}
|
2025-07-17 10:00:28 -07:00
|
|
|
|
|
|
|
|
global.testUtils = testUtilsObject
|
|
|
|
|
globalThis.testUtils = testUtilsObject
|