We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hey team, I've noticed that Vitest's typecheck feature doesn't work even though we have *.test-d.ts files in the repo.
*.test-d.ts
There are 2 apparent issues:
pnpm test
typecheck
vitest.config.ts
vitest.config
import { defineConfig } from 'vitest/config' const resolve = (specifier: string) => new URL(import.meta.resolve(specifier)).pathname export default defineConfig(env => ({ test: { globals: true, include: ['tests/**/*.test.ts'], benchmark: { include: ['benchmarks/**/*.bench.ts'], }, coverage: { thresholds: { 100: true }, include: ['src/**'], }, setupFiles: env.mode === 'benchmark' ? ['benchmarks/globals.ts'] : [], + typecheck: { + include: ['tests/**/*.test-d.ts'], + enabled: true, + }, }, resolve: { alias: { radashi: resolve('./src/mod.js'), }, }, }))
select.test-d.ts
import * as _ from 'radashi' describe('select types', () => { + test('bogus test to test vitest', () => { + expectTypeOf<number>().toEqualTypeOf<string>() + }) test('select with condition', () => { const array = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: null }, ] const result = _.select( array, item => item.name, item => item.name !== null, ) // No way for TypeScript to understand that the result is a string[] expectTypeOf(result).toEqualTypeOf<(string | null)[]>() }) test('select without condition', () => { const array = [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: null }, ] const result = _.select(array, item => item.name) expectTypeOf(result).toEqualTypeOf<string[]>() }) })
tsconfig.json
{ - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "tests/**/*.test-d.ts"], "compilerOptions": { "allowImportingTsExtensions": true, "moduleResolution": "node", "outDir": "./dist/tmp", "noEmitOnError": true, "declaration": true, "emitDeclarationOnly": true, "isolatedDeclarations": true, "target": "es2017", "lib": ["es2017"], "esModuleInterop": true, "skipLibCheck": true, "strict": true, "paths": { "radashi": ["./src/mod.ts"] }, - "types": [] + "types": ["vitest/globals"] } }
However, this doesn't seem ideal, as the tsconfig.json in tests implies we should configure tests there and not the root tsconfig.json.
tests
Note that solution (2) requires solution (1). It only works with an updated vitest.
Edit: I think I found a good, minimal solution in #245
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Description
Hey team, I've noticed that Vitest's typecheck feature doesn't work even though we have
*.test-d.ts
files in the repo.There are 2 apparent issues:
pnpm test
due to not configuringtypecheck
invitest.config.ts
. It's disabled by default.typecheck
invitest.config.ts
causes typecheck tests to pass blindly, even where there are failing tests.How to reproduce
pnpm test
. You will notice that*.test-d.ts
files are not reported.vitest.config
:pnpm test
again. It looks like all*.test-d.ts
tests are now reported, and pass!*.test-d.ts
files, sayselect.test-d.ts
:pnpm test
again, all*.test-d.ts
tests still pass.Questions
Attempted fixes
tsconfig.json
. The following change fixes the issue:However, this doesn't seem ideal, as the
tsconfig.json
intests
implies we should configure tests there and not the roottsconfig.json
.Note that solution (2) requires solution (1). It only works with an updated vitest.
Edit: I think I found a good, minimal solution in #245
The text was updated successfully, but these errors were encountered: