Skip to content

Commit 237e73a

Browse files
committed
migrate jest to vitest
1 parent 9df211c commit 237e73a

File tree

4 files changed

+929
-5889
lines changed

4 files changed

+929
-5889
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"type-check": "tsc --noEmit",
4545
"lint": "eslint src --ext .ts,.tsx",
4646
"build": "yarn type-check && yarn lint && vite build",
47-
"test": "react-scripts test",
48-
"eject": "react-scripts eject",
47+
"test": "vitest",
4948
"format": "prettier --write './src/**/*.{ts,tsx}'",
5049
"gen-types": "json2ts src/services/storage/assets/keyboard-definition-schema.json --style.singleQuote > src/gen/types/KeyboardDefinition.ts;",
5150
"storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006 -s public",
@@ -82,7 +81,6 @@
8281
"@types/ajv": "^1.0.0",
8382
"@types/axios": "^0.14.0",
8483
"@types/downloadjs": "^1.4.2",
85-
"@types/jest": "^26.0.15",
8684
"@types/lodash": "^4.14.167",
8785
"@types/node": "^14.14.22",
8886
"@types/prop-types": "^15.7.4",
@@ -99,19 +97,21 @@
9997
"@typescript-eslint/eslint-plugin": "^4.10.0",
10098
"@typescript-eslint/parser": "^7.11.0",
10199
"@vitejs/plugin-react": "^4.3.0",
100+
"@vitejs/plugin-react-swc": "^3.7.0",
102101
"babel-eslint": "^10.1.0",
103102
"eslint": "8.57.0",
104103
"eslint-config-prettier": "^7.0.0",
105104
"eslint-plugin-prettier": "^5.1.3",
106105
"eslint-plugin-react": "^7.21.5",
106+
"happy-dom": "^14.12.0",
107107
"husky": "^4.3.6",
108108
"json-schema-to-typescript": "^10.1.2",
109109
"lint-staged": "^10.5.3",
110110
"prettier": "^3.2.5",
111-
"react-scripts": "^4.0.1",
112111
"sinon": "^11.1.2",
113112
"vite": "^5.2.12",
114-
"vite-plugin-node-polyfills": "^0.22.0"
113+
"vite-plugin-node-polyfills": "^0.22.0",
114+
"vitest": "^1.6.0"
115115
},
116116
"husky": {
117117
"hooks": {

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"typeRoots": ["node_modules/@types", "node_modules", "src/@types"],
1919
"types": [
2020
"node",
21-
"@types/jest",
2221
"@types/w3c-web-hid",
2322
"@types/w3c-web-usb",
2423
"@types/w3c-web-serial",
2524
"@types/wicg-file-system-access",
26-
"vite/client"
25+
"vite/client",
26+
"vitest/globals"
2727
]
2828
},
2929
"include": ["src"]

vite.config.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import react from '@vitejs/plugin-react';
1+
/// <reference types="vitest" />
2+
import react from '@vitejs/plugin-react-swc';
23
import { defineConfig, Plugin, loadEnv } from 'vite';
34
import { nodePolyfills } from 'vite-plugin-node-polyfills';
45

@@ -15,20 +16,25 @@ export default defineConfig(({ mode }) => {
1516
server: {
1617
port: 3000,
1718
},
19+
test: {
20+
globals: true,
21+
environment: "happy-dom",
22+
setupFiles: "setupTests.ts"
23+
},
1824
};
1925
});
2026

2127
function envPlugin(): Plugin {
2228
return {
23-
name: 'env-plugin',
29+
name: "env-plugin",
2430
config(_, { mode }) {
25-
const env = loadEnv(mode, '.', ['REACT_APP_', 'NODE_ENV']);
31+
const env = loadEnv(mode, ".", ["REACT_APP_", "NODE_ENV", "PUBLIC_URL"]);
2632
return {
2733
define: Object.fromEntries(
2834
Object.entries(env).map(([key, value]) => [
2935
`import.meta.env.${key}`,
3036
JSON.stringify(value),
31-
])
37+
]),
3238
),
3339
};
3440
},

0 commit comments

Comments
 (0)