nikolai-cc / svu

Svelte development, supercharged.
https://svu.vercel.app
MIT License
39 stars 3 forks source link

Add tests #7

Closed MathiasWP closed 3 months ago

MathiasWP commented 2 years ago

Definitely something that should be added as early as possible, will make the library a lot more appealing, and it's a lot easier beginning with it from the get-go instead of having it as a technical debt. Also makes it easier for other people to contribute/fix issues.

nikolai-cc commented 2 years ago

I don't like writing tests 😅 In all seriousness, I do agree it is a necessary evil. Do you have a suggestion? SvelteKit suggests Playwright since some time now but I haven't used it before myself.

buhodev commented 2 years ago

There's been some recent discussion on twitter about which approach to take when testing large React apps (e2e vs unit, etc). That discussion led me to do more research and I came across the Prefer Integration Tests? Think twice article that dives deep into the topic. I suggest you to give it a read if you are unsure about what approach to take. Either way, Johnny Magrippis recently uploaded two videos about integrating SvelteKit with Vitest and with Playwright that could be useful for you.

nikolai-cc commented 2 years ago

@buhodev Thanks, I'll check these links out

MathiasWP commented 2 years ago

I can begin working on a test-setup, i'll create a test branch!

nikolai-cc commented 2 years ago

Great! Before you take up all the effort, can you elaborate a little bit on the plan? :)

MathiasWP commented 2 years ago

Looking for finding the minimal required setup to setup tests.

I'm thinking a folder structure like this

- test /
        - action
        - store
        - ...etc

We could define all the tests within this folder, and I'm thinking about using Playwright for svelte-stuff, and Vitest for everything else. Thoughts?

nikolai-cc commented 2 years ago

OK! 👍 Though I'm currently not even sure sure how much we would need Playwright. As the utilities are designed to be as standalone as possible, maybe simply some unit tests per action, etc. with Vitest will suffice?

MathiasWP commented 2 years ago

OK! 👍 Though I'm currently not even sure sure how much we would need Playwright. As the utilities are designed to be as standalone as possible, maybe simply some unit tests per action, etc. with Vitest will suffice?

The difficult thing i that there is no good way to run unit tests with Vitest. I tried with @testing-library/svelte, but they don't have a good api for mocking things like clicks and keyboard-events. Playwright has a lot of that, so it makes it much easier to test things like outside click and clipboard stuff.

nikolai-cc commented 2 years ago

Ah I see. True, now that I think about it would indeed be much easier to test those things in application context. :) I'll get myself up to speed with it in the meantime; let me know how it goes!