Skip to content

Commit bd90e46

Browse files
committed
chore: replace jest with vitest
1 parent 6e779f7 commit bd90e46

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

jest.config.js

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

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"prettier-base": "prettier . --ignore-unknown --cache --log-level warn",
4848
"rule-doc-generator": "eslint-doc-generator",
4949
"semantic-release": "semantic-release",
50-
"test": "jest",
51-
"test:ci": "pnpm run test --ci --coverage",
52-
"test:watch": "pnpm run test --watch",
50+
"test": "vitest run",
51+
"test:ci": "vitest run --coverage",
52+
"test:watch": "vitest",
5353
"type-check": "tsc --noEmit"
5454
},
5555
"dependencies": {
@@ -63,10 +63,9 @@
6363
"@eslint/eslintrc": "^3.3.1",
6464
"@eslint/js": "^9.35.0",
6565
"@swc/core": "^1.9.3",
66-
"@swc/jest": "^0.2.37",
67-
"@types/jest": "^29.5.14",
6866
"@types/node": "^22.9.3",
6967
"@typescript-eslint/rule-tester": "^8.15.0",
68+
"@vitest/coverage-v8": "^3.2.4",
7069
"del-cli": "^6.0.0",
7170
"eslint": "^9.35.0",
7271
"eslint-config-prettier": "^10.1.8",
@@ -80,14 +79,15 @@
8079
"eslint-remote-tester-repositories": "^1.0.1",
8180
"globals": "^16.3.0",
8281
"husky": "^9.1.7",
83-
"jest": "^29.7.0",
82+
"is-ci": "^3.0.1",
8483
"lint-staged": "^15.2.10",
8584
"prettier": "3.6.2",
8685
"semantic-release": "^25.0.2",
8786
"semver": "^7.6.3",
8887
"ts-node": "^10.9.2",
8988
"typescript": "^5.7.2",
90-
"typescript-eslint": "^8.15.0"
89+
"typescript-eslint": "^8.15.0",
90+
"vitest": "^3.2.4"
9191
},
9292
"peerDependencies": {
9393
"eslint": "^8.57.0 || ^9.0.0"

tests/index.test.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
1-
import { existsSync } from 'fs';
2-
import { resolve } from 'path';
1+
import { existsSync } from 'node:fs';
2+
import { resolve } from 'node:path';
3+
4+
import { it, expect } from 'vitest';
35

46
import plugin from '../lib';
57

68
const numberOfRules = 28;
79
const ruleNames = Object.keys(plugin.rules);
810

9-
// eslint-disable-next-line jest/expect-expect
1011
it('should have a corresponding doc for each rule', () => {
1112
ruleNames.forEach((rule) => {
1213
const docPath = resolve(__dirname, '../docs/rules', `${rule}.md`);
1314

14-
if (!existsSync(docPath)) {
15-
throw new Error(
16-
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
17-
);
18-
}
15+
expect(
16+
existsSync(docPath),
17+
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
18+
).toBe(true);
1919
});
2020
});
2121

22-
// eslint-disable-next-line jest/expect-expect
2322
it('should have a corresponding test for each rule', () => {
2423
ruleNames.forEach((rule) => {
2524
const testPath = resolve(__dirname, './lib/rules/', `${rule}.test.ts`);
2625

27-
if (!existsSync(testPath)) {
28-
throw new Error(
29-
`Could not find test file for rule "${rule}" in path "${testPath}"`
30-
);
31-
}
26+
expect(
27+
existsSync(testPath),
28+
`Could not find test file for rule "${rule}" in path "${testPath}"`
29+
).toBe(true);
3230
});
3331
});
3432

35-
// eslint-disable-next-line jest/expect-expect
3633
it('should have the correct amount of rules', () => {
3734
const { length } = ruleNames;
3835

39-
if (length !== numberOfRules) {
40-
throw new Error(
41-
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
42-
);
43-
}
36+
expect(
37+
numberOfRules,
38+
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
39+
).toEqual(length);
4440
});
4541

4642
it('should export configs that refer to actual rules', () => {

tests/lib/utils/is-testing-library-module.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { it, expect, describe } from 'vitest';
2+
13
import {
24
isCustomTestingLibraryModule,
35
isOfficialTestingLibraryModule,

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["./tests", "./tools"]
3+
"exclude": ["./tests", "./tools", "./vitest.*"]
44
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"outDir": "dist",
1717
"sourceMap": false
1818
},
19-
"include": ["**/*.ts"]
19+
"include": ["**/*.ts", "**/*.mts"]
2020
}

vitest.config.mts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['**/tests/**/*.test.ts'],
6+
setupFiles: ['./vitest.setup.mts'],
7+
coverage: {
8+
thresholds: {
9+
branches: 90,
10+
functions: 90,
11+
lines: 90,
12+
statements: 90,
13+
},
14+
},
15+
},
16+
});

vitest.setup.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { RuleTester } from '@typescript-eslint/rule-tester';
2+
import * as vitest from 'vitest';
3+
4+
// Setup for typescript-eslint RuleTester
5+
// https://typescript-eslint.io/packages/rule-tester/#vitest
6+
7+
RuleTester.afterAll = vitest.afterAll;
8+
RuleTester.it = vitest.it;
9+
RuleTester.itOnly = vitest.it.only;
10+
RuleTester.describe = vitest.describe;

0 commit comments

Comments
 (0)