Initial Commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Browser-bundle gate. Confirms that the `./wasm` subpath entry point
|
||||
* compiles cleanly under `Bun.build({ target: "browser", format: "esm" })`
|
||||
* AND that the produced bundle does not pull in any `node:*` specifier,
|
||||
* Hono, or OTel-SDK dependency.
|
||||
*
|
||||
* The lint script `scripts/lint/check-wasm-subpath-deps.ts` is the
|
||||
* static-analysis counterpart; this test is the runtime confirmation
|
||||
* via the actual Bun bundler.
|
||||
*/
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
describe("wasm subpath bundles for browser target", () => {
|
||||
it("Bun.build emits a valid ESM bundle with no banned specifiers", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
const entry = resolve(__dirname, "..", "..", "src", "wasm", "index.ts");
|
||||
const result = await Bun.build({
|
||||
entrypoints: [entry],
|
||||
target: "browser",
|
||||
format: "esm",
|
||||
external: [
|
||||
"@suaveplan/error",
|
||||
"@suaveplan/api-types",
|
||||
"@opentelemetry/api",
|
||||
"zod",
|
||||
"tslib",
|
||||
],
|
||||
});
|
||||
if (!result.success) {
|
||||
const log = result.logs.map((l) => String(l)).join("\n");
|
||||
throw new Error(`Bun.build failed: ${log}`);
|
||||
}
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.outputs.length).toBeGreaterThan(0);
|
||||
const text = await result.outputs[0]!.text();
|
||||
// No node:* specifier in the produced bundle.
|
||||
expect(text.includes("node:")).toBe(false);
|
||||
// No Hono import in the produced bundle.
|
||||
expect(/from\s+["']hono["']/.test(text)).toBe(false);
|
||||
expect(/from\s+["']@hono\//.test(text)).toBe(false);
|
||||
// No OTel SDK in the produced bundle.
|
||||
expect(/from\s+["']@opentelemetry\/sdk-/.test(text)).toBe(false);
|
||||
// No api-host import.
|
||||
expect(text.includes("@suaveplan/api-host")).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user