Skip to content

Commit

Permalink
Fixed up vitest config
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeckenham committed Dec 19, 2024
1 parent 535b1b6 commit 53a5889
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 18 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 0 additions & 16 deletions src/ui/utils/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Expand Down
15 changes: 15 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
});
73 changes: 73 additions & 0 deletions vitest.init.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 53a5889

Please sign in to comment.