Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192/** Tests for the worker-source builders: template fidelity and per-kind worker bodies. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { errorReporterSource, makeCallWorkerBody, makeIterableWorkerBody, nodeWorkerPreambleSource,} from '../dist/final/neutral/index.mjs';
await describe({ name: '', children: [ describe({ name: errorReporterSource, children: [ it({ name: 'carries the error serializer and its AggregateError branch', fn: async () => { expect(errorReporterSource,).toContain('getErrorProperties',); expect(errorReporterSource,).toContain('reportError',); expect(errorReporterSource,).toContain('error.errors',); }, },), ], },),
describe({ name: nodeWorkerPreambleSource, children: [ it({ name: 'shims worker globals and wires the baseUrl module hook', fn: async () => { expect(nodeWorkerPreambleSource,).toContain('node:worker_threads',); expect(nodeWorkerPreambleSource,).toContain('registerHooks',); expect(nodeWorkerPreambleSource,).toContain('workerData.baseUrl',); expect(nodeWorkerPreambleSource,).toContain('globalThis.postMessage',); }, },), ], },),
describe({ name: makeCallWorkerBody.name, children: [ it({ name: 'invokes the serialized function once per message', fn: async () => { /** Worker body for a doubling function. */ const body = makeCallWorkerBody('function (x) { return x; }',); expect(body,).toContain('globalThis.onmessage',); expect(body,).toContain('function (x) { return x; }',); expect(body,).toContain('{id, output}',); expect(body,).toContain('reportError(error, id)',); }, },), ], },),
describe({ name: makeIterableWorkerBody.name, children: [ it({ name: 'normalizes the first return into an iterator and guards next results', fn: async () => { /** Worker body for a generator function. */ const body = makeIterableWorkerBody('function * (x) { yield x; }',); expect(body,).toContain('Symbol.asyncIterator',); expect(body,).toContain('Symbol.iterator',); expect(body,).toContain('iterator.next()',); expect(body,).toContain('Iterator result is not an object',); }, },), ], },), ],},);