Skip to content

Commit 96e413d

Browse files
authored
Vitest (#905)
* Vitest * Coverage config * Clear vitest cache * Run vitest in ci * Coverage directory * Coverage reporter json * Add @preserve to istanbul ignore * Rename coverage directory to js-coverage * Remove jest-fixed-jsdom
1 parent 4e2b2b1 commit 96e413d

File tree

17 files changed

+1178
-467
lines changed

17 files changed

+1178
-467
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ jobs:
1515
- name: Setup node
1616
uses: actions/setup-node@v4
1717
with:
18-
node-version: "20"
18+
node-version: "20"
1919
- name: Install pnpm
2020
run: npm install -g pnpm
2121
- name: Get pnpm store directory
2222
id: pnpm-cache
2323
run: |
24-
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
24+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
2525
- uses: actions/cache@v4
2626
name: Setup pnpm cache
2727
with:
28-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
29-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
30-
restore-keys: |
31-
${{ runner.os }}-pnpm-store-
28+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
29+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
30+
restore-keys: |
31+
${{ runner.os }}-pnpm-store-
3232
- uses: actions/cache@v4
3333
name: Setup Playwright browsers cache
3434
with:
35-
path: /home/runner/.cache/ms-playwright/
36-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37-
restore-keys: |
38-
${{ runner.os }}-playwright-
35+
path: /home/runner/.cache/ms-playwright/
36+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-playwright-
3939
- name: Install packages
4040
run: |
4141
pnpm install
@@ -49,9 +49,9 @@ jobs:
4949
run: |
5050
pnpm run tsc
5151
- name: Clean coverage
52-
run: rm -rf .nyc_output && npx jest --clearCache
53-
- name: Run jest tests
54-
run: pnpm run jest
52+
run: rm -rf .nyc_output && rm -rf node_modules/.vite
53+
- name: Run vitest tests
54+
run: pnpm run vitest
5555
- name: Playwright install
5656
run: npx playwright install chromium
5757
- name: Copy vendor files
@@ -63,13 +63,13 @@ jobs:
6363
if: always()
6464
uses: actions/upload-artifact@v4
6565
with:
66-
if-no-files-found: ignore
67-
name: screenshots
68-
path: test-results/
66+
if-no-files-found: ignore
67+
name: screenshots
68+
path: test-results/
6969
- name: Merge coverage
70-
run: cp jest-coverage/coverage-final.json .nyc_output/coverage_jsdom.json
70+
run: cp js-coverage/coverage-final.json .nyc_output/coverage_jsdom.json
7171
- name: Codecov
7272
uses: codecov/codecov-action@v5
7373
with:
74-
directory: .nyc_output
75-
verbose: true
74+
directory: .nyc_output
75+
verbose: true

config/jest.config.js

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

config/vitest.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
coverage: {
6+
exclude: ['src/playwright'],
7+
include: ['src/**'],
8+
provider: "istanbul",
9+
reporter: ["json"],
10+
reportsDirectory: "js-coverage"
11+
},
12+
environment: "jsdom",
13+
globals: true,
14+
include: ['src/test/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
15+
setupFiles: [
16+
"./src/test/support/setupTests.ts",
17+
"givens/setup.js",
18+
"jest-extended/all",
19+
],
20+
},
21+
});

eslint.config.mjs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import eslint from "@eslint/js";
22
import tseslint from "typescript-eslint";
33
import importPlugin from "eslint-plugin-import";
4-
import jestPlugin from "eslint-plugin-jest";
54
import jestDomPlugin from "eslint-plugin-jest-dom";
65
import perfectionistPlugin from "eslint-plugin-perfectionist";
76
import playwrightPlugin from "eslint-plugin-playwright";
87
import testingLibraryPlugin from "eslint-plugin-testing-library";
8+
import vitestPlugin from "@vitest/eslint-plugin";
99

