-
-
Notifications
You must be signed in to change notification settings - Fork 18
Migrate to Vitest #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to Vitest #260
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,41 +41,41 @@ | |
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog", | ||
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", | ||
"prepack": "./scripts/prepack.sh", | ||
"test": "jest && jest-it-up && attw --pack", | ||
"test:watch": "jest --watch" | ||
"test": "vitest && attw --pack", | ||
"test:watch": "vitest --watch" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "^0.15.3", | ||
"@lavamoat/allow-scripts": "^3.0.4", | ||
"@lavamoat/preinstall-always-fail": "^2.0.0", | ||
"@metamask/auto-changelog": "^4.0.0", | ||
"@metamask/eslint-config": "^14.0.0", | ||
"@metamask/eslint-config-jest": "^14.0.0", | ||
"@metamask/eslint-config-nodejs": "^14.0.0", | ||
"@metamask/eslint-config-typescript": "^14.0.0", | ||
"@metamask/eslint-config-vitest": "^1.0.0", | ||
"@ts-bridge/cli": "^0.6.3", | ||
"@types/jest": "^28.1.6", | ||
"@types/node": "^18.18", | ||
"@typescript-eslint/utils": "^8.6.0", | ||
"@vitest/coverage-istanbul": "^3.0.7", | ||
"@vitest/eslint-plugin": "^1.1.4", | ||
"@yarnpkg/types": "^4.0.0-rc.52", | ||
"depcheck": "^1.4.3", | ||
"eslint": "^9.11.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-typescript": "^3.6.3", | ||
"eslint-plugin-import-x": "^4.3.0", | ||
"eslint-plugin-jest": "^28.8.3", | ||
"eslint-plugin-jsdoc": "^50.2.4", | ||
"eslint-plugin-n": "^17.10.3", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"eslint-plugin-promise": "^7.1.0", | ||
"jest": "^28.1.3", | ||
"jest-it-up": "^2.0.2", | ||
"prettier": "^3.3.3", | ||
"prettier-plugin-packagejson": "^2.3.0", | ||
"ts-jest": "^28.0.7", | ||
"prettier-plugin-packagejson": "^2.5.8", | ||
"ts-node": "^10.7.0", | ||
"typedoc": "^0.26.11", | ||
"typescript": "~5.4.5", | ||
"typescript-eslint": "^8.6.0" | ||
"typescript": "~5.7.3", | ||
"typescript-eslint": "^8.6.0", | ||
"vite": "^6.2.0", | ||
"vitest": "^3.0.7" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
|
@@ -87,7 +87,8 @@ | |
}, | ||
"lavamoat": { | ||
"allowScripts": { | ||
"@lavamoat/preinstall-always-fail": false | ||
"@lavamoat/preinstall-always-fail": false, | ||
"vite>esbuild": false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { describe, it, expectTypeOf } from 'vitest'; | ||
|
||
import greeter from '.'; | ||
|
||
describe('greeter', () => { | ||
it('returns a string', () => { | ||
expectTypeOf(greeter('Huey')).toEqualTypeOf<string>(); | ||
}); | ||
}); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Vite uses For example, if a test in a
And type errors in regular test files are detected as well, as unhandled source errors:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
Mrtenz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"module": "ES2022", | ||
"moduleResolution": "Bundler", | ||
mcmire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true | ||
}, | ||
"include": ["./src/**/*.test.ts", "./src/**/*.test-d.ts"], | ||
"exclude": ["./dist", "**/node_modules"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
// Vitest enables watch mode by default. We disable it here, so it can be | ||
// explicitly enabled with `yarn test:watch`. | ||
watch: false, | ||
|
||
// The files to include in the test run. | ||
include: ['src/**/*.test.ts'], | ||
|
||
coverage: { | ||
enabled: true, | ||
|
||
// Configure the coverage provider. We use `istanbul` here, because it | ||
// is more stable than `v8`. | ||
provider: 'istanbul', | ||
|
||
// The files to include in the coverage report. | ||
include: [ | ||
'src/**/*.ts', | ||
'src/**/*.tsx', | ||
'src/**/*.js', | ||
'src/**/*.jsx', | ||
'src/**/*.mjs', | ||
], | ||
|
||
// The files to exclude from the coverage report. Vitest excludes test | ||
// files by default, but not `test-d.ts` files. | ||
exclude: ['src/**/*.test-d.ts'], | ||
|
||
// Coverage thresholds. If the coverage is below these thresholds, the | ||
// test will fail. | ||
thresholds: { | ||
// Auto-update the coverage thresholds. When this is enabled, the | ||
// thresholds will be updated automatically when the coverage is | ||
// above the current thresholds. | ||
autoUpdate: true, | ||
|
||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
statements: 100, | ||
}, | ||
}, | ||
|
||
typecheck: { | ||
enabled: true, | ||
|
||
// The path to the tsconfig file to use for type checking. | ||
tsconfig: './tsconfig.test.json', | ||
}, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vitest doesn't inject globals like
describe
,it
,expect
by default. We could enable a setting for this, but I think importing is preferred over using globals.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!