Skip to content

Commit 2fcbf79

Browse files
dmealingclaude
andcommitted
test(runtime-web): cover loadMetaModel in the browser-bundling gate
load-meta-model.ts imports metamodel constants from @metaobjectsdev/metadata/constants to avoid pulling in the node:url dependency from the package root (#287). This test uses Bun.build() to verify the bundle succeeds and contains loadMetaModel without fileURLToPath, catching any future regressions where someone changes the import. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015NrWUxA6euwvnFcwKxcK6A
1 parent 6796b54 commit 2fcbf79

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

‎client/web/packages/runtime-web/test/browser-bundleable.test.ts‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ async function browserBundle(entry: string): Promise<{ ok: boolean; message: str
4848
}
4949

5050
describe("#287 — browser bundleability", () => {
51+
test("loadMetaModel is reachable in a browser bundle", async () => {
52+
// load-meta-model.ts imports its metamodel constants from
53+
// @metaobjectsdev/metadata/constants. If that ever becomes the package root,
54+
// the root pulls MetaDataLoader -> library-sources.ts -> node:url and this fails.
55+
const out = await Bun.build({ entrypoints: [DIST_ENTRY], target: "browser", throw: false });
56+
const code = await out.outputs[0]?.text() || "";
57+
expect(out.success, out.logs.map((l) => String(l)).join("\n")).toBe(true);
58+
expect(code).toContain("loadMetaModel");
59+
expect(code).not.toContain("fileURLToPath");
60+
});
61+
5162
test("the BUILT runtime-web entry bundles for a browser target", async () => {
5263
// dist/ is what a published consumer resolves. If it is missing the gate is
5364
// meaningless, so say so rather than skipping quietly.
@@ -86,19 +97,4 @@ describe("#287 — browser bundleability", () => {
8697
const { ok } = await browserBundle(root);
8798
expect(ok).toBe(false);
8899
});
89-
90-
test("loadMetaModel is reachable and imports from browser-safe paths", async () => {
91-
// load-meta-model.ts imports TYPE_* from @metaobjectsdev/metadata/constants.
92-
// If it ever imports them from the package root instead, the root pulls
93-
// MetaDataLoader -> library-sources.ts -> node:url and this breaks browser bundles (#287).
94-
// Test 1: load Meta Model function is exported from built dist
95-
const distModule = await import(DIST_ENTRY);
96-
expect(distModule.loadMetaModel).toBeDefined();
97-
expect(typeof distModule.loadMetaModel).toBe("function");
98-
99-
// Test 2: source file imports constants from the safe subpath, not the root
100-
const sourceFile = await Bun.file(join(PKG_ROOT, "src", "load-meta-model.ts")).text();
101-
expect(sourceFile).toContain('from "@metaobjectsdev/metadata/constants"');
102-
expect(sourceFile).not.toMatch(/from ["']@metaobjectsdev\/metadata["']\s*;/);
103-
});
104100
});

0 commit comments

Comments
 (0)