Typescript compiler error when running tests using Vitest
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
3.28.0
Node.js version
16
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.3
Description
I would like to test my fastify app using vitest, however I have noticed there is a typescript error I can’t seem to get around.
When I run my tests Fastify errors, fastify-autoload cannot import plugin ... . To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app..
I can successfully run the tests when I compile them to Javascript and import the javascript version in the test. This does however, feel a bit hacky. It can also impact the code coverage (depending on how you are generating the javascript).
Steps to Reproduce
Stackbliz link: https://stackblitz.com/edit/node-sdwsoh
Run the npm run test command.
Expected Behavior
Tests can be run in vitest using Typescript without having to compile first, and import the javascript version.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:39 (21 by maintainers)
Top Results From Across the Web
Testing Types | Guide - Vitest
Keep in mind that Vitest doesn't run or compile these files, they are only statically analyzed by the compiler, and because of that...
Read more >How do I fix TSC errors when using vite? - Stack Overflow
I have jest tests in my project as well. When I run vite build it seems to be compiling and bundling my test...
Read more >Testing with Vitest - This Dot Labs
I'm using the VITEST env variable to differentiate when running tests, but if your configuration is too different, you can use another ...
Read more >Introduction to Vitest: in-source testing using Typescript | CodeX
Vitest is a testing toolkit designed to make setting up, writing, and running tests easy. Want to find out more about Vite? Keep...
Read more >How to Do Test-Driven Development with Svelte and Vitest
It helps in mocking the DOM API and running the tests in a reliable method. ... If you are using TypeScript, your TypeScript...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have a potential PR
Might be a config issue on my side, but when I now try my repro again (with the updated package), I get the following:
This is the same issue I got when I tried to do the changes myself.
Again, it might be a config issue on my side, but it’s unclear to me at this point.