2021-06-21 22:05:08 +00:00
|
|
|
import { getLocalStorage, getMemoryStorage, getRemoteStorage } from "./mod.ts";
|
|
|
|
import { MemoryStorage, ScopedStorage } from "./basic.ts";
|
|
|
|
import { describe, expect, it, runTestServer } from "./testing.ts";
|
2019-11-07 21:33:23 +00:00
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
/*describe(getLocalStorage, () => {
|
2019-11-07 21:33:23 +00:00
|
|
|
it("returns the best storage available", async () => {
|
2019-10-02 20:12:55 +00:00
|
|
|
const mockWarn = jest.spyOn(console, "warn").mockImplementation();
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
let storage = getLocalStorage("app1");
|
|
|
|
expect(storage).toBeInstanceOf(ScopedStorage);
|
|
|
|
expect((storage as any).target).toBeInstanceOf(BrowserLocalStorage);
|
2019-10-02 20:12:55 +00:00
|
|
|
expect(mockWarn).not.toHaveBeenCalled();
|
|
|
|
|
2019-11-07 21:33:23 +00:00
|
|
|
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();
|
|
|
|
|
2019-10-02 20:12:55 +00:00
|
|
|
delete (window as any)["localStorage"];
|
2019-11-07 21:33:23 +00:00
|
|
|
storage = getLocalStorage("app1");
|
|
|
|
expect(storage).toBeInstanceOf(NodeDirectoryStorage);
|
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
(NodeDirectoryStorage.findUserData as any).mockImplementation(() => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
2019-11-07 21:33:23 +00:00
|
|
|
|
|
|
|
storage = getLocalStorage("app1");
|
2019-10-02 20:12:55 +00:00
|
|
|
expect(storage).toBeInstanceOf(MemoryStorage);
|
2021-06-21 22:05:08 +00:00
|
|
|
expect(mockWarn).toHaveBeenCalledWith(
|
|
|
|
"No persistent storage available, using in-memory volatile storage",
|
|
|
|
);
|
2019-10-02 20:12:55 +00:00
|
|
|
});
|
2021-06-21 22:05:08 +00:00
|
|
|
});*/
|
2019-11-14 17:15:03 +00:00
|
|
|
|
2019-11-27 21:51:27 +00:00
|
|
|
describe(getRemoteStorage, () => {
|
|
|
|
it("returns a scoped storage", async () => {
|
2021-06-21 22:05:08 +00:00
|
|
|
await runTestServer(async (url) => {
|
|
|
|
let storage = getRemoteStorage("app1", url);
|
2019-11-27 21:51:27 +00:00
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
await storage.set("testkey", "testvalue");
|
|
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
2019-11-27 21:51:27 +00:00
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
storage = getRemoteStorage("app1", url);
|
|
|
|
expect(await storage.get("testkey")).toBe("testvalue");
|
2019-11-27 21:51:27 +00:00
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
storage = getRemoteStorage("app2", url);
|
|
|
|
expect(await storage.get("testkey")).toBeNull();
|
|
|
|
});
|
2019-11-27 21:51:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("scopes in a private namespace on shared mode", async () => {
|
2021-06-21 22:05:08 +00:00
|
|
|
// TODO
|
2019-11-27 21:51:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-14 17:15:03 +00:00
|
|
|
describe(getMemoryStorage, () => {
|
|
|
|
it("returns a memory storage", () => {
|
|
|
|
const storage = getMemoryStorage();
|
|
|
|
expect(storage).toBeInstanceOf(MemoryStorage);
|
|
|
|
});
|
|
|
|
});
|