Skip to content

Commit 8823a49

Browse files
feat: migrate to Vitest (#748)
1 parent a26ebfa commit 8823a49

20 files changed

+1157
-2020
lines changed

.github/copilot-instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This is the freeCodeCamp UI component library, built with React and Tailwind CSS
1010
- Each component folder typically contains:
1111
- `*.tsx`: Component implementation
1212
- `*.stories.tsx`: Storybook stories
13-
- `*.test.tsx`: Jest tests
13+
- `*.test.tsx`: Vitest tests
1414
- `types.ts`: TypeScript types for props
1515
- Components are exported via `src/index.ts`.
1616
- Styles are managed with Tailwind CSS. The main stylesheet is `src/base.css`, built to `dist/base.css`.
@@ -20,7 +20,7 @@ This is the freeCodeCamp UI component library, built with React and Tailwind CSS
2020

2121
- **Install dependencies:** `pnpm install`
2222
- **Run Storybook:** `pnpm run storybook` (see components in isolation)
23-
- **Run tests:** `pnpm test` (Jest, Testing Library)
23+
- **Run tests:** `pnpm test` (Vitest, Testing Library)
2424
- **Lint:** `pnpm lint`
2525
- **Typecheck:** `pnpm typecheck`
2626
- **Build:** `pnpm run build` (runs clean, CSS build, JS build)
@@ -29,7 +29,7 @@ This is the freeCodeCamp UI component library, built with React and Tailwind CSS
2929

3030
## Testing
3131

32-
- Tests use Jest and React Testing Library.
32+
- Tests use Vitest and React Testing Library.
3333
- CSS imports are stubbed in tests via `__mocks__/styleMock.ts`.
3434
- Use the `should` style for assertions.
3535

eslint.config.mjs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import tseslint from "typescript-eslint";
33
import reactPlugin from "eslint-plugin-react";
44
import reactHooksPlugin from "eslint-plugin-react-hooks";
55
import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
6-
import jestPlugin from "eslint-plugin-jest";
7-
import jestDomPlugin from "eslint-plugin-jest-dom";
6+
import vitestPlugin from "eslint-plugin-vitest";
87
import testingLibraryPlugin from "eslint-plugin-testing-library";
98
import globals from "globals";
109

@@ -63,17 +62,6 @@ export default [
6362
},
6463
},
6564

66-
// Jest DOM recommended
67-
{
68-
files: ["**/*.{js,jsx,ts,tsx}"],
69-
plugins: {
70-
"jest-dom": jestDomPlugin,
71-
},
72-
rules: {
73-
...jestDomPlugin.configs.recommended.rules,
74-
},
75-
},
76-
7765
// Testing Library React
7866
{
7967
files: ["**/*.{js,jsx,ts,tsx}"],
@@ -89,16 +77,15 @@ export default [
8977
{
9078
files: ["**/*.test.{js,ts,jsx,tsx}", "**/*.spec.{js,ts,jsx,tsx}"],
9179
plugins: {
92-
jest: jestPlugin,
80+
vitest: vitestPlugin,
9381
},
9482
languageOptions: {
9583
globals: {
96-
...jestPlugin.environments.globals.globals,
84+
...vitestPlugin.environments.env.globals,
9785
},
9886
},
9987
rules: {
100-
...jestPlugin.configs.recommended.rules,
101-
...jestPlugin.configs.style.rules,
88+
...vitestPlugin.configs.recommended.rules,
10289
},
10390
},
10491

jest-setup.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

jest.config.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"storybook": "storybook dev -p 6006 --no-open",
4343
"storybook:theming": "pnpm run storybook --no-manager-cache",
4444
"clean": "rm -rf dist/*",
45-
"gen-component": "ts-node ./utils/gen-component-script",
46-
"test": "jest",
45+
"gen-component": "tsx ./utils/gen-component-script",
46+
"test": "vitest",
4747
"prepare": "husky",
4848
"typecheck": "tsc"
4949
},
@@ -82,31 +82,29 @@
8282
"@storybook/blocks": "8.6.14",
8383
"@storybook/react": "8.6.14",
8484
"@storybook/react-webpack5": "8.6.14",
85-
"@testing-library/jest-dom": "6.9.1",
85+
"@testing-library/jest-dom": "^6.9.1",
8686
"@testing-library/react": "12.1.5",
8787
"@testing-library/react-hooks": "8.0.1",
8888
"@testing-library/user-event": "14.6.1",
89-
"@types/jest": "29.5.14",
9089
"@types/prismjs": "1.26.5",
9190
"@types/react": "16.14.68",
9291
"@types/react-dom": "16.9.25",
9392
"@types/sanitize-html": "2.16.0",
93+
"@vitest/ui": "4.0.18",
9494
"autoprefixer": "10.4.22",
9595
"babel-loader": "8.4.1",
9696
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
9797
"cross-env": "7.0.3",
9898
"css-loader": "6.11.0",
9999
"eslint": "9.39.2",
100-
"eslint-plugin-jest": "29.12.1",
101-
"eslint-plugin-jest-dom": "5.5.0",
102100
"eslint-plugin-jsx-a11y": "6.10.2",
103101
"eslint-plugin-react": "7.37.5",
104102
"eslint-plugin-react-hooks": "7.0.1",
105103
"eslint-plugin-testing-library": "7.15.4",
104+
"eslint-plugin-vitest": "0.5.4",
106105
"globals": "17.3.0",
107106
"husky": "9.1.7",
108-
"jest": "29.7.0",
109-
"jest-environment-jsdom": "29.7.0",
107+
"jsdom": "25.0.1",
110108
"lint-staged": "15.5.2",
111109
"npm-run-all2": "5.0.2",
112110
"postcss": "8.5.6",
@@ -119,11 +117,11 @@
119117
"storybook": "8.6.17",
120118
"style-loader": "3.3.4",
121119
"tailwindcss": "3.4.18",
122-
"ts-node": "10.9.2",
123120
"tslib": "2.8.1",
124121
"tsx": "4.20.6",
125122
"typescript": "5.9.3",
126-
"typescript-eslint": "8.54.0"
123+
"typescript-eslint": "8.54.0",
124+
"vitest": "4.0.18"
127125
},
128126
"keywords": [
129127
"storybook",

0 commit comments

Comments
 (0)