mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-04 06:43:12 +00:00
test: local storage specific test
This commit is contained in:
parent
b55967c409
commit
2a0a08d0e2
@ -1260,7 +1260,14 @@ describe("MessageChannel", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Default localStorage persistence", () => {
|
describe("localStorage persistence", function () {
|
||||||
|
// LocalStorage specific tests (browser)
|
||||||
|
before(function () {
|
||||||
|
if (typeof localStorage === "undefined") {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("should restore messages from localStorage on channel recreation", async () => {
|
it("should restore messages from localStorage on channel recreation", async () => {
|
||||||
const persistentChannelId = "persistent-channel";
|
const persistentChannelId = "persistent-channel";
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
||||||
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { ILocalHistory, MemLocalHistory } from "./mem_local_history.js";
|
import { ILocalHistory, MemLocalHistory } from "./mem_local_history.js";
|
||||||
import { ChannelId, ContentMessage, HistoryEntry } from "./message.js";
|
import { ChannelId, ContentMessage, HistoryEntry } from "./message.js";
|
||||||
|
|
||||||
|
const log = new Logger("sds:persistent-history");
|
||||||
|
|
||||||
export interface HistoryStorage {
|
export interface HistoryStorage {
|
||||||
getItem(key: string): string | null;
|
getItem(key: string): string | null;
|
||||||
setItem(key: string, value: string): void;
|
setItem(key: string, value: string): void;
|
||||||
@ -48,6 +51,13 @@ export class PersistentHistory implements ILocalHistory {
|
|||||||
this.memory = new MemLocalHistory();
|
this.memory = new MemLocalHistory();
|
||||||
this.storage = options.storage ?? DEFAULT_HISTORY_STORAGE;
|
this.storage = options.storage ?? DEFAULT_HISTORY_STORAGE;
|
||||||
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
|
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
|
||||||
|
|
||||||
|
if (!this.storage) {
|
||||||
|
log.warn(
|
||||||
|
"Storage backend unavailable (localStorage not found). Falling back to in-memory history. Messages will not persist across sessions."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user