Skip to content

Commit ba6312b

Browse files
committed
fix(tests): mock chrome for vitest tests
1 parent 0bb898a commit ba6312b

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"build": "cross-env NODE_ENV=production run-s dist type:check 'vite:build {@}' --",
4141
"build:web": "VITE_WEB=true VITE_BASE=/trakt-extension/ pnpm run build",
4242
"analyse": "vite-bundle-visualizer",
43-
"test:unit": "vitest run --environment jsdom --coverage",
44-
"test:watch": "vitest --environment jsdom",
43+
"test:unit": "vitest run --coverage",
44+
"test:watch": "vitest",
4545
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
4646
"lint": "eslint .",
4747
"lint:fix": "pnpm run lint --fix",

src/settings/traktv.api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const Staging = {
2222

2323
const isProd = import.meta.env.PROD;
2424

25-
const client = !isProd ? Production : Staging;
25+
const client = isProd ? Production : Staging;
2626

2727
const browserRedirect = window.location.href.split('#').at(0) ?? client.RedirectionUrl;
2828

src/utils/browser/browser.utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const openTab = (options: chrome.tabs.CreateProperties) => window.open(options.u
1010
/**
1111
* @see [chrome.tabs.create](https://developer.chrome.com/docs/extensions/reference/tabs/#method-create)
1212
*/
13-
export const createTab = chrome?.tabs?.create ?? openTab;
13+
export const createTab = (options: chrome.tabs.CreateProperties) => (chrome?.tabs?.create ?? openTab)(options);
1414

1515
/**
1616
* The ID of the current extension.

vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default defineConfig(() => ({
167167
coverage: {
168168
reportsDirectory: '../coverage',
169169
},
170+
setupFiles: ['../vitest.setup.ts'],
170171
},
171172
optimizeDeps: {
172173
exclude: ['path', 'fast-glob'],

vitest.setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.chrome = {} as typeof chrome;

0 commit comments

Comments
 (0)