**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
import { defineConfig } from 'vitest/config'
export default defineConfig ( {
test : {
// Default configuration
globals : true ,
setupFiles : [ './tests/setup.ts' ] ,
2025-08-10 13:52:01 -07:00
testTimeout : 120000 , // 120 seconds for TensorFlow operations
hookTimeout : 120000 ,
// Run tests in parallel with limited pool
pool : 'forks' ,
poolOptions : {
forks : {
singleFork : true , // Run all tests in a single fork to reduce memory usage
isolate : false , // Don't isolate tests to reduce overhead
}
} ,
// Limit concurrent tests to reduce memory usage
maxConcurrency : 1 ,
// Clear mocks between tests
clearMocks : true ,
restoreMocks : true ,
**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
// Include test files
include : [ 'tests/**/*.{test,spec}.{js,ts}' ] ,
2025-07-16 11:40:42 -07:00
// Default environment
environment : 'node' ,
**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
// Exclude old test files
exclude : [
'node_modules/**' ,
'dist/**' ,
'scripts/**' ,
'examples/**' ,
'*.js' // Exclude old JS test files in root
] ,
// Add environment options to help with TextEncoder issues
environmentOptions : {
env : {
FORCE_PATCHED_PLATFORM : 'true'
}
2025-07-16 11:40:42 -07:00
} ,
2025-07-28 16:00:05 -07:00
// Configure reporters for different output formats
2025-07-16 13:08:41 -07:00
reporters : [
2025-07-28 16:00:05 -07:00
// Default reporter for basic progress during test run
2025-07-16 13:08:41 -07:00
[
'default' ,
{
2025-07-28 10:04:45 -07:00
summary : true ,
2025-07-28 16:00:05 -07:00
reportSummary : true ,
// Show test titles for all tests
successfulTestOnly : false ,
// Show a compact output
outputFile : false
2025-07-16 13:08:41 -07:00
}
2025-07-28 10:04:45 -07:00
] ,
2025-07-28 16:00:05 -07:00
// JSON reporter for machine-readable output (can be used for CI/CD)
[
'json' ,
{
2025-07-30 10:42:18 -07:00
outputFile : './tests/results/test-results.json'
2025-07-28 16:00:05 -07:00
}
]
2025-07-16 13:08:41 -07:00
] ,
2025-07-28 10:04:45 -07:00
// Configure output for better visibility
2025-07-16 11:40:42 -07:00
silent : false ,
// Configure error display for better readability
bail : 0 ,
// Disable coverage reports by default to reduce noise
coverage : {
enabled : false
} ,
2025-07-28 16:00:05 -07:00
// Don't show test statistics to reduce noise
2025-07-16 11:40:42 -07:00
logHeapUsage : false ,
2025-07-28 16:00:05 -07:00
// Hide skipped tests to reduce noise
hideSkippedTests : true ,
// Only show stack traces for failed tests
printConsoleTrace : false ,
// Show test timing information in the summary
// showTimer: true,
// Aggressively filter out console output to only show test progress
2025-07-16 11:40:42 -07:00
onConsoleLog : ( log : string , type : 'stdout' | 'stderr' ) : false | void = > {
2025-07-28 16:00:05 -07:00
// For stdout, only allow critical error messages and test progress indicators
if ( type === 'stdout' ) {
// Only allow through explicit test-related messages and critical errors
const allowedPatterns = [
'Error:' ,
'FAIL' ,
'PASS' ,
'WARNING:' ,
'test result' ,
'Test Files' ,
'Tests' ,
'Start at' ,
'Duration' ,
'✓' ,
'✗' ,
'running' ,
'suite'
]
// If the log doesn't contain any allowed pattern, filter it out
if ( ! allowedPatterns . some ( ( pattern ) = > log . includes ( pattern ) ) ) {
return false
}
}
// For stderr, only show actual errors
if (
type === 'stderr' &&
! log . includes ( 'Error:' ) &&
! log . includes ( 'FAIL' )
) {
return false
}
// Expanded list of noise patterns to filter out
2025-07-16 13:08:41 -07:00
const noisePatterns : string [ ] = [
2025-07-28 16:00:05 -07:00
// Original patterns
'Brainy:' ,
'TensorFlow' ,
'Universal Sentence Encoder' ,
'Using file system storage' ,
'Using WebGL backend' ,
'Platform node' ,
2025-07-16 13:08:41 -07:00
'The kernel' ,
'for backend' ,
'is already registered' ,
2025-07-28 16:00:05 -07:00
'Hi there 👋' ,
2025-07-16 13:08:41 -07:00
'backend registration' ,
'webgl' ,
'cpu' ,
2025-07-28 16:00:05 -07:00
'Could not get context' ,
'Retrying' ,
2025-07-16 13:08:41 -07:00
'Skipping noun' ,
'due to dimension mismatch' ,
2025-07-28 16:00:05 -07:00
'Successfully loaded' ,
'model loaded' ,
'module structure' ,
'No default export' ,
'Using sentenceEncoderModule' ,
'Loading' ,
'Applying' ,
'Overwriting' ,
'Applied' ,
'running in Node.js environment' ,
'Pre-loading' ,
'has already been set' ,
// Additional patterns to filter out common console.log statements from tests
'Attempting to add' ,
'Successfully added' ,
'Test API server running' ,
'Text content not found' ,
'Searching for text' ,
'Expected ID:' ,
'Search returned' ,
'First result ID:' ,
'All result IDs:' ,
'Could not find result' ,
'Found result with matching ID:' ,
'console.log' ,
'console.info' ,
'console.debug'
2025-07-16 13:08:41 -07:00
]
2025-07-16 11:40:42 -07:00
// Return false (don't show) if log contains any noise pattern
if ( noisePatterns . some ( ( pattern ) = > log . includes ( pattern ) ) ) {
return false
}
2025-07-28 16:00:05 -07:00
// Additional filtering for common debug output patterns
if (
log . includes ( 'Searching' ) ||
log . includes ( 'Found' ) ||
log . includes ( 'Created' ) ||
log . includes ( 'Loaded' ) ||
log . includes ( 'Processing' ) ||
log . includes ( 'Initializing' ) ||
log . includes ( 'Starting' ) ||
log . includes ( 'Completed' ) ||
log . includes ( 'Finished' )
) {
return false
}
return undefined // Show the log if it passes all filters
**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
}
2025-07-28 16:00:05 -07:00
// Add a custom reporter configuration for a cleaner output
// outputDiffLines: 5, // Limit diff output lines for cleaner error reports
// outputFileMaxLines: 40, // Limit file output lines for cleaner error reports
// outputTruncateLength: 80 // Truncate long output lines
**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
} ,
// Resolve configuration for proper module handling
resolve : {
alias : {
'@' : './src' ,
'@tests' : './tests'
}
} ,
// Define different configurations for different environments
define : {
'process.env.NODE_ENV' : '"test"'
}
} )