Improve testing page #12700
Replies: 2 comments 2 replies
-
|
Well, since you used the term "upper deck".... 😄 Admittedly, this page has a bit of a "backstory" to it, and I would not be opposed to a rethinking of it! |
Beta Was this translation helpful? Give feedback.
-
Integration and E2E tests are more solved problems, we've been doing those on Starlight and people have also been doing it on many other projects (possibly Adam takes the crown there). Writing tests for integrations as opposed to integration tests for Astro projects is also mostly a solved problem, although not documented in Astro Docs. I do it a lot and have a helper for it. Starlight also does it since it is an integration. Unit tests of TS modules are the same as they would be for normal TS projects. Using Vitest you just write it and it works, using a non-vite-based test runner you need to build the project first and test against the final JS. All well-known within the ecossystem. Unit tests of Astro files "upper deck" is the tricky part. It is hidden inside the rendering pipeline, so currently it can only be tested indirectly. You look at the code, see what HTML you'd expect from that logic and test the HTML. We don't expose any way to test what are the values available for the template, the code and the template become a single thing. I'm not sure we'd want to expose something like that, I think the guarantee of the whole Astro file being "the unit" is the granularity we should have. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
https://docs.astro.build/en/guides/testing/
vitest section
I think this section could have a little more explanation of the consequences of using the getviteconfig() function we suggest here
it is a bit confusing how it actually works, and it is also not strictly needed to use vitest with astro. Particularly that it allows for using astros virtual modules, but it also disallows using real imports from "astro" like the programatic js cli functions ( build dev etc in your tests )
End to end section
this section of this page isn't really going over anything astro specific, so it might be worth it to, instead of explain to users how to use these tools, explain the ways that an astro project can be tested. This also wouldnt necessarily be astro specific, but I think it would be more useful than just how to use 3 different tools.
I was thinking something like in the overview we go over unit, integration, end to end giving an example of each ? these terms can get sort of blurry and it would be a bit arbitrary
unit might be testing some logic in the component script ( upper deck ), integration might be testing a .astro component's expected html, e2e might be testing some browser specific logic like i18n language select working
going over how to test actions
might belong to the actions page, but it has come up in the discord, I collected some notes and examples in this repo https://github.com/OliverSpeir/astro-actions-vitest
Beta Was this translation helpful? Give feedback.
All reactions