chore: harden release checks and package coverage
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/store",
|
||||
"version": "0.8.9",
|
||||
"version": "0.8.11",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { StoreContainer, defineStore } from "../src/index.ts";
|
||||
|
||||
test("memory persistence includes only approved fields and migrates old state", async () => {
|
||||
const original = defineStore({
|
||||
name: "preferences-migration",
|
||||
kind: "global" as const,
|
||||
createSharedState: () => ({ theme: "dark", secret: "initial" }),
|
||||
persist: { storage: "memory" as const, version: 1, include: ["theme"] },
|
||||
actions: {
|
||||
setTheme: {
|
||||
runtime: "client" as const,
|
||||
handler: ({ state }: any, theme: string) => void (state.theme = theme),
|
||||
},
|
||||
},
|
||||
});
|
||||
const first = await new StoreContainer({ runtime: "client" }).use(original);
|
||||
await first.actions.setTheme("light");
|
||||
|
||||
const migrated = defineStore({
|
||||
...original,
|
||||
persist: {
|
||||
storage: "memory" as const,
|
||||
version: 2,
|
||||
include: ["theme"],
|
||||
migrate: (state: any) => ({ ...state, theme: `${state.theme}-v2` }),
|
||||
},
|
||||
});
|
||||
const second = await new StoreContainer({ runtime: "client" }).use(migrated);
|
||||
expect(second.state.theme).toBe("light-v2");
|
||||
expect(second.state.secret).toBe("initial");
|
||||
});
|
||||
Reference in New Issue
Block a user