feat: add diagnostics and telemetry runtime
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createBrowserStorageAdapter } from "../../src/adapters/storage/browser-storage-adapter.js";
|
||||
import {
|
||||
@@ -61,13 +61,27 @@ describe("storage registry", () => {
|
||||
|
||||
it("falls back to memory when preference storage quota is exceeded", () => {
|
||||
const localStorage = createStorage({ quota: true });
|
||||
const adapter = createBrowserStorageAdapter({ localStorage });
|
||||
const record = vi.fn();
|
||||
const adapter = createBrowserStorageAdapter({
|
||||
localStorage,
|
||||
diagnostics: { record },
|
||||
});
|
||||
expect(adapter.write("COLOR_SCHEME", "dark")).toMatchObject({
|
||||
ok: false,
|
||||
fallback: "memory",
|
||||
error: { kind: "STORAGE_QUOTA_EXCEEDED" },
|
||||
});
|
||||
expect(adapter.read("COLOR_SCHEME")).toEqual({ ok: true, value: "dark" });
|
||||
expect(record).toHaveBeenCalledOnce();
|
||||
expect(record).toHaveBeenCalledWith({
|
||||
level: "warn",
|
||||
eventId: "storage.operation.failed",
|
||||
context: {
|
||||
operation: "write:COLOR_SCHEME",
|
||||
error_kind: "STORAGE_QUOTA_EXCEEDED",
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(record.mock.calls)).not.toContain("dark");
|
||||
});
|
||||
|
||||
it("discards data from a previous schema version", () => {
|
||||
|
||||
Reference in New Issue
Block a user