Skip to content

Commit 160ad9c

Browse files
committed
Migrate to Vitest
1 parent 963c11d commit 160ad9c

File tree

8 files changed

+1287
-2157
lines changed

8 files changed

+1287
-2157
lines changed

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base, { createConfig } from '@metamask/eslint-config';
2-
import jest from '@metamask/eslint-config-jest';
32
import nodejs from '@metamask/eslint-config-nodejs';
43
import typescript from '@metamask/eslint-config-typescript';
4+
import vitest from '@metamask/eslint-config-vitest';
55

66
const config = createConfig([
77
{
@@ -40,7 +40,7 @@ const config = createConfig([
4040

4141
{
4242
files: ['**/*.test.ts', '**/*.test.js'],
43-
extends: [jest, nodejs],
43+
extends: [vitest, nodejs],
4444
},
4545
]);
4646

jest.config.js

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

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,41 @@
4141
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
4242
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
4343
"prepack": "./scripts/prepack.sh",
44-
"test": "jest && jest-it-up && attw --pack",
45-
"test:watch": "jest --watch"
44+
"test": "vitest && attw --pack",
45+
"test:watch": "vitest --watch"
4646
},
4747
"devDependencies": {
4848
"@arethetypeswrong/cli": "^0.15.3",
4949
"@lavamoat/allow-scripts": "^3.0.4",
5050
"@lavamoat/preinstall-always-fail": "^2.0.0",
5151
"@metamask/auto-changelog": "^4.0.0",
5252
"@metamask/eslint-config": "^14.0.0",
53-
"@metamask/eslint-config-jest": "^14.0.0",
5453
"@metamask/eslint-config-nodejs": "^14.0.0",
5554
"@metamask/eslint-config-typescript": "^14.0.0",
55+
"@metamask/eslint-config-vitest": "^1.0.0",
5656
"@ts-bridge/cli": "^0.6.3",
57-
"@types/jest": "^28.1.6",
5857
"@types/node": "^18.18",
58+
"@vitest/coverage-istanbul": "^3.0.7",
59+
"@vitest/eslint-plugin": "^1.1.4",
5960
"@yarnpkg/types": "^4.0.0-rc.52",
6061
"depcheck": "^1.4.3",
6162
"eslint": "^9.11.0",
6263
"eslint-config-prettier": "^9.1.0",
6364
"eslint-import-resolver-typescript": "^3.6.3",
6465
"eslint-plugin-import-x": "^4.3.0",
65-
"eslint-plugin-jest": "^28.8.3",
6666
"eslint-plugin-jsdoc": "^50.2.4",
6767
"eslint-plugin-n": "^17.10.3",
6868
"eslint-plugin-prettier": "^5.2.1",
6969
"eslint-plugin-promise": "^7.1.0",
70-
"jest": "^28.1.3",
71-
"jest-it-up": "^2.0.2",
7270
"prettier": "^3.3.3",
73-
"prettier-plugin-packagejson": "^2.3.0",
71+
"prettier-plugin-packagejson": "^2.5.8",
7472
"ts-jest": "^28.0.7",
7573
"ts-node": "^10.7.0",
7674
"typedoc": "^0.26.11",
77-
"typescript": "~5.4.5",
78-
"typescript-eslint": "^8.6.0"
75+
"typescript": "~5.7.3",
76+
"typescript-eslint": "^8.6.0",
77+
"vite": "^6.2.0",
78+
"vitest": "^3.0.7"
7979
},
8080
"packageManager": "[email protected]",
8181
"engines": {
@@ -87,7 +87,8 @@
8787
},
8888
"lavamoat": {
8989
"allowScripts": {
90-
"@lavamoat/preinstall-always-fail": false
90+
"@lavamoat/preinstall-always-fail": false,
91+
"vite>esbuild": false
9192
}
9293
}
9394
}

src/index.test-d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { describe, it, expectTypeOf } from 'vitest';
2+
3+
import greeter from '.';
4+
5+
describe('greeter', () => {
6+
it('returns a string', () => {
7+
expectTypeOf(greeter('Huey')).toEqualTypeOf<string>();
8+
});
9+
});

src/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { describe, it, expect } from 'vitest';
2+
13
import greeter from '.';
24

3-
describe('Test', () => {
5+
describe('greeter', () => {
46
it('greets', () => {
57
const name = 'Huey';
68
const result = greeter(name);

tsconfig.test.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"exactOptionalPropertyTypes": true,
5+
"forceConsistentCasingInFileNames": true,
6+
"lib": ["ES2023"],
7+
"module": "ES2022",
8+
"moduleResolution": "Bundler",
9+
"noEmit": true,
10+
"noErrorTruncation": true,
11+
"noUncheckedIndexedAccess": true,
12+
"skipLibCheck": true,
13+
"skipDefaultLibCheck": true,
14+
"strict": true,
15+
"target": "ES2023"
16+
},
17+
"include": [
18+
"./src/**/*.test.ts",
19+
"./src/**/*.test-d.ts"
20+
],
21+
"exclude": ["./dist", "**/node_modules"]
22+
}

vitest.config.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
// Vitest enables watch mode by default. We disable it here, so it can be
6+
// explicitly enabled with `yarn test:watch`.
7+
watch: false,
8+
9+
// The files to include in the test run.
10+
include: ['src/**/*.test.ts'],
11+
12+
coverage: {
13+
enabled: true,
14+
15+
// Configure the coverage provider. We use `istanbul` here, because it
16+
// is more stable than `v8`.
17+
provider: 'istanbul',
18+
19+
// The files to include in the coverage report.
20+
include: [
21+
'src/**/*.ts',
22+
'src/**/*.tsx',
23+
'src/**/*.js',
24+
'src/**/*.jsx',
25+
'src/**/*.mjs',
26+
],
27+
28+
// The files to exclude from the coverage report. Vitest excludes test
29+
// files by default, but not `test-d.ts` files.
30+
exclude: ['src/**/*.test-d.ts'],
31+
32+
// Coverage thresholds. If the coverage is below these thresholds, the
33+
// test will fail.
34+
thresholds: {
35+
// Auto-update the coverage thresholds. When this is enabled, the
36+
// thresholds will be updated automatically when the coverage is
37+
// above the current thresholds.
38+
autoUpdate: true,
39+
40+
branches: 100,
41+
functions: 100,
42+
lines: 100,
43+
statements: 100,
44+
},
45+
},
46+
47+
typecheck: {
48+
enabled: true,
49+
50+
// The path to the tsconfig file to use for type checking.
51+
tsconfig: './tsconfig.test.json',
52+
},
53+
},
54+
});

0 commit comments

Comments
 (0)