API reference › @evolu/nodejs › TestBundle › testBundle
function testBundle(
__namedParameters: TestBundleOptions,
): Promise<Readonly<Record<string, Readonly<Record<string, TestBundleSize>>>>>;
Defined in: packages/nodejs/src/TestBundle.ts:188
Bundles, executes, measures, and verifies named cases with every supported bundler.
The fixture must default-export either a value, a promise, or a function that returns one. The resolved value must be structured-cloneable so it can cross the worker boundary. All asynchronous work started by the fixture must be awaited by that returned promise; detached work scheduled after it settles is outside the execution contract. Verification runs outside the measured bundle. Each emitted bundle runs in an isolated worker so evaluation errors, rejected promises, uncaught errors and unhandled rejections observed before completion, and timeouts fail the test without affecting the test process. Cases and bundlers form one flattened job list that runs concurrently, bounded by the CPU parallelism available to the process. If multiple jobs fail, all failures are reported together with their case and bundler names. The returned record contains only raw and Brotli byte counts grouped by case and versioned bundler name, so it can be compared directly with an inline snapshot.
Example
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { testBundle } from "@evolu/nodejs/TestBundle";
const directory = await mkdtemp(join(tmpdir(), "evolu-test-bundle-"));
try {
const entryPath = join(directory, "entry.ts");
await writeFile(entryPath, "export default { answer: 42 };\n");
const result = await testBundle({
cases: {
example: {
entryPath,
verify: (value) => {
expect(value).toEqual({ answer: 42 });
},
},
},
});
for (const size of Object.values(result.example)) {
expect(size.brotliSizeInBytes).toBeGreaterThan(0);
}
} finally {
await rm(directory, { recursive: true });
}