Major improvements to build process, package optimization, and test infrastructure: ## Package Size Optimization (3.4MB → 2.2MB) - Remove source maps from npm package (reduce size by 35%) - Update package.json files field to exclude *.js.map and *.d.ts.map - Enhanced .npmignore for better exclusion patterns - Preserve all browser compatibility and universal shims ## Test Infrastructure Fixes - Increase test timeouts to 120s for TensorFlow operations - Improve memory management with garbage collection hooks - Add proper cleanup between tests to prevent file accumulation - Configure single-fork test execution to reduce memory usage - Fix test parameter issues in intelligent verb scoring tests ## Bug Fixes - Fix lock directory creation in FileSystemStorage - Remove deprecated node-fetch import from api-integration tests - Fix addVerb() and db.add() parameter usage throughout test suite - Ensure proper vector dimensions (384) in all test vectors - Add directory existence checks before lock file operations ## Build & Development - Update vitest configuration for better concurrency and reliability - Add comprehensive test cleanup in setup.ts - Preserve all browser JavaScript functionality and universal compatibility layer The package now meets size requirements while maintaining full functionality for both browser and Node.js environments.
203 lines
5.8 KiB
TypeScript
203 lines
5.8 KiB
TypeScript
import { defineConfig } from 'vitest/config'
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
// Default configuration
|
|
globals: true,
|
|
setupFiles: ['./tests/setup.ts'],
|
|
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,
|
|
// Include test files
|
|
include: ['tests/**/*.{test,spec}.{js,ts}'],
|
|
// Default environment
|
|
environment: 'node',
|
|
// 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'
|
|
}
|
|
},
|
|
// Configure reporters for different output formats
|
|
reporters: [
|
|
// Default reporter for basic progress during test run
|
|
[
|
|
'default',
|
|
{
|
|
summary: true,
|
|
reportSummary: true,
|
|
// Show test titles for all tests
|
|
successfulTestOnly: false,
|
|
// Show a compact output
|
|
outputFile: false
|
|
}
|
|
],
|
|
// JSON reporter for machine-readable output (can be used for CI/CD)
|
|
[
|
|
'json',
|
|
{
|
|
outputFile: './tests/results/test-results.json'
|
|
}
|
|
]
|
|
],
|
|
// Configure output for better visibility
|
|
silent: false,
|
|
// Configure error display for better readability
|
|
bail: 0,
|
|
// Disable coverage reports by default to reduce noise
|
|
coverage: {
|
|
enabled: false
|
|
},
|
|
// Don't show test statistics to reduce noise
|
|
logHeapUsage: false,
|
|
// 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
|
|
onConsoleLog: (log: string, type: 'stdout' | 'stderr'): false | void => {
|
|
// 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
|
|
const noisePatterns: string[] = [
|
|
// Original patterns
|
|
'Brainy:',
|
|
'TensorFlow',
|
|
'Universal Sentence Encoder',
|
|
'Using file system storage',
|
|
'Using WebGL backend',
|
|
'Platform node',
|
|
'The kernel',
|
|
'for backend',
|
|
'is already registered',
|
|
'Hi there 👋',
|
|
'backend registration',
|
|
'webgl',
|
|
'cpu',
|
|
'Could not get context',
|
|
'Retrying',
|
|
'Skipping noun',
|
|
'due to dimension mismatch',
|
|
'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'
|
|
]
|
|
|
|
// Return false (don't show) if log contains any noise pattern
|
|
if (noisePatterns.some((pattern) => log.includes(pattern))) {
|
|
return false
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
},
|
|
// Resolve configuration for proper module handling
|
|
resolve: {
|
|
alias: {
|
|
'@': './src',
|
|
'@tests': './tests'
|
|
}
|
|
},
|
|
// Define different configurations for different environments
|
|
define: {
|
|
'process.env.NODE_ENV': '"test"'
|
|
}
|
|
})
|