refactor: port lib layer to src/lib

classic-mode.js moves byte-for-byte. champion-data.js swaps the Next.js
env-var fetch prefix for asset() from $app/paths, which resolves to
/champions.json in dev and /loldle/champions.json in the deployed build.
getChampionImageUrl keeps returning an absolute Data Dragon URL, unwrapped.

Drops three exports with no callers: getAllChampions, getChampionByName,
getGuessedNames.

The characterization suite passes unchanged against the new location -- only
import specifiers moved, no assertions touched.
This commit is contained in:
tiennm99 committed 2026-07-25 11:01:40 +07:00
1 parent e2ae34a8ab
commit 078d80c962
7 files changed
+391 -4

No files matched your search

+7 -2
View File
@@ -1,7 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { getChampionImageUrl, getTodaySeed } from "../lib/champion-data";
import { getChampionImageUrl, getTodaySeed } from "$lib/champion-data";
import { AATROX, CHAMPIONS } from "./fixtures/champions";
// $app/paths is a SvelteKit build-time construct with no meaning to a bare
// Vitest run. Base-path behaviour is verified by the production preview check,
// not here, so the identity stub is the honest unit-test substitute.
vi.mock("$app/paths", () => ({ asset: (p) => p }));
/**
* `champions` is module-private with no reset export, so each group gets a fresh
* module instance instead of adding production code for testability.
@@ -14,7 +19,7 @@ async function freshModule({ champions = CHAMPIONS, ok = true, status = 200 } =
json: async () => champions,
}));
vi.stubGlobal("fetch", fetchMock);
const mod = await import("../lib/champion-data");
const mod = await import("$lib/champion-data");
return { mod, fetchMock };
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { CLASSIC_ATTRIBUTES, compareChampions } from "../lib/classic-mode";
import { CLASSIC_ATTRIBUTES, compareChampions } from "$lib/classic-mode";
import { AATROX, AHRI, AKALI, BELVETH } from "./fixtures/champions";
/** Pull one attribute's comparison out of the 7-entry result array. */
+1 -1
View File
@@ -7,7 +7,7 @@ import {
loadUnlimitedStats,
saveUnlimitedStats,
submitGuess,
} from "../lib/game-engine";
} from "$lib/game-engine";
import { AATROX, AHRI } from "./fixtures/champions";
/** Minimal stand-in for compareChampions — the engine only stores what this returns. */