- 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.
24 lines
625 B
JavaScript
24 lines
625 B
JavaScript
// Test script to verify that the workerUtils functions work correctly after removing eval
|
|
import { executeInThread } from './dist/unified.js'
|
|
|
|
// Test function to execute in a thread
|
|
const testFunction = `function(args) {
|
|
return "Hello from " + args.name;
|
|
}`
|
|
|
|
// Test with different environments
|
|
async function runTests() {
|
|
try {
|
|
console.log('Testing executeInThread...')
|
|
const result = await executeInThread(testFunction, {
|
|
name: 'Worker Thread'
|
|
})
|
|
console.log('Result:', result)
|
|
|
|
console.log('All tests passed!')
|
|
} catch (error) {
|
|
console.error('Test failed:', error)
|
|
}
|
|
}
|
|
|
|
runTests()
|