**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:
parent
00039f836f
commit
f0db5b471f
30 changed files with 1799 additions and 1583 deletions
|
|
@ -66,6 +66,11 @@ async function runAllTests() {
|
|||
runCommand('npm run build')
|
||||
log('Main package built successfully!', colors.green)
|
||||
|
||||
// Apply TextEncoder patch
|
||||
log('Applying TextEncoder patch...', colors.yellow)
|
||||
runCommand('node scripts/patch-textencoder.js')
|
||||
log('TextEncoder patch applied successfully!', colors.green)
|
||||
|
||||
// Build the browser package
|
||||
log('Building browser package...', colors.yellow)
|
||||
runCommand('npm run build:browser')
|
||||
|
|
@ -89,6 +94,11 @@ async function runAllTests() {
|
|||
log(textEncodingResult)
|
||||
log('Unified text encoding test completed!', colors.green)
|
||||
|
||||
log('Running TensorFlow and TextEncoder test...', colors.yellow)
|
||||
const tensorflowTextEncoderResult = runCommand('node test-tensorflow-textencoder.js')
|
||||
log(tensorflowTextEncoderResult)
|
||||
log('TensorFlow and TextEncoder test completed!', colors.green)
|
||||
|
||||
logSection('RUNNING BROWSER TESTS')
|
||||
|
||||
// Start a simple HTTP server to serve the test files
|
||||
|
|
@ -214,6 +224,25 @@ async function runAllTests() {
|
|||
log('Fallback test result:', colors.green)
|
||||
log(fallbackResult.replace(/<[^>]*>/g, '').trim())
|
||||
|
||||
// Test TensorFlow and TextEncoder in browser
|
||||
log('Running TensorFlow and TextEncoder browser test...', colors.yellow)
|
||||
await page.goto(`http://localhost:${PORT}/demo/test-tensorflow-textencoder.html`)
|
||||
await page.waitForSelector('#runTest')
|
||||
await page.click('#runTest')
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const resultText = document.getElementById('result').textContent
|
||||
return resultText.includes('Test completed')
|
||||
},
|
||||
{ timeout: 30000 }
|
||||
)
|
||||
|
||||
const browserTensorflowTextEncoderResult = await page.evaluate(() => {
|
||||
return document.getElementById('result').innerHTML
|
||||
})
|
||||
log('TensorFlow and TextEncoder browser test result:', colors.green)
|
||||
log(browserTensorflowTextEncoderResult.replace(/<[^>]*>/g, '').trim())
|
||||
|
||||
// Close the browser and server
|
||||
await browser.close()
|
||||
server.close()
|
||||
|
|
@ -239,6 +268,11 @@ async function runAllTests() {
|
|||
log('Testing pipeline command...', colors.yellow)
|
||||
const pipelineResult = runCommand('brainy test-pipeline "This is a test"')
|
||||
log('Pipeline test completed!', colors.green)
|
||||
|
||||
// Test TensorFlow and TextEncoder in CLI
|
||||
log('Testing TensorFlow and TextEncoder in CLI...', colors.yellow)
|
||||
const cliTensorflowResult = runCommand('brainy test-tensorflow-textencoder')
|
||||
log('TensorFlow and TextEncoder CLI test completed!', colors.green)
|
||||
} catch (error) {
|
||||
log(
|
||||
"CLI tests failed. This might be expected if you don't have the CLI installed globally.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue