Skip to content

Commit fa8489d

Browse files
committed
Replace Jest with Vitest
1 parent 88fd5ee commit fa8489d

File tree

7 files changed

+209
-1831
lines changed

7 files changed

+209
-1831
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ Inspired by [this video](https://www.youtube.com/watch?v=kYl271X2LNA).
1818

1919
## Development
2020

21+
> Requires Node >=v14
22+
2123
1. Clone this template
2224
2. Install dependencies with `yarn`
23-
3. `yarn build:watch` to build into `dist`, launch a chromium window with the extension installed, and rebuild on file changes
25+
3. `yarn dev` to build into `dist`, launch a chromium window with the extension installed, and rebuild on file changes
2426
4. `yarn test` to run unit tests
2527

2628
## Building
2729

28-
1. `yarn build:prod` to build into `dist`
30+
1. `yarn build` to build into `dist`
2931
2. Enable dev mode in `chrome://extensions/` and upload your extension
3032
- If you want to develop for Firefox, you need the [web-ext cli](https://extensionworkshop.com/documentation/develop/web-ext-command-reference/)
3133
- Also take a look at the [dynamic browser options](https://vite-plugin-web-extension.aklinker1.io/guide/configuration.html#browser-specific-manifest-fields) in `vite-plugin-web-extension` if you don't want to use `webextension-polyfill`

package.json

+5-37
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,25 @@
33
"version": "0.0.1",
44
"description": "",
55
"scripts": {
6-
"build:watch": "cross-env SOURCEMAP=true vite build --watch",
7-
"build:prod": "vite build",
8-
"test": "jest"
6+
"dev": "cross-env SOURCEMAP=true vite build --watch",
7+
"build": "vite build",
8+
"test": "vitest"
99
},
1010
"author": "Thomas Chin",
1111
"license": "ISC",
1212
"devDependencies": {
13-
"@types/jest": "^29.1.1",
1413
"@types/webextension-polyfill": "^0.9.1",
1514
"@vitejs/plugin-vue": "^3.1.0",
1615
"@vue/test-utils": "^2.1.0",
17-
"@vue/vue3-jest": "28",
1816
"cross-env": "^7.0.3",
19-
"jest": "^29.1.2",
20-
"jest-environment-jsdom": "^29.1.2",
17+
"jsdom": "^20.0.1",
2118
"postcss": "8.4.17",
2219
"sass": "^1.55.0",
23-
"ts-jest": "^29.0.3",
2420
"typescript": "^4.8.4",
2521
"vite": "^3.1.4",
2622
"vite-plugin-web-extension": "^1.4.4",
23+
"vitest": "^0.23.4",
2724
"vue": "^3.2.40",
2825
"webextension-polyfill": "^0.10.0"
29-
},
30-
"jest": {
31-
"moduleFileExtensions": [
32-
"ts",
33-
"tsx",
34-
"vue",
35-
"js",
36-
"jsx",
37-
"json",
38-
"node"
39-
],
40-
"moduleNameMapper": {
41-
"^@/(.*)$": "<rootDir>/src/$1"
42-
},
43-
"testEnvironment": "jsdom",
44-
"testEnvironmentOptions": {
45-
"customExportConditions": [
46-
"node",
47-
"node-addons"
48-
]
49-
},
50-
"transform": {
51-
"^.+\\.vue$": "@vue/vue3-jest",
52-
"^.+\\.tsx?$": "ts-jest"
53-
},
54-
"transformIgnorePatterns": [
55-
"/node_modules/"
56-
],
57-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$"
5826
}
5927
}

src/tests/example.spec.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
import { shallowMount } from "@vue/test-utils";
2-
import OptionsScreen from "@/options/OptionsScreen.vue";
2+
import OptionsScreen from "../options/OptionsScreen.vue";
3+
import browser from "webextension-polyfill";
4+
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
35

46
describe("OptionsScreen.vue", () => {
7+
beforeAll(() => {
8+
vi.mock("webextension-polyfill", () => ({
9+
default: {
10+
runtime: {
11+
sendMessage: vi.fn(),
12+
},
13+
},
14+
}));
15+
});
16+
517
test("renders options page when passed", () => {
618
const wrapper = shallowMount(OptionsScreen, {});
719
expect(wrapper.text()).toMatch("Options Page");
20+
expect(browser.runtime.sendMessage).toBeCalled();
21+
});
22+
23+
afterAll(() => {
24+
vi.clearAllMocks();
825
});
926
});

src/shims-vue.d.ts src/vite-env.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="vite/client" />
2+
13
// https://vuejs.github.io/vetur/guide/setup.html#typescript
24
declare module '*.vue' {
35
import type { DefineComponent } from 'vue'

tsconfig.node.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"moduleResolution": "Node",
66
"allowSyntheticDefaultImports": true
77
},
8-
"include": ["vite.config.ts"]
8+
"include": ["vite.config.ts", "vitest/globals"]
99
}

vitest.config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference types="vitest" />
2+
3+
import { defineConfig } from "vite";
4+
import Vue from "@vitejs/plugin-vue";
5+
6+
export default defineConfig({
7+
plugins: [Vue()],
8+
test: {
9+
globals: true,
10+
environment: "jsdom",
11+
},
12+
});

0 commit comments

Comments
 (0)