Replies: 7 comments 20 replies
-
I think that both, Vitest and Playwright are necessary for comprehensive testing. To differentiate between the two: Vitest for component tests, where every dependency is mocked (and "normal" unit tests for business code of course). Playwright for end-to-end tests, where nothing is mocked (or at most outgoing HTTP calls). |
Beta Was this translation helpful? Give feedback.
-
I just updated my |
Beta Was this translation helpful? Give feedback.
-
Created a PR to add Vitest with svelte-create here #5708 My PR adds Sorry, totally missed this discussion. Didn't even know I'll look into Has anyone got an example of a working vitest config utilizing. |
Beta Was this translation helpful? Give feedback.
-
It might be off-topic here, but we also need to figure out how to handle SvelteKit runtime modules like Here are the workarounds I saw so far:
IMO they're hacky for anyone who wants to start testing their SvelteKit app. It'd be better to have a unifying approach. |
Beta Was this translation helpful? Give feedback.
-
Alright so here's my 2 cents on the problem. The problem is currently we have the option for 2 test runners for individual component testing, vitest with testing-library/svelte and Playwright. Using Playwright would be nice since we already use it for e2e tests and it would be nice to not have to install and learn another thing. My problem with this is that their Component testing is currently considered experimental, and seems to have a few issues. Whereas, I would argue that I think Vitest with testing-library/svelte seems to be more stable and currently my company uses it to test production code. I would not feel comfortable right now telling people to start using something experimental like playwright component testing. My point is I don't think either of these approaches are definitive, there are pluses and minuses to each, and I don't think we will ever have a definitive approach. I know a lot of people really like Vitest and would be willing to use it instead of playwright even with playwright installed, and there will definitely always be people that just want to use playwright especially once their component testing gets more stable. Only time will tell. My suggestion would be maybe taking an approach similar to the create-vue where we allow users to chose the test runner they want based on preferences. Basically saying for now we should just embrace the controversy lol. |
Beta Was this translation helpful? Give feedback.
-
Anyone here with a work-around for this? |
Beta Was this translation helpful? Give feedback.
-
Thanks @davipon for the great example project its really helped me understand the testing set up and flow a lot better. However I am still struggling to understand how to test the Load data object in sveltekit. I understand you can set up api mocks but what about server side rendered logic and properties as shown here https://kit.svelte.dev/docs/load I am using server side to securely call some api's and only returning part of the data that I want exposed. Vitest simple starts the render by saying data is not rendered. I can't even return a static test string via the page data object. |
Beta Was this translation helpful? Give feedback.
-
@sveltejs/kit/vite
adds improved support for Vitest and I think we should probably add it tocreate-svelte
though I'd be interested to hear more opinions about this.If we do add it to
create-svelte
there are some questions about the ideal test setup. E.g. do we write component tests with Vitest (possibly with@testing-library/svelte
) or Playwright (@playwright/experimental-ct-svelte
)? And do we keep both test runners (e.g.:vitest
scans*.test.(js|ts)
, playwright scans*.e2e.(js|ts)
) or run everything with a single test runner? Are there other libraries we should include likesvelte-inline-compile
.Should we just kick the can on these questions and not include component testing for the time being? Or document the options and let users decide?
Beta Was this translation helpful? Give feedback.
All reactions