const test = require('node:test'); const assert = require('node:assert/strict'); const {readFile} = require('node:fs/promises'); const {join} = require('node:path'); test('Piper worker is built and started as an ES module', async () => { const [buildScript, runtime] = await Promise.all([ readFile(join(__dirname, '..', 'scripts', 'build-piper.mjs'), 'utf8'), readFile(join(__dirname, '..', 'piper-runtime.js'), 'utf8'), ]); assert.match(buildScript, /outfile: join\(workerRoot, 'piper-worker\.js'\),\s*bundle: true,\s*format: 'esm'/); assert.match(runtime, /new Worker\(workerUrl, \{type: 'module'\}\)/); }); test('Piper runtime discards a worker after a failed initialization for a clean retry', async () => { const runtime = await readFile(join(__dirname, '..', 'piper-runtime.js'), 'utf8'); assert.match(runtime, /TtsSession keeps a singleton even when ONNX initialization fails/); assert.match(runtime, /worker\?\.terminate\(\);\s*worker = null;/); });