mirror of
https://github.com/tiennm99/loldle.git
synced 2026-09-01 10:19:42 +00:00
Cover classic-mode comparison rules, game-engine state machine and localStorage persistence, and champion-data search/seeding/loading with Vitest. Storage keys are asserted literally so returning players' saved games and stats cannot silently break. Node environment with a hand-rolled localStorage stub; fixtures are four hand-written champions so the weekly data sync cannot destabilise the suite.
38 lines
641 B
JavaScript
38 lines
641 B
JavaScript
import { beforeEach, vi } from "vitest";
|
|
|
|
/**
|
|
* Minimal spec-shaped localStorage stub.
|
|
* `key(i)` and `length` are required: clearExpiredCache iterates by index.
|
|
*/
|
|
class LocalStorageStub {
|
|
#store = new Map();
|
|
|
|
get length() {
|
|
return this.#store.size;
|
|
}
|
|
|
|
key(i) {
|
|
return [...this.#store.keys()][i] ?? null;
|
|
}
|
|
|
|
getItem(k) {
|
|
return this.#store.has(k) ? this.#store.get(k) : null;
|
|
}
|
|
|
|
setItem(k, v) {
|
|
this.#store.set(k, String(v));
|
|
}
|
|
|
|
removeItem(k) {
|
|
this.#store.delete(k);
|
|
}
|
|
|
|
clear() {
|
|
this.#store.clear();
|
|
}
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.stubGlobal("localStorage", new LocalStorageStub());
|
|
});
|