diff --git a/eslint.config.mjs b/eslint.config.mjs index d776629a..4afdbe92 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -86,7 +86,7 @@ export default [ // Test files specific config { - files: ['e2e/**/*', 'playwright.config.ts', 'vitest.config.ts'], + files: ['e2e/**/*', 'playwright.config.ts', 'vitest.config.ts', 'vitest.init.ts'], languageOptions: { parserOptions: { project: './tsconfig.test.json', diff --git a/src/ui/utils/__tests__/index.test.ts b/src/ui/utils/__tests__/index.test.ts index ced5fd4e..9613c48d 100644 --- a/src/ui/utils/__tests__/index.test.ts +++ b/src/ui/utils/__tests__/index.test.ts @@ -1,19 +1,3 @@ -import { describe, it, expect, vi } from 'vitest'; - -// Mock the function -vi.mock('../../utils', () => ({ - HexToDecimalConverter: (hexValue: string) => { - const convertHexToDecimal = (hex) => { - if (!hex.startsWith('0x')) { - hex = '0x' + hex; - } - return BigInt(hex).toString(); - }; - const decimalValue = convertHexToDecimal(hexValue); - return decimalValue; - }, -})); - // Import from the mocked module import { HexToDecimalConverter } from '../../utils'; diff --git a/tsconfig.test.json b/tsconfig.test.json index 95573a21..5b8974c1 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,6 +1,6 @@ { "extends": "./tsconfig.json", - "include": ["e2e/**/*", "playwright.config.ts", "vitest.config.ts"], + "include": ["e2e/**/*", "playwright.config.ts", "vitest.config.ts", "vitest.init.ts"], "compilerOptions": { "types": ["@playwright/test"] } diff --git a/vitest.config.ts b/vitest.config.ts index 72aebbe1..c705de9e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,5 +8,20 @@ export default defineConfig({ '**/e2e/**', '**/.{idea,git,cache,output,temp}/**', ], + setupFiles: './vitest.init.ts', + typecheck: { + tsconfig: './tsconfig.test.json', + }, + globals: true, + }, + resolve: { + alias: { + '@': '/src', + utils: '/src/utils', + ui: '/src/ui', + background: '/src/background', + consts: '/src/constant', + assets: '/src/ui/assets', + }, }, }); diff --git a/vitest.init.ts b/vitest.init.ts new file mode 100644 index 00000000..2350f8da --- /dev/null +++ b/vitest.init.ts @@ -0,0 +1,73 @@ +import { vi } from 'vitest'; + +// Mock chrome API +global.chrome = { + runtime: { + sendMessage: vi.fn(), + onMessage: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onUpdated: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onInstalled: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + getURL: vi.fn(), + }, + tabs: { + query: vi.fn(), + sendMessage: vi.fn(), + create: vi.fn(), + onMessage: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onUpdated: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onInstalled: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onRemoved: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + }, + windows: { + query: vi.fn(), + create: vi.fn(), + onFocusChanged: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + onRemoved: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + }, + notifications: { + create: vi.fn(), + onClicked: { + addListener: vi.fn(), + removeListener: vi.fn(), + }, + }, + storage: { + local: { + get: vi.fn(), + set: vi.fn(), + }, + sync: { + get: vi.fn(), + set: vi.fn(), + }, + }, + + // Add any other Chrome APIs you're using +} as any;