Issue
tsconfig.app.json
included the whole src
folder, which also contained test files. This meant the tests were type-checked by both tsconfig.app.json
and tsconfig.test.json
, which caused conflicts and ESLint didn’t recognize Vitest globals.
Fix
Exclude test files from tsconfig.app.json
so only tsconfig.test.json
handles them.
tsconfig.app.json
{
// Vite defaults...
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/tests/setup.ts"]
}
tsconfig.test.json
{
"compilerOptions": {
"types": ["vitest/globals"],
"lib": ["ES2020", "DOM"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx"
},
"include": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/tests/setup.ts"]
}
After this change, ESLint recognized describe
, it
, expect
, etc.
(Optional): I also added @vitest/eslint-plugin
to my ESLint config. Not required for fixing the globals error, but helpful for extra rules and best practices in tests.