- Resolve the 2604 extracted icons through a generated static asset URL lookup instead of an eager import.meta.glob, so opening a plugin page no longer pulls every icon as its own dev-server module. - Keep the icon URLs cacheable per rendered element and add a test that the catalog never regains the module glob and that every declared icon file ships.
23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { scumCatalogEntries, scumCatalogIconUrl } from "../examples/scum-server-plugin/features/scum-catalog.js";
|
|
|
|
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../examples/scum-server-plugin");
|
|
const catalogSource = readFileSync(join(pluginRoot, "features/scum-catalog.ts"), "utf8");
|
|
|
|
describe("scum catalog icons", () => {
|
|
it("resolves icons on demand instead of importing each icon as its own module", () => {
|
|
expect(catalogSource).not.toContain("import.meta.glob");
|
|
expect(scumCatalogIconUrl("npcs/zombie11.webp")).toContain("zombie11.webp");
|
|
expect(scumCatalogIconUrl("npcs/does-not-exist.webp")).toBe("");
|
|
});
|
|
|
|
it("ships an icon file for every entry that declares one", () => {
|
|
const missing = scumCatalogEntries.filter((entry) => entry.icon && !existsSync(join(pluginRoot, "assets/scum-catalog", entry.icon)));
|
|
expect(missing.map((entry) => entry.icon)).toEqual([]);
|
|
});
|
|
});
|