is it possible to load a different tsconfig for Vitest? I could do it with ts-jest
#1291
Replies: 1 comment
-
|
TL;DR: There’s no Vitest equivalent to ts-jest.tsconfig. Vitest runs inside Vite, and Vite doesn’t support switching tsconfigs at runtime. Use one runtime tsconfig (Vite + Vitest) and separate build/typecheck configs instead. I ran into this exact question coming from a Jest + ts-jest background, and I think your expectation here is completely reasonable. What you're describing "having app code and test code typechecked/compiled under different The surprise with Vitest isn't that the use-case is invalid, but that Vitest doesn't own TypeScript compilation at all. The key realisation for me was: Vite ≠ Vitest. Vitest is not a standalone test runner in the same way Jest is. Vitest runs on top of Vite, and Vite is the thing that owns:
Vitest simply asks Vite to execute files in mode: Because of that:
Even though Vitest supports This is also why options like
Only a subset of Regarding this part of your concern:
That makes perfect sense from an app build perspective. In the Vite/Vitest model, test files are still transpiled on demand by the runtime when tests run, not included in your application build or The supported pattern in Vite/Vitest is therefore:
Example setup you might use:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So as the tittle suggest, the question is to ask if it's possible to load a different
tsconfigfile? Like atsconfig.spec.jsonwhere I could add the paths of my spec files. The problem that I currently have is that I only have 1 tsconfig file for both my Vue+Vite / Vitest project and I don't want, neither need, to transpile the unit test spec files.I know that most boilerplate, like Vitesse for example, would have all their unit tests in a separate
\testfolder in the root but I don't like this structure, I prefer to have my unit tests close to the components/services in a__tests__which I could do easily in JestIn Jest I was able to do load a different tsconfig via
ts-jestwith this config,is that possible in Vitest? I couldn't find anything in the docs neither in any issues//discussions.
I want to have 2 tsconfig, where the base one would be similar to this
{ "compilerOptions": { "target": "es2020", "module": "esnext", "baseUrl": ".", "types": ["node", "quasar", "vite", "vite/client"], "lib": ["esnext", "dom", "dom.iterable", "scripthost"] }, "include": ["src/**/*.ts", "src/**/*.vue", "src/**/*.spec.ts"], "exclude": ["node_modules", "src/**/*.spec.ts"] }and a separate one for Vitest that would look like this
{ "extends": "./tsconfig.base.json", "compilerOptions": { "types": ["vitest/globals"], }, "include": ["src/**/*.spec.ts"] }How can I do this in Vitest? I want to keep current structure of
__tests__close to their source...Beta Was this translation helpful? Give feedback.
All reactions