Тёмный

Why Vitest Is Better Than Jest 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 136 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 163   
@nikfp
@nikfp 2 года назад
I'm seeing a lot of frustration from folks that are using Jest and don't see the benefit of converting to Vitest, so I thought I would share my experience when switching over. I'm working on a back-end Node API that exposes a Graphql endpoint, and also a Sveltekit project. I have used Vitest in both. - When trying to work with Jest (and also Mocha) I experienced huge hurdles in working with ESM and typescript. The "solution" was to maintain a different tsconfig for testing as the production config, which means they could easily migrate away if I wasn't careful. Also modules in testing were compiling to commonjs and for production were compiling to ESM. - My first attempt to fix this was to use Uvu and TSM together, and I was actually pretty impressed with it. However it is minimal, so any mocking or anything else I was doing needed to be done by hand. This was also an issue for front end testing in Sveltekit. Rather than reinvent the wheel, I gave Vitest a shot and it works great. I was able to get rid of the tsconfig.testing.json file entirely, and still make use of the larger Jest-like API offered by Vitest - Initial test run performance of Vitest vs Mocha (which was similar to Jest when tested previously) were about the same. Uvu did actually go a bit faster right out of the gate, but not really enough to notice. (half a second or less difference) HOWEVER once the test runner was running in watch mode, Vitest was orders of magnitude faster than Jest and Mocha and about twice as fast as Uvu. I think this has to do with the Hot Module Reloading in Vite. - When working in Sveltekit, Vitest just worked. Since Vitest uses the same Vite config, this wasn't all that surprising. Overall I've been happy with Vitest and don't see myself going back to Jest any time soon.
@PieterWigboldus-v5v
@PieterWigboldus-v5v 7 месяцев назад
Jest has an issue to solve ESM for 4 years, that is 1 reason I never use Jest anymore, but Vitest for frontend and the native Node test runner for backend and packages. If you want test ESM with Jest, it compiles it indeed to commonjs, but that is not a real world test for me, because I use ESM in production in the backend. So Jest was for me not useful to test if it works, because you test something different than what we run. if you build something with a build step, like most frontend applications, it is a different situation. But be careful, that the test should build the same as you do in production. But in the backend and packages I never add a build step anymore, so everything is much more simple, and also a lot faster. You can just test the code without waiting on the build.
@marcusthelin9991
@marcusthelin9991 4 месяца назад
I'm back in the Node.js world again after some time working in Golang and I just got reminded how much I hate Jest... Constant import errors and super terrible TS support
@enyakstew7107
@enyakstew7107 2 года назад
I have been struggling for hours trying to setup a react app created with vite and jest until I came across this video. Thank you for this !
@steveh7922
@steveh7922 2 года назад
Just tried it out on the online emulator. So easy to mock an imported ES6 module, I'm switching. Thanks Kyle!
@cocohead2478
@cocohead2478 2 года назад
that's good to hear! I was just wondering if mocking with vitest was easy.
@victorlongon
@victorlongon 2 года назад
Of course you can have your opinion but why do you think mocking with jest is hard/complicated?
@steveh7922
@steveh7922 2 года назад
Aaaand I've now switched back to Cypress
@jaideepshekhar4621
@jaideepshekhar4621 2 года назад
@@steveh7922 What happened? XD
@kamehameha38
@kamehameha38 Год назад
@@steveh7922 Lmao, what happened?
@JoaoPaulo-ox6pr
@JoaoPaulo-ox6pr Год назад
I have lots of nightmares with configuration files for everything, whether it is Eslint, Tsconfig, BabelRC, webpack, there's pratically no material outside the docs about them, i was having so many issues trying to config jest for react/typescript vite builded projects. and then i found this video, you're a lifesaver.
@010timeboy27
@010timeboy27 Год назад
I feel your pain
@johnodonnell5342
@johnodonnell5342 2 года назад
I was wondering how to keep test code out of the bundler. Thanks for describing the config that does that!
@StephenMoreira
@StephenMoreira 2 года назад
Will check this out, Jest is my #1 pain point in my project.
@codehan
@codehan 2 года назад
What‘s your opinion to use vitest within a react project? What about snapshot tests? Is it possible with vitest? I don‘t really see a benfit to be honest. No configs is good but does it really work in larger projects?
@locim9201
@locim9201 2 года назад
Wanna knows these too
@mathnewph
@mathnewph 2 года назад
Don't using react but After a short look at the docs that looked good for react and i'm already using it in a large projet and it juste work great
@erics2133
@erics2133 2 года назад
vitest does jest-compatible snapshot testing, as I understand it, though I've never tried to see how compatible it is.
@igorswies5913
@igorswies5913 2 года назад
I would just test the UI by looking at it, separated from logic (with mock data) and test functionality, but I don't do automatic testing on my project yet tho
@rickyalmeida
@rickyalmeida 2 года назад
@@mathnewph are you using react testing library? is it possible to extend vitest expect with jest-dom matchers?
@michamazurkiewicz80
@michamazurkiewicz80 2 года назад
Man you are such a talented guy. You should prepare something more than just a sum function. For which test looks the same with jest. Boundled files? You should not even keep the test code together with the src to not increase package size. So that’s useless. I would like to see how can I mock with it different async calls, how to test api etc. very bad. Don’t be lazy.
@risitas5874
@risitas5874 2 года назад
The main struggle my team has with Jest is the memory usage. We have 3500 tests and when we run them all, the process slowly eats up more and more ram until it reaches 20-25 GB. If you don't have enough ram, the OS starts to use the harddrive and the tests start to timeout because of the slow speed. Vitest has not solved this issue. Last time I tried it, the process just hung indefinitely.
@LordSuperAstro
@LordSuperAstro 2 года назад
sounds like something is wrong with your tests
@vickylance
@vickylance 2 года назад
@@LordSuperAstro It is not. jest is simply utterly slow to run tests. We have over 6K tests and it just takes 2 hours on dev machine to run all test cases and most of the time it fails due to timeouts
@risitas5874
@risitas5874 2 года назад
@@LordSuperAstro We spent weeks trying to find a cause and we never did. As @Vickylance said, it's a problem with jest.
@parlor3115
@parlor3115 2 года назад
@@vickylance If what you're testing isn't already CPU intensive then it's maybe a GC problem. Maybe try to be more conservative with allocations. Not saying it's not a problem with the framework but maybe you can circumvent it with good programming.
@vickylance
@vickylance 2 года назад
@@parlor3115 the problem is react takes a lot of time to render per test in jest, and 250 frontend devs writing code tests can't be checked for maximum efficiency every time. Even when I just run one test it takes a lot of time to even start the test.
@marcosadriano05
@marcosadriano05 2 года назад
Vite and Vitest save much time, another solution is Jest with SWC instead Babel, its runs really good too.
@joshuasmith2814
@joshuasmith2814 Год назад
I never had an issue using import in jest... so it is hard to argue for that to be the reason to switch. I'd be more interested to see how to test UI components with vitest.
@harsinghsekhon5935
@harsinghsekhon5935 5 месяцев назад
How do you create your react projects? Using vite ? or create-react-app? Because I just had a lot of problems with import.meta statements in vite/react projects while working with jest.
@MrWertixvost
@MrWertixvost 2 месяца назад
Your videos are so insanely good, with fast enough pace and clean speech…. Demon!:)
@Moonwalkerrabhi
@Moonwalkerrabhi Год назад
Hey Kyle, please make a similar video for end to end testing using react native expo+ detox, it would be of great help
@j0hannes5
@j0hannes5 2 года назад
I'd be interested in a more general video about testing libraries, their features and their tradeoffs. And setups you can have, like Webpack + Mocha+Chai + React Testing Library.
@animaniaco6080
@animaniaco6080 2 месяца назад
Let me ask about the parameter with the spread operator (...numbers).... Are you doing it like this so you are not mutating the argument that is sent to the function? Is this because of a good practice to avoid changing the arguments reference?
@yokiyu799
@yokiyu799 2 года назад
I think most of the products from vue team are opinionated, that's why vite or vitest seems less configuration files and easier to setup with, but the tradeoff is also exists behind the scene. From my experience, if you want to setup a well known structure that vite provides you then choose vite, but if you want to setup piece by piece and to have the most extendability then choose webpack rollup cra jest stuff like that. BTW, I don't think a little compile speed gain is worth changing to an opinionated architecture.
@daleryanaldover6545
@daleryanaldover6545 2 года назад
You got a point but the less opinionated a framework become the more ways the code can branch into multiple paradigm that if left unchecked, will become more harder to maintain in the future. This is why most frameworks tends to favor convention over configuration. But then a good framework always adopts good convention or best practices by the community while also leaving spaces for configuration.
@yokiyu799
@yokiyu799 2 года назад
@@daleryanaldover6545 TIL! Can't agree with you more, especially “a good framework always adopts good convention or best practices by the community while also leaving spaces for configuration”.
@webdeveloper2769
@webdeveloper2769 10 месяцев назад
Can you do it with react components
@abuzain859
@abuzain859 9 месяцев назад
Hey Kyle! I watched your video and it is awesome. Now I am using the Vitest in my project but I am getting this error : ( Not implemented: window.computedStyle(elt, pseudoElt) at module.exports (C:\Users\Faizan\Desktop\full-stack ode_modules\jsdom\lib\jsdom\browser ot-implemented.js:9:17) )
@eyyMinda
@eyyMinda 2 года назад
I'm getting an error "No test suite found in file .../vite.config.ts" Can't seem to find a solution :(
@kesavanarayanaanaparthi6428
@kesavanarayanaanaparthi6428 8 месяцев назад
How to configure MUI testing in this project and show me how to run single test. Good content. Love your presentation.
@arzievsultan
@arzievsultan 2 года назад
Why is vite including tests in the bundle if it was not exported? How does work tree shaking in vite? Not based on exports & imports?
@daleryanaldover6545
@daleryanaldover6545 2 года назад
It only includes tests that are inline, meaning the ones you write in your main .js or .ts files. Vite doesn't include the ones from test files as far as I know.
@bryson2662
@bryson2662 2 года назад
Damn, you convinced me. I'm switching. I like in line tests.
@skyzane2735
@skyzane2735 6 месяцев назад
Do you have in depth explanation and examples about diff of toBe and toEqual?
@wahyufebrianto5938
@wahyufebrianto5938 2 года назад
That's Awesome... Thank you for the excellent content❤
@nicolindenau3349
@nicolindenau3349 2 года назад
Why is Typescript not complaining when you call sum without any arguments? The function should only accept an array with numbers. What am I missing?
@jackwright517
@jackwright517 Год назад
strictNullChecks in the tsconfig is false by default. Setting it to true should make TS highlight that as an issue 😁👍
@gritsienkooleg3447
@gritsienkooleg3447 Год назад
Thank you so much) Very helpful!
@shupesmerga4694
@shupesmerga4694 Год назад
Where do I configure vitest for In-source setup on vanilla JS where do i put "types": "vitest/importMeta"
@ElrondMcBong86
@ElrondMcBong86 4 месяца назад
Whats the best approach to add vitest into an EXCISTING project?
@SithLordBishop
@SithLordBishop 2 года назад
Jest drives me mad. Ill have to play with this! Love Vite!
@inasuma8180
@inasuma8180 2 года назад
Jest is very simple already. I’m surprised there is a concern that it’s too complicated. Using babel-jest you can compile down your test code which automatically gives support for modern JS including import/export.
@alext5497
@alext5497 Год назад
doesn't this cram test code into the bundler
@justdoeverything8883
@justdoeverything8883 2 года назад
Vitest is sooooo fast! I'm loving it!
@jsonkody
@jsonkody 11 месяцев назад
11:32 .. easy way of fix that is go after build to production code and erase the test code from the compiled code-soup ._.
@mr.random8447
@mr.random8447 Год назад
Is vitest faster than jest with SWC (Rust)?
@legends_assemble4938
@legends_assemble4938 11 месяцев назад
Thanks!
@WebDevSimplified
@WebDevSimplified 10 месяцев назад
Welcome!
@TruthSeeker23-m4o
@TruthSeeker23-m4o Год назад
can we use Vitesh with NextJS pls make a video on this and latest unit testing video
@nelsonmendezz_
@nelsonmendezz_ 2 года назад
Anthony Fu the best 🚀
@AlanDeveloperz
@AlanDeveloperz 5 месяцев назад
Real world question: How Vitest goes with Mock/Spy and these things for "advanced"
@hikari1690
@hikari1690 2 года назад
Ah something new and old... I've been web dev-ing for almost a year now and never used jest, or maybe have but I have no idea when. Or what it even does
@gauravdobriyal1337
@gauravdobriyal1337 2 года назад
Please make a video on dataset in javascript I am really confused.
@RoKi-bo1mf
@RoKi-bo1mf 2 года назад
Can I use vitest in the existing webpack project (without vite)?
@daleryanaldover6545
@daleryanaldover6545 2 года назад
I don't think vitest will add support to webpack, it would be like giving people more reasons to just stay using webpack.
@RoKi-bo1mf
@RoKi-bo1mf 2 года назад
@@daleryanaldover6545 ok thanks!
@arshadsiddiqui9071
@arshadsiddiqui9071 Год назад
Can you show us this with a normally setup typescript project. I keep getting errors. When using Vite it is pretty seemless though. Edit: Wow it just fixed itself after restarting the IDE. A developer problem needs developer solutions lol.
@umairulislam9048
@umairulislam9048 9 месяцев назад
Well explained
@mocnyfullpucha500ml
@mocnyfullpucha500ml 2 года назад
scarxlus when u became web dev??
@A_Saban
@A_Saban 2 года назад
interesting ill give it a go
@benjaminvenezia1944
@benjaminvenezia1944 Год назад
Hello, whats about vitest + react native? Ty
@benjaminvenezia1944
@benjaminvenezia1944 Год назад
After verification seems Vitest is not supported.
@johnm8358
@johnm8358 2 года назад
How hard to move from jest to vitetest
@pranupranav5563
@pranupranav5563 7 месяцев назад
Import in jest is supported.
@Elduque40
@Elduque40 2 года назад
But axios isn’t version 1 yet. It hasn’t been for years
@Twi1ightFr0st
@Twi1ightFr0st 2 года назад
does anyone here not use any testing library, but use only console.assert with conditionals that run in dev but not in prod? seems lot simpler
@TheSysmat
@TheSysmat 2 года назад
when adding vitest my eslint fail,
@shawnlee6775
@shawnlee6775 2 года назад
Been using it since 0.1 Never going back to Jest.
@quintencabo
@quintencabo 2 года назад
What about cypress
@kshitizshah6685
@kshitizshah6685 2 года назад
Good, but frequently transition on every new tech is bad
@huizhong3713
@huizhong3713 2 года назад
amazing
@eduAIJourney
@eduAIJourney 2 года назад
Vite created by vue framework creator 🔥😍
@karthikm.1804
@karthikm.1804 2 года назад
Pathfinder visualizer project with Vanilla javascript
@mphy
@mphy 2 года назад
awesome
@cmdv42
@cmdv42 2 года назад
💯
@다람쥐-q3l
@다람쥐-q3l 2 года назад
Nice hair style
@hikari1690
@hikari1690 2 года назад
Can the next video be visualizing tigergraph data in vue *hint hint nudge nudge wink wink*
@baka_baca
@baka_baca 2 года назад
The main audience here seems to be developers of frontend apps using Vite. I get the appeal of not wanting to double-configure some things, it makes makes sense. But I can't find a reason to want to switch otherwise, maybe I need to be using Typescript (which is just overkill for what I'm working on these days). Inline tests look nice with the small simple example, but most functions/modules worth testing can quickly end up having hundreds of lines of testing code; I would not want that mixed up with the module itself. Moreover, I wouldn't want to sometimes do inline tests and sometimes not as that is confusing. Also, it looks and feels super hacky to set up this feature with the "define import.vitest = undefined" stuff. I get why it works, but if the configuration on Vitest is so good, why do I have to do something hacky like this at all for such an obvious use-case? Kind of makes me lose confidence with what else might be hiding in the configs. I'm not convinced to switch, I'd rather deal with the rather minimal jest configuration (Vitest doesn't seem to spare me much work at all) than get another opinionated mess from the Vue team. This feels like the Vue team trying to rope developers in more and more to a Vue ecosystem just for the sake of being in that ecosystem without adding much value. They are a hard working team that has helped push some things in the field forward, but for my preferences, they have also consistently picked poor and confusing abstractions that have caused me more headaches than problems solved, why would I want to switch if I'm not using Vite?
@rodbrowning
@rodbrowning 2 года назад
Unfortunately it's not for mobile users
@alexsherzhukov6747
@alexsherzhukov6747 2 года назад
Video named Why Vitest Is Better Than Jest yet not a single reason to use it besides a single controversial feature
@elgalas
@elgalas 2 года назад
"Why Vitest is Better than Jest", links to a Jest video, and says the API is built on top of Jest. Catchy titles much?
@AlessioMichelini
@AlessioMichelini 2 года назад
Sorry man, I generally love your videos, but apart from inline testing, which I would generally prefer to avoid, you can do exactly the same as you did with vitest, with just Jest...
@Ferdimitry
@Ferdimitry 2 года назад
I absolutely agree
@TiberiusGracchi
@TiberiusGracchi 2 года назад
I think the point is that jest is bad
@AlessioMichelini
@AlessioMichelini 2 года назад
@@TiberiusGracchi the video does nothing to show that, also if vitest is just an abstraction of Jest, not sure how it can be any faster.
@heroe1486
@heroe1486 2 года назад
I mean the thumbnail speaks for the video, anyway if someone is telling you, without nuance, that the established solution is bad and the new shinny stuff is good based on a hello world example that's probably irrelevant. But that's the JS Community/RU-vid's need for new content that demand that kind of stuff.
@ob34915
@ob34915 Год назад
Yeah they are same but less configuration with vitest
@FatherPhi
@FatherPhi 2 года назад
My god jest is horrible and ruined my Stripe interview😮‍💨
@avoerman89
@avoerman89 2 года назад
If vitest is the same API as jest, it doesn't really solve the issue with jest's convoluted mocking system which makes it a pain to spy on default function exports. I get that it's faster, but it doesn't look like the jest killer that we need.
@ass_awper
@ass_awper 2 года назад
Amazing content bro love it keep it up
@ando_ow
@ando_ow Год назад
npm create vite . already doesn't work for me lol
@qwertt14
@qwertt14 2 года назад
"it's superfast, it took only 2ms" to sum 2 and 2 ;/ At least try summing a couple thousand numbers
@vamshiart
@vamshiart Год назад
vitest has been very slow in CI pipeline, supposedly 2-3 times slower than jest. I am surprised no one talking about that. We moved to vitest, saw how slow it is and moved back to jest.
@_flavio_silva
@_flavio_silva Год назад
Hey nice video, help a lot. Who to have the `describe`, `expect`, `test`/`it`, etc... global? 😅:)
@Renoistic
@Renoistic 2 года назад
Personally I'm really happy with Jest + React Testing Library but I'll give this a shot. I don't really see a benefit with inline testing though. If you have several small files I'd rather put the test files in a __tests__ folder.
@Cowkill
@Cowkill 2 года назад
Hi Renoistic ! Do you have any source or good tutorial to learn Jest and React Testing Library ? I'm trying to learn it but it's a pain to find any meaningful source, and the doc is a mess. Thanks !
@ShivamMishra-mn6cs
@ShivamMishra-mn6cs 2 года назад
Udemy
@igorswies5913
@igorswies5913 2 года назад
the benefit is that they are easily accessible, tests are meant to be partly a form of documentation
@rickyalmeida
@rickyalmeida 2 года назад
@@Cowkill try kent c dodds courses, they've helped me a lot
@VladBurlutsky
@VladBurlutsky 2 года назад
Is it?My first impression in March that it wasn’t
@kirilltalalykin919
@kirilltalalykin919 2 года назад
im confused about the part at 3:18, where you say import/export in test file is not available in jest. What do you mean by that. I never experienced any problem with jest test files and imports
@AlessioMichelini
@AlessioMichelini 2 года назад
I was about to ask the same, I use ESModules with Jest all the time, never had a problem...
@Zeioth
@Zeioth 10 месяцев назад
I don't doubt there might be some benefit on using vitest, but I doubt it compensates the inflated cost of finding a vitest developer over a jest developer, or having to train people on it. After 10 years trying everything, I've settled with react + express/django + jest because it does what it is supposed to, and they don't break stuff. And those who had to migrate from angularjs to angular know what I'm speaking about.
@fooked1
@fooked1 2 года назад
What import / export issues in Jest?
@warrencedro6832
@warrencedro6832 2 года назад
This is great, could you make a video about Turborepo implementing Vite and Vitetest?
@VasylBatih
@VasylBatih 2 месяца назад
nee more video from vitest
@SithLordBishop
@SithLordBishop 2 года назад
Love to see a follow up on how mocks work.
@kamehameha38
@kamehameha38 Год назад
Currently stuck on how to mock using their test runner. Hope he does an update
@WilChow
@WilChow 2 года назад
Another reason why I need to try out a project with Vite
@tenebrae1191
@tenebrae1191 Год назад
👏
@syz3981
@syz3981 2 года назад
so, Why Vitest Is Better Than Jest ?????
@heroe1486
@heroe1486 2 года назад
Because it's newer and shiny
@milon27
@milon27 Год назад
hi in one folder all of my test file are running parallel , so for testing database conflict data and failed many test. but when I run one file at a time all test are passing. how are configure vitest in a way so that it only run one testfile at a time?
@dixienormus8097
@dixienormus8097 2 года назад
I'd be interested to see how Vitest handles error reporting. Jasmine / Karma is fucking horrible with presenting errors in a comprehensive format. You can spend hours trying to find out what's wrong. Jest has been slightly better over the last year. Wonder how good this is when you're working with subscriptions, fake async zones, state etc.
@hycalvinc
@hycalvinc Год назад
Sadly vitest is much slower then jest and this issue is still not solved after a year
@victorlongon
@victorlongon 2 года назад
If it is quicker than jest AND integrate will in an existing project not using vite it might be worth a try, otherwise no. Does someone here using it in a real world project that does not use vite and can compare with jest?
@MuhammadAhmedAshraf
@MuhammadAhmedAshraf 2 года назад
Am i right that apis are methods properties from a library or framework and URLS like rest
@learn029
@learn029 2 года назад
I can't able to install create react app with yarn which step of command i have to follow
@lovelyboy8056
@lovelyboy8056 Год назад
Jesus so fast and helpful information ❤
@jake8217
@jake8217 2 года назад
I saw this video and thought it would be cool to use it in node. But it has not been smooth sailing. Can you do a video for vitest on nodejs?
@vivekkaushik9508
@vivekkaushik9508 Год назад
What's the benefit of using inline-test?
@mon_codes
@mon_codes 2 года назад
Im hoping that there will be a Vue content from you. 😊
@Noritoshi-r8m
@Noritoshi-r8m 2 года назад
That gif... lol!!
@shupesmerga4694
@shupesmerga4694 Год назад
I'm a simple man, if it's new I install it
@wezter96
@wezter96 2 года назад
Does Vitest work with React Native?
@sendo_19
@sendo_19 2 года назад
Vitest works in nestjs?
@codernerd7076
@codernerd7076 2 года назад
Jest is awful happy to see replacements!
@wfl-junior
@wfl-junior 2 года назад
that's awesome
@danydany6068
@danydany6068 2 года назад
not in angular
Далее
Why Signals Are Better Than React Hooks
16:30
Просмотров 478 тыс.
Попробовал салат! А вы? 😋
00:23
Просмотров 2,7 млн
Why is Vite Everywhere? | Evan You
38:32
Просмотров 34 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 79 тыс.
Vite Crash Course | Faster Alternative To CRA
16:24
Просмотров 203 тыс.
Mocking Asynchronous Functions with Jest
21:50
Просмотров 70 тыс.
Introduction to Jest Testing | JavaScript Unit Tests
25:30
Vitest with React Testing Library, Jest-dom & MSW
18:44
Thoughts About Unit Testing | Prime Reacts
11:21
Просмотров 225 тыс.
Every React Concept Explained in 12 Minutes
11:53
Просмотров 661 тыс.
Попробовал салат! А вы? 😋
00:23
Просмотров 2,7 млн