test: typecheck test files in CI; drop mock-only test; richer chrome mock
- typecheck now also runs tsc over tsconfig.test.json (test files were never type-checked before). - Delete tests/unit/background.test.ts, which only asserted the vitest chrome mock's own behavior — every remaining test imports production code from src/lib. - Baseline mock gains runtime.id, storage.session/remove, contextMenus, and tabs.sendMessage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
describe('Background Service Worker', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return error when no API key is configured', async () => {
|
||||
(chrome.storage.local.get as any).mockImplementation((keys: any, cb: any) => cb({}));
|
||||
|
||||
// Simulate the handleAnalyzeText function behavior
|
||||
const config = await new Promise<any>((resolve) =>
|
||||
chrome.storage.local.get(['provider', 'apiKey', 'model'], resolve)
|
||||
);
|
||||
|
||||
expect(config.apiKey).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should store API key correctly', async () => {
|
||||
const testConfig = { provider: 'openai', apiKey: 'sk-test123', model: 'gpt-4o-mini' };
|
||||
|
||||
await new Promise<void>((resolve) =>
|
||||
chrome.storage.local.set(testConfig, resolve)
|
||||
);
|
||||
|
||||
expect(chrome.storage.local.set).toHaveBeenCalledWith(testConfig, expect.any(Function));
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,15 @@
|
||||
// Mock Chrome extension APIs
|
||||
// Baseline Chrome extension API mock. Individual tests may rebuild
|
||||
// global.chrome to control specifics (e.g. runtime.id presence).
|
||||
global.chrome = {
|
||||
storage: {
|
||||
local: {
|
||||
get: vi.fn((keys, cb) => cb({})),
|
||||
set: vi.fn((data, cb) => cb && cb()),
|
||||
remove: vi.fn((keys, cb) => cb && cb()),
|
||||
},
|
||||
session: {
|
||||
get: vi.fn((keys, cb) => cb({})),
|
||||
set: vi.fn((data, cb) => cb && cb()),
|
||||
},
|
||||
sync: {
|
||||
get: vi.fn((keys, cb) => cb({})),
|
||||
@@ -11,10 +17,24 @@ global.chrome = {
|
||||
},
|
||||
},
|
||||
runtime: {
|
||||
id: 'test-extension-id',
|
||||
sendMessage: vi.fn(),
|
||||
onMessage: {
|
||||
addListener: vi.fn(),
|
||||
},
|
||||
onInstalled: {
|
||||
addListener: vi.fn(),
|
||||
},
|
||||
openOptionsPage: vi.fn(),
|
||||
},
|
||||
contextMenus: {
|
||||
create: vi.fn(),
|
||||
removeAll: vi.fn((cb) => cb && cb()),
|
||||
onClicked: {
|
||||
addListener: vi.fn(),
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
sendMessage: vi.fn(),
|
||||
},
|
||||
} as any;
|
||||
|
||||
Reference in New Issue
Block a user