Files
bun-src/test/internal/internal-module-blob.test.ts
2026-08-27 21:09:14 +00:00

40 lines
1.8 KiB
TypeScript

// Correctness guard for the bun_internal_modules_data blob layout
// (src/codegen/bundle-modules.ts + bundle-functions.ts): the WebCoreJSBuiltins
// function sources sit at offset 0, internal module sources follow at generated
// offsets. A wrong offset or length here surfaces as a SyntaxError when JSC
// parses a module or a @-intrinsic builtin function from the blob.
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
test("internal JS builtin function and module sources parse from the linked blob", async () => {
await using proc = Bun.spawn({
cmd: [
bunExe(),
"-e",
`
// WebCoreJSBuiltins path: ReadableStream's reader/pipe machinery is all @-intrinsic
// builtin functions whose source sits at the start of the blob.
const { readable, writable } = new TransformStream({ transform: (c, ctl) => ctl.enqueue(c) });
const w = writable.getWriter();
w.write("blob-ok");
w.close();
const [r] = await Promise.all([readable.getReader().read()]);
// InternalModuleRegistry path: each module's source is a span at a known
// offset into the same blob (release) or read from disk (debug).
const assert = require("node:assert");
assert.strictEqual(require("node:util").format("%s", r.value), "blob-ok");
assert.strictEqual(require("node:path").posix.join("a", "b"), "a/b");
require("node:stream");
require("node:http");
console.log(r.value);
`,
],
env: bunEnv,
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout: stdout.trim(), stderr, exitCode }).toEqual({ stdout: "blob-ok", stderr: "", exitCode: 0 });
});