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:
@@ -12,7 +12,7 @@
|
|||||||
"zip": "wxt zip",
|
"zip": "wxt zip",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@wxt-dev/module-react": "^1.1.5",
|
"@wxt-dev/module-react": "^1.1.5",
|
||||||
|
|||||||
@@ -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 = {
|
global.chrome = {
|
||||||
storage: {
|
storage: {
|
||||||
local: {
|
local: {
|
||||||
get: vi.fn((keys, cb) => cb({})),
|
get: vi.fn((keys, cb) => cb({})),
|
||||||
set: vi.fn((data, cb) => 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: {
|
sync: {
|
||||||
get: vi.fn((keys, cb) => cb({})),
|
get: vi.fn((keys, cb) => cb({})),
|
||||||
@@ -11,10 +17,24 @@ global.chrome = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
runtime: {
|
runtime: {
|
||||||
|
id: 'test-extension-id',
|
||||||
sendMessage: vi.fn(),
|
sendMessage: vi.fn(),
|
||||||
onMessage: {
|
onMessage: {
|
||||||
addListener: vi.fn(),
|
addListener: vi.fn(),
|
||||||
},
|
},
|
||||||
|
onInstalled: {
|
||||||
|
addListener: vi.fn(),
|
||||||
|
},
|
||||||
openOptionsPage: 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;
|
} as any;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["vitest/globals"]
|
"types": ["chrome", "vitest/globals"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"tests/**/*"
|
"tests/**/*"
|
||||||
|
|||||||
Reference in New Issue
Block a user