- Added `cli-package/brainy-wrapper.js` to patch global `TextEncoder` and `TextDecoder` for Node.js environments, ensuring compatibility with TensorFlow.js. - Implemented unified text encoding utilities in `cli-package/src/utils/textEncoding.ts` for cross-environment consistency. - Enhanced `src/worker.js` and introduced `src/worker.ts` to improve worker execution with better function serialization and error handling. - Updated `package.json`: - Modified the `build` script to include a patch for `TextEncoder`. - Added `test-all` script for multi-environment testing. - Introduced the Puppeteer dependency for browser testing. - Created a favicon generation script `scripts/create-favicon.js` using a base64-encoded icon. - Added `scripts/test-all-environments.js` to run automated tests across Node.js, browser, and CLI environments. - Enhanced `src/utils/workerUtils.ts` to support improved fallback mechanisms and robust worker pooling. This update improves the project's compatibility across environments, refines worker functionalities, and adds comprehensive testing support for reliability.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
// Test script to verify the unified text encoding approach works correctly
|
|
import { BrainyData } from './dist/unified.js'
|
|
|
|
async function testUnifiedEncoding() {
|
|
console.log(
|
|
'Testing unified text encoding approach in Node.js environment...'
|
|
)
|
|
|
|
try {
|
|
// Initialize BrainyData which should trigger the PlatformNode constructor
|
|
console.log('Creating BrainyData instance...')
|
|
const db = new BrainyData()
|
|
|
|
// Initialize the database
|
|
console.log('Initializing database...')
|
|
await db.init()
|
|
|
|
console.log('Test successful! Unified text encoding is working correctly.')
|
|
|
|
// Get database status to verify everything is working
|
|
const status = await db.status()
|
|
console.log('Database status:', status)
|
|
|
|
return true
|
|
} catch (error) {
|
|
console.error('Error during test:', error)
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
testUnifiedEncoding().then((success) => {
|
|
if (success) {
|
|
console.log('Unified text encoding verification completed successfully!')
|
|
} else {
|
|
console.error('Unified text encoding verification failed!')
|
|
process.exit(1)
|
|
}
|
|
})
|