1010
export default [
1111
eslint.configs.recommended,
@@ -52,23 +52,21 @@ export default [
5252
},
5353
{
5454
files: ["src/test/**/*.ts"],
55-
...jestPlugin.configs["flat/all"],
55+
...vitestPlugin.configs.all,
5656
},
5757
{
5858
files: ["src/test/**/*.ts"],
5959
rules: {
60-
"jest/no-conditional-in-test": "off",
61-
"jest/no-duplicate-hooks": "off",
62-
"jest/no-hooks": "off",
63-
"jest/no-identical-title": "off",
64-
"jest/prefer-ending-with-an-expect": "off",
65-
"jest/prefer-expect-assertions": "off",
66-
"jest/prefer-importing-jest-globals": [
67-
"error",
68-
{ types: ["jest"] },
69-
],
70-
"jest/prefer-lowercase-title": "off",
71-
"jest/require-hook": "off",
60+
"vitest/no-duplicate-hooks": "off",
61+
"vitest/no-hooks": "off",
62+
"vitest/no-identical-title": "off",
63+
"vitest/prefer-describe-function-title": "off",
64+
"vitest/prefer-expect-assertions": "off",
65+
"vitest/prefer-importing-vitest-globals": "off",
66+
"vitest/prefer-lowercase-title": "off",
67+
"vitest/prefer-strict-boolean-matchers": "off",
68+
"vitest/require-hook": "off",
69+
"vitest/require-mock-type-parameters": "off",
7270
},
7371
},
7472
{

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
},
1717
"scripts": {
1818
"ci": "pnpm lint && pnpm tsc && pnpm test",
19-
"jest": "jest --coverage --no-cache --verbose --config ./config/jest.config.js",
20-
"jest-watch": "jest --watch --config ./config/jest.config.js",
19+
"vitest": "vitest run --coverage --config config/vitest.config.ts",
20+
"vitest-watch": "vitest --config config/vitest.config.ts",
2121
"lint": "eslint src",
2222
"production": "./config/production",
2323
"devserver": "SERVE=true rollup --config config/rollup.config.mjs --watch",
@@ -26,7 +26,7 @@
2626
"prettier": "prettier src/*.ts --write --tab-width 4",
2727
"tsc": "tsc --noEmit --project tsconfig.json",
2828
"playwright": "pnpm build-with-coverage && playwright test --config config/playwright.config.js",
29-
"test": "pnpm jest && pnpm playwright"
29+
"test": "pnpm vitest && pnpm playwright"
3030
},
3131
"peerDependencies": {
3232
"jquery": "^3"
@@ -37,7 +37,6 @@
3737
"@babel/preset-env": "^7.28.3",
3838
"@babel/preset-typescript": "^7.27.1",
3939
"@eslint/js": "^9.34.0",
40-
"@jest/globals": "^30.0.5",
4140
"@playwright/test": "^1.55.0",
4241
"@rollup/plugin-babel": "^6.0.4",
4342
"@rollup/plugin-node-resolve": "^16.0.1",
@@ -49,21 +48,19 @@
4948
"@types/jest-axe": "^3.5.9",
5049
"@types/jquery": "^3.5.33",
5150
"@types/node": "^24.3.0",
51+
"@vitest/coverage-istanbul": "^3.2.4",
52+
"@vitest/eslint-plugin": "^1.3.13",
5253
"autoprefixer": "^10.4.21",
53-
"babel-jest": "^30.0.5",
5454
"babel-plugin-istanbul": "^7.0.0",
5555
"eslint": "^9.34.0",
5656
"eslint-plugin-import": "^2.32.0",
57-
"eslint-plugin-jest": "^29.0.1",
5857
"eslint-plugin-jest-dom": "^5.5.0",
5958
"eslint-plugin-perfectionist": "^4.15.0",
6059
"eslint-plugin-playwright": "^2.2.2",
6160
"eslint-plugin-testing-library": "^7.6.6",
6261
"givens": "^1.3.9",
63-
"jest": "^30.0.5",
6462
"jest-axe": "^10.0.0",
6563
"jest-extended": "^6.0.0",
66-
"jest-fixed-jsdom": "^0.0.9",
6764
"jsdom-testing-mocks": "^1.15.2",
6865
"jsonfile": "^6.2.0",
6966
"lodash": "^4.17.21",
@@ -78,7 +75,8 @@
7875
"rollup-plugin-serve": "^3.0.0",
7976
"tslib": "^2.8.1",
8077
"typescript": "^5.9.2",
81-
"typescript-eslint": "^8.40.0"
78+
"typescript-eslint": "^8.40.0",
79+
"vitest": "^3.2.4"
8280
},
8381
"pnpm": {
8482
"onlyBuiltDependencies": [

0 commit comments

Comments
 (0)