67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import contentPolicy from "../../shared/content-policy.json" with { type: "json" };
|
|
import { verifyReleaseBundle } from "./verify-release-bundle.mjs";
|
|
|
|
async function fixture() {
|
|
const root = await mkdtemp(path.join(os.tmpdir(), "healer-man-release-bundle-test-"));
|
|
await mkdir(path.join(root, "content", "bundled"), { recursive: true });
|
|
const manifest = {
|
|
schemaVersion: 1,
|
|
packs: contentPolicy.bootstrapPackIds.map((id) => ({ id })),
|
|
files: {},
|
|
};
|
|
const moduleReport = { shelvedModesEnabled: false, chunks: [{ file: "assets/index.js", modules: ["src/App.tsx"] }] };
|
|
const write = async () => {
|
|
await writeFile(path.join(root, "content", "bootstrap-manifest.json"), `${JSON.stringify(manifest)}\n`);
|
|
await writeFile(path.join(root, "bundle-module-report.json"), `${JSON.stringify(moduleReport)}\n`);
|
|
};
|
|
await write();
|
|
return { root, manifest, moduleReport, write };
|
|
}
|
|
|
|
test("accepts the exact compact production policy", async () => {
|
|
const value = await fixture();
|
|
try {
|
|
const report = await verifyReleaseBundle(value.root);
|
|
assert.deepEqual(report.packs, [...contentPolicy.bootstrapPackIds].sort());
|
|
assert.equal(report.storedBytes, 0);
|
|
} finally {
|
|
await rm(value.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("rejects arena packs and shelved client modules", async () => {
|
|
const value = await fixture();
|
|
try {
|
|
value.manifest.packs.push({ id: "core:arenas" });
|
|
await value.write();
|
|
await assert.rejects(verifyReleaseBundle(value.root), /bootstrap packs/);
|
|
|
|
value.manifest.packs.pop();
|
|
value.moduleReport.chunks[0].modules.push("src/ArenaRuntime.tsx");
|
|
await value.write();
|
|
await assert.rejects(verifyReleaseBundle(value.root), /shelved client modules/);
|
|
} finally {
|
|
await rm(value.root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("rejects a bootstrap above the stored-byte budget", async () => {
|
|
const value = await fixture();
|
|
try {
|
|
value.manifest.files["/large.glb"] = {
|
|
packId: "core:runtime",
|
|
url: `/content/bundled/${"c".repeat(64)}.glb`,
|
|
bytes: contentPolicy.maxBootstrapStoredBytes + 1,
|
|
};
|
|
await value.write();
|
|
await assert.rejects(verifyReleaseBundle(value.root), /limit is/);
|
|
} finally {
|
|
await rm(value.root, { recursive: true, force: true });
|
|
}
|
|
});
|