| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { describe, expect, it } from "vitest";
- import {
- DEFAULT_PACK_SUBDIR,
- dialogDefaultsFromProject,
- packHints,
- projectYamlFromPack,
- resolvePackRequest,
- } from "../src/pack-options.js";
- describe("dialogDefaultsFromProject", () => {
- it("pre-fills the dialog from project.yaml pack fields", () => {
- const options = dialogDefaultsFromProject(
- { name: "My Farm", icon: "icon.png", pack: { name: "Pinefield Valley", installer: true, mods: true, splitAssets: true } },
- "/proj",
- "fallback",
- );
- expect(options.name).toBe("Pinefield Valley");
- expect(options.icon).toBe("icon.png");
- expect(options.desktop).toBe(true);
- expect(options.installer).toBe(true);
- expect(options.mods).toBe(true);
- expect(options.splitAssets).toBe(true);
- expect(options.outDir).toBe(`/proj/${DEFAULT_PACK_SUBDIR}`);
- });
- it("falls back to the top-level name then the project display name with defaults", () => {
- expect(dialogDefaultsFromProject({ name: "My Farm" }, "/proj", "fallback").name).toBe("My Farm");
- const none = dialogDefaultsFromProject(null, "/proj", "fallback");
- expect(none.name).toBe("fallback");
- expect(none.icon).toBe("");
- expect(none.desktop).toBe(false);
- expect(none.installer).toBe(false);
- expect(none.mods).toBe(false);
- expect(none.splitAssets).toBe(false);
- });
- it("defaults desktop from pack.installer (installer implies desktop; desktop is not persisted)", () => {
- const options = dialogDefaultsFromProject({ pack: { installer: true } }, "/proj", "x");
- expect(options.desktop).toBe(true);
- expect(options.installer).toBe(true);
- });
- });
- describe("projectYamlFromPack", () => {
- it("writes pack fields + icon and preserves the prev display name", () => {
- const data = projectYamlFromPack(
- { name: "Pinefield Valley", icon: "icon.png", desktop: true, installer: true, mods: false, splitAssets: true, outDir: "/proj/dist-pack" },
- { name: "My Farm" },
- );
- expect(data).toEqual({
- name: "My Farm",
- icon: "icon.png",
- pack: { name: "Pinefield Valley", installer: true, mods: false, splitAssets: true },
- });
- });
- it("removes empty name/icon and keeps desktop out of project.yaml", () => {
- const data = projectYamlFromPack(
- { name: "", icon: "", desktop: true, installer: false, mods: false, splitAssets: false, outDir: "" },
- { name: "My Farm", pack: { name: "Old", mods: true } },
- );
- expect(data.pack?.name).toBeUndefined();
- expect(data.pack?.installer).toBe(false);
- expect(data.pack?.mods).toBe(false);
- expect(data.pack?.splitAssets).toBe(false);
- expect(data.icon).toBeUndefined();
- expect(data.name).toBe("My Farm");
- });
- });
- describe("resolvePackRequest", () => {
- it("maps dialog options to a pack request (content/outDir, installer implies desktop)", () => {
- const request = resolvePackRequest(
- "/proj",
- { name: "Pinefield Valley", icon: "", desktop: false, installer: true, mods: true, splitAssets: false, outDir: "" },
- true,
- );
- expect(request).toEqual({
- contentDir: "/proj/content",
- outDir: `/proj/${DEFAULT_PACK_SUBDIR}`,
- desktop: true,
- installer: true,
- splitAssets: false,
- modsDir: "/proj/mods",
- name: "Pinefield Valley",
- });
- });
- it("honors a custom outDir, plain desktop, and omits mods when off or the dir is absent", () => {
- const custom = resolvePackRequest(
- "/proj",
- { name: "", icon: "", desktop: true, installer: false, mods: false, splitAssets: true, outDir: "/tmp/out" },
- true,
- );
- expect(custom.outDir).toBe("/tmp/out");
- expect(custom.splitAssets).toBe(true);
- expect(custom.desktop).toBe(true);
- expect(custom.name).toBeUndefined();
- expect(custom.modsDir).toBeUndefined();
- const noModsDir = resolvePackRequest(
- "/proj",
- { name: "", icon: "", desktop: false, installer: false, mods: true, splitAssets: false, outDir: "" },
- false,
- );
- expect(noModsDir.modsDir).toBeUndefined();
- });
- });
- describe("packHints", () => {
- it("includes desktop and installer commands when those modes are on", () => {
- const hints = packHints({
- defCount: 1,
- kinds: 1,
- assetCount: 0,
- modCount: 0,
- desktop: true,
- installer: true,
- });
- const text = hints.join("\n");
- expect(text).toContain("npm install && npm start");
- expect(text).toContain("npm install && npm run dist");
- });
- it("is site-only without desktop/installer", () => {
- const hints = packHints({ defCount: 1, kinds: 1, assetCount: 0, modCount: 0, desktop: false, installer: false });
- expect(hints).toHaveLength(1);
- expect(hints[0]).toContain("serve the output folder");
- });
- });
|