65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { getLocalStorage, getMemoryStorage, getRemoteStorage } from "./mod.ts";
|
|
import { MemoryStorage, ScopedStorage } from "./basic.ts";
|
|
import { describe, expect, it, runTestServer } from "./testing.ts";
|
|
|
|
/*describe(getLocalStorage, () => {
|
|
it("returns the best storage available", async () => {
|
|
const mockWarn = jest.spyOn(console, "warn").mockImplementation();
|
|
|
|
let storage = getLocalStorage("app1");
|
|
expect(storage).toBeInstanceOf(ScopedStorage);
|
|
expect((storage as any).target).toBeInstanceOf(BrowserLocalStorage);
|
|
expect(mockWarn).not.toHaveBeenCalled();
|
|
|
|
await storage.set("testkey", "testvalue");
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
|
|
|
storage = getLocalStorage("app1");
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
|
|
|
storage = getLocalStorage("app2");
|
|
expect(await storage.get("testkey")).toBeNull();
|
|
|
|
delete (window as any)["localStorage"];
|
|
storage = getLocalStorage("app1");
|
|
expect(storage).toBeInstanceOf(NodeDirectoryStorage);
|
|
|
|
(NodeDirectoryStorage.findUserData as any).mockImplementation(() => {
|
|
throw new Error();
|
|
});
|
|
|
|
storage = getLocalStorage("app1");
|
|
expect(storage).toBeInstanceOf(MemoryStorage);
|
|
expect(mockWarn).toHaveBeenCalledWith(
|
|
"No persistent storage available, using in-memory volatile storage",
|
|
);
|
|
});
|
|
});*/
|
|
|
|
describe(getRemoteStorage, () => {
|
|
it("returns a scoped storage", async () => {
|
|
await runTestServer(async (url) => {
|
|
let storage = getRemoteStorage("app1", url);
|
|
|
|
await storage.set("testkey", "testvalue");
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
|
|
|
storage = getRemoteStorage("app1", url);
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
|
|
|
storage = getRemoteStorage("app2", url);
|
|
expect(await storage.get("testkey")).toBeNull();
|
|
});
|
|
});
|
|
|
|
it("scopes in a private namespace on shared mode", async () => {
|
|
// TODO
|
|
});
|
|
});
|
|
|
|
describe(getMemoryStorage, () => {
|
|
it("returns a memory storage", () => {
|
|
const storage = getMemoryStorage();
|
|
expect(storage).toBeInstanceOf(MemoryStorage);
|
|
});
|
|
});
|