**feat(tests): add tests for TextEncoder, TensorFlow.js, and fallback mechanisms**

- Introduced `test-fallback-function.js` and `test-fallback-simple.js` to validate `executeInThread` fallback functionality with both named and anonymous compute-intensive functions.
- Added `test-tensorflow-textencoder.js` for TensorFlow.js and TextEncoder tests in a Node.js environment.
- Created `test-tensorflow-textencoder.html` for browser-based TensorFlow.js and TextEncoder tests.
- Implemented cross-environment test support in `cli-package/src/test-tensorflow-textencoder.ts` for CLI functionality.
- Enhanced `src/utils/embedding.ts`, `textEncoding.ts`, and `brainy-wrapper.js` to include updated global `TextEncoder` and `TextDecoder` utilities for compatibility and worker improvements.
- Standardized and expanded utility methods in `PlatformNode` for broader support, including `isFloat32Array` and `isTypedArray` checks.
- Updated Node.js requirement to `>= 24.4.0` across documentation and configuration files for compatibility improvements.

This update introduces comprehensive testing for fallback mechanisms, TensorFlow.js, and TextEncoder across multiple environments, ensuring robustness and compatibility.
This commit is contained in:
David Snelling 2025-07-11 11:11:56 -07:00
parent 00039f836f
commit f0db5b471f
30 changed files with 1799 additions and 1583 deletions

View file

@ -99,36 +99,32 @@
})
async function runWorkerTest(resultDiv) {
// Define a compute-intensive function using a function expression
// This is more compatible with how the worker evaluates the function string
const computeIntensiveFunction = `
function computeTask(data) {
console.log('Worker/Fallback: Starting computation...');
// Define a compute-intensive function using a simple anonymous function expression
// This format works with both worker and fallback mechanisms
const computeIntensiveFunction = `function(data) {
console.log('Worker/Fallback: Starting computation...');
// Simulate a compute-intensive task
const start = Date.now();
let result = 0;
for (let i = 0; i < data.iterations; i++) {
result += Math.sqrt(i) * Math.sin(i);
// Simulate a compute-intensive task
const start = Date.now();
let result = 0;
for (let i = 0; i < data.iterations; i++) {
result += Math.sqrt(i) * Math.sin(i);
}
const duration = Date.now() - start;
console.log('Worker/Fallback: Computation completed in ' + duration + 'ms');
const globalObj = typeof self !== 'undefined' ? self :
typeof window !== 'undefined' ? window :
{};
return {
result,
duration,
iterations: data.iterations,
webWorkersAvailable: typeof globalObj.Worker !== 'undefined'
};
}
const duration = Date.now() - start;
console.log('Worker/Fallback: Computation completed in ' + duration + 'ms');
const globalObj = typeof self !== 'undefined' ? self :
typeof window !== 'undefined' ? window :
{};
return {
result,
duration,
iterations: data.iterations,
webWorkersAvailable: typeof globalObj.Worker !== 'undefined'
};
}
// Return the function itself
computeTask;
`
// Execute the function