-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
vitest doesn't work properly with @nestjs/testing #708
Comments
Added reproduction repo https://github.com/wight554/vitest-nestjs-testing
while
From what I've seen in @nestjs/testing it doesn't rely on specific testing framework, so it seems to be vitest issue |
another example:
also I've noticed that this code:
would work if you use some token getter (like |
tested with mocha - works fine as well, so issue is definitely not on nestjs side |
Just to clarify, still fails on vitest@0.3.6 |
vitest@0.4.1 fails too |
@sheremet-va got answer from nest team member |
I don't know much about vite or how it's using esbuild under the hood, but if it is using the async API of esbuild you can use a plugin like esbuild-plugin-tsc to make use of decorators, and the typescript compiler specifically on files that use decorators, but other than that, I know it's out of scope for esbuild to support the |
As I see vite doesn't support esbuild plugins, but allows to disable esbuild in favour of rollup, and rollup has full set of options. E.g. https://github.com/axe-me/vite-plugin-node uses swc for nestjs instead of esbuild |
I've created working example with swc:
|
Oh I see, vite has some kind of esbuild plugin support, but vitest can't benefit from it |
It was closed because we don't use |
I would also prefer using |
Don't think they'll implement additional way to use plugins just for vitest that's lacking it. But if you don't mind, can you do this? I don't think I'll be able to give enough argumentation on why it's needed |
swc is a decent choice, but that implies using another heavyweight compiler in project just for tests. Also it's handled by rollup plugin which makes compilation process more complicated. esbuild has a way to handle this issue, so using it would be preferable imo |
Changing label to upstream, because we are limited by the Vite api. You can open an issue in Vite repo to allow passing esbuild plugins. |
After writing the previous message, I decided to look up how Vite uses Plugins for esbuild are supported only when using esbuild as a bundler, so Vite actually cannot do anything about it. You can try bundle your files with esbuild and run tests against them, although I don't think it will be a good DX, but there is nothing Vitest can do to fix this. To summarize, you can either:
Closing the issue, since it is out of scope of Vitest. |
With this recommendation, I installed https://github.com/egoist/unplugin-swc and it seems to work fine indeed! Hoping the decorator proposal progresses faster so esbuild implements it or that vite supports running esbuild plugins so we could use esbuild-plugin-tsc, using esbuild's fast transpilation while testing with Decorators! |
@V-ed do you have any example on how to integrate SWC into vitest, instead of the default esbuild compiler? We could not find many info about it. |
I haven't done anything else than what is said in the readme of the repo (https://github.com/egoist/unplugin-swc) : Install it using your package manager and use the vite plugin in your configuration (in my case, in the If it's still not working / there's any other issue, I'm afraid I can't really help and you should probably raise another issue with your problem. |
Describe the bug
Running vitest on any sample app from https://github.com/nestjs/nest/tree/master/sample won't run well with testing modules like this
and leads to errors like this:
Might be related to nestjs itself, but runs well on jest
Reproduction
https://github.com/wight554/vitest-nestjs-testing
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: