sharing contexts

This commit is contained in:
2026-11-14 13:49:21 -03:00
parent 313098892e
commit a69db0cd2a
13 changed files with 192 additions and 208 deletions
+4 -4
View File
@@ -71,12 +71,12 @@ Deno.test("check-mods runs a mod's content phase, and its files can name the blo
assertEquals(rocks.blocks.map(({ json }) => json.id), ["rocks:lamp", ...CODE_BLOCKS]);
assertEquals(rocks.blocks.slice(1).map(({ file }) => file), CODE_BLOCKS.map(() => "scripts/content.ts"));
// only during setup
// only while the content phase runs
const ctx = (globalThis as unknown as { rocks_ctx: ContentContext }).rocks_ctx;
assertThrows(
() => ctx.blocks.register({ id: "rocks:late", textures: "cubi:missing" }),
Error,
"only be registered during setup",
"block can only be registered while the content phase runs",
);
});
@@ -128,7 +128,7 @@ Deno.test("a content phase's mistakes stop its mod loading, naming the script",
const cases: [string, string][] = [
[
`ctx.blocks.register({ id: "bworld:granite", textures: "cubi:missing" });`,
`scripts/content.ts: block bworld:granite isn't in this mod's namespace "rocks"`,
`scripts/content.ts: block bworld:granite must be in the namespace "rocks"`,
],
[`ctx.blocks.register({ id: "rocks:broken" } as any);`, "scripts/content.ts: block rocks:broken: "],
[
@@ -155,6 +155,6 @@ Deno.test("a content phase's mistakes stop its mod loading, naming the script",
Deno.removeSync(folder, { recursive: true });
assertStringIncludes(
(rejected as Error).message,
`rocks.cubi: script.js: block bworld:granite isn't in this mod's namespace "rocks"`,
`rocks.cubi: script.js: block bworld:granite must be in the namespace "rocks"`,
);
});