You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
keiko: Storage writes are dropped, since the game's globalThis.localStorage is Node's (undefined), not the page's #130
Under keiko, Storage from @debuffjp/core never writes anything: a game's saves live only in memory, so a logic test can't check that a save was written, and nothing reaches the page's localStorage (game.window.localStorage).
Storage reads and writes globalThis.localStorage (storage.js, local() and write()). When keiko runs the game, that is Node's own global, not the page's: on Node 26 it is undefined unless Node was started with --localstorage-file, and reading it prints ExperimentalWarning: localStorage is not available because --localstorage-file was not provided. So write() returns false and every set is dropped. The page keiko builds has its own localStorage on game.window, which stays empty.
Reproduction
Any game that saves with new Storage(key, defaults) and save.set(...) when something happens, plus:
import{play,test}from"keiko";test("a save reaches the page's localStorage",async()=>{constgame=awaitplay();constbefore={globalHasLocalStorage: (globalThisas{localStorage?: unknown}).localStorage!==undefined,windowIsGlobal: (game.windowasunknown)===globalThis,page: game.window.localStorage.length,};// ...play until the game calls save.set(...)...thrownewError(JSON.stringify({ before,after: {page: game.window.localStorage.length}}));});
Here, after a run that ended with save.set("best", 156):
Point the game's globalThis.localStorage at the page's storage (as for window/document), or have Storage use window.localStorage when a window exists. Then a test can read back what a game saved.
An option on play() to start with given storage contents (or to keep storage from the previous play()), so "the best score survives a reload" can be a logic test. Today each play() starts empty, which is the right default.
Activity