mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
test: local storage specific test
This commit is contained in:
parent
d6412e5536
commit
ad4973aa20
@ -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 () => {
|
||||
const persistentChannelId = "persistent-channel";
|
||||
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
import { ILocalHistory, MemLocalHistory } from "./mem_local_history.js";
|
||||
import { ChannelId, ContentMessage, HistoryEntry } from "./message.js";
|
||||
|
||||
const log = new Logger("sds:persistent-history");
|
||||
|
||||
export interface HistoryStorage {
|
||||
getItem(key: string): string | null;
|
||||
setItem(key: string, value: string): void;
|
||||
@ -48,6 +51,13 @@ export class PersistentHistory implements ILocalHistory {
|
||||
this.memory = new MemLocalHistory();
|
||||
this.storage = options.storage ?? DEFAULT_HISTORY_STORAGE;
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user