-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Feature] Component SSR testing #19399
Comments
Agree that this might be useful.
test('default', async ({ mount }) => {
const component = await mount(Component);
// hydrates automatically because mode is 'default' by default
});
test('ssr', async ({ mount }) => {
const component = await mount(Component, { mode: 'ssr' }); // include mode: 'stream' ?
// .. verify that SSR was right
await component.hydrate();
// .. verify the component after hydration works
});
['ssr', 'default'].forEach(mode => {
test(mode, async ({ mount }) => {
const component = await mount(Component, { mode });
// .. verify that SSR and default was right
});
});
related to: |
This is a great question - how much let the user the control of the manual hydration, versus the automatic process by Playwright? I think as a user, I would like to have Playwright mounting and hydrating everything for me, and specify the test code I want to be run before hydration, and also the test code I want after hydration, the way you did it for Svelte(disclaimer: I know only Svelte). However, I wish that there could be a way to "skip" SSR automatically, so the same code will test both cases. In Svelte. I think that the easiest code will be to have "dual rendering" (this is a generalization of your code): dual_test('CSR&SSR', async ({ render }) => {
const { mount, ssr } = await render(Component);
if (ssr) {
// .. verify that the SSR was right
}
const component = await mount();
// .. verify the component after hydration works
}); This way, the user write the test code once, and Playwright (could) test the component twice:
In any case, I believe a similar fashion can be done to other frameworks. |
Would like to explore the ideas a bit further if you can share a simple repository with SSR use case(s) you want to test? |
Let's split our discussion to "simple" and "advanced" components. Simple ComponentsSimple components here are one that their initial display does not need browser JS API (it may need it for the next "frames"). You can think about a simple Advanced ComponentsThese are components that use the browser JS API for the setup phase, and do some HTML/CSS tricks to make the component looks great (or at least, reasonable) in the SSR rendering phase, before the browser JS API is available. |
It would be nice not only for rendering components but for Api SSR mocking as well for Nuxt.js / Next.js / etc... |
@khryshyn yeah agree. No one seems to have a working/released solution for mocking API calls in server components yet tho. @kettanaito / MSW is working on something which looks really promising: https://www.youtube.com/watch?v=H4lGysz_dOQ |
Yeah, once we release |
Playwrite supports currently component testing for many UI frameworks (in experimental mode), but only by mounting the component, and with no SSR rendering testing support.
I would like to add to the component testing environment some form of SSR mode in testing. For many simple component it might not really be needed, but for more advanced UI handaling it will be useful to verify that both SSR and hydration work great.
A note for designers: Some UI framework simulate a full browser context on SSR(i.e.
window
anddocument
objects are available to use on SSR mode, e.g. React as far as I know), while some others simulate no browser context on SSR(e.g. Svelte).Specifically, I think this 3 situations are needed to be tested, and have some flag indicaring the user what is currently being tested:
Not sure how to fuse this ideas with the currently
mount
call, I'm open to suggestions.The text was updated successfully, but these errors were encountered: