-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: main
Are you sure you want to change the base?
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 |
---|---|---|
@@ -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:
|
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", | ||
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. Why use 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. Vitest uses Vite to transpile TypeScript. |
||
"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.