- Create browser-ext/ with full extension code (MV3 manifest, background service worker, content script, popup, options page) - Add tRPC API client that communicates with unified monolith endpoints - Implement cache, settings, and phishing detection utilities - Create extension tRPC router in web app (getAuthStatus, linkDevice, reportPhishing) - Configure Vite build with manifest V3 support - Write unit tests for cache, phishing detector, and API client - All 20 tests passing, TypeScript lint clean
41 lines
1016 B
TypeScript
41 lines
1016 B
TypeScript
import { vi } from "vitest";
|
|
|
|
const mockStorage: Record<string, unknown> = {};
|
|
|
|
vi.stubGlobal("chrome", {
|
|
runtime: {
|
|
id: "test-extension-id",
|
|
onInstalled: {
|
|
addListener: vi.fn(),
|
|
},
|
|
onMessage: {
|
|
addListener: vi.fn(),
|
|
},
|
|
sendMessage: vi.fn(),
|
|
openOptionsPage: vi.fn(),
|
|
},
|
|
storage: {
|
|
sync: {
|
|
get: vi.fn((keys: string | string[] | Record<string, unknown>) => {
|
|
if (typeof keys === "string") {
|
|
return Promise.resolve({ [keys]: mockStorage[keys] ?? null });
|
|
}
|
|
if (Array.isArray(keys)) {
|
|
const result: Record<string, unknown> = {};
|
|
for (const key of keys) result[key] = mockStorage[key] ?? null;
|
|
return Promise.resolve(result);
|
|
}
|
|
return Promise.resolve({});
|
|
}),
|
|
set: vi.fn((items: Record<string, unknown>) => {
|
|
Object.assign(mockStorage, items);
|
|
return Promise.resolve();
|
|
}),
|
|
},
|
|
local: {
|
|
get: vi.fn(),
|
|
set: vi.fn(),
|
|
},
|
|
},
|
|
});
|