32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { join } from "node:path";
|
|
import { ortAliasPlugin } from "../scripts/ortAlias";
|
|
|
|
// D-051: the Parakeet path must not bring a second onnxruntime into the
|
|
// inference worker. parakeet.js depends on its own onnxruntime-web (1.24.1);
|
|
// the app runs the one Transformers.js pins. Unminified bundles carry a
|
|
// `// node_modules/<path>` comment per bundled module, so count runtimes.
|
|
|
|
const WORKER = join(import.meta.dir, "../src/worker/inference.worker.ts");
|
|
|
|
async function bundledRuntimes(plugins: Bun.BunPlugin[]): Promise<string[]> {
|
|
const build = await Bun.build({ entrypoints: [WORKER], target: "browser", format: "esm", plugins });
|
|
expect(build.success).toBe(true);
|
|
const code = await build.outputs[0]!.text();
|
|
return [...code.matchAll(/^\/\/ (node_modules\/\S*onnxruntime-web\/dist\/\S+)$/gm)].map((m) => m[1]!);
|
|
}
|
|
|
|
describe("inference worker bundle", () => {
|
|
test("with the alias plugin it holds only the Transformers.js onnxruntime", async () => {
|
|
expect(await bundledRuntimes([ortAliasPlugin])).toEqual([
|
|
"node_modules/onnxruntime-web/dist/ort.webgpu.bundle.min.mjs",
|
|
]);
|
|
});
|
|
|
|
test("without it, parakeet.js's own runtime would be bundled too (the plugin is load-bearing)", async () => {
|
|
const runtimes = await bundledRuntimes([]);
|
|
expect(runtimes).toHaveLength(2);
|
|
expect(runtimes.some((path) => path.includes("parakeet.js/node_modules/"))).toBe(true);
|
|
});
|
|
});
|