Skip to content

chore: improve hydration tests #10887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 23, 2024
Merged

chore: improve hydration tests #10887

merged 9 commits into from
Mar 23, 2024

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Mar 23, 2024

Right now, we test hydration by inserting the contents of a _before.html file, hydrating, and checking that we have the expected output. These _before.html files are created manually.

This is both extremely laborious — this PR is the outcome of frustrations I had while trying to debug something hydration-related — and quite bug-prone. As a case in point, there is currently a failing test on this branch, and I'm pretty sure it's a legitimate failure (i.e. a real bug was being masked by an incorrect _before.html). now fixed

This PR simplifies things:

  • we add a server_props object to the test interface, and use that for SSR if it exists
  • we SSR the component and hydrate the result of that, instead of the _before.html file
  • for debuggability, the rendered HTML (and <head> contents) are written to the _output directory, alongside the compiler output
  • if we expect a mismatch between the pre- and post-hydration HTML, we add an _expected.html (formerly _after.html) and compare against that, otherwise we compare against the initial SSR'd HTML

As well as being much simpler and more maintainable, this will aid us if we implement something like #10609 (which we should).

TODO:

  • diagnose test failure

Copy link

changeset-bot bot commented Mar 23, 2024

🦋 Changeset detected

Latest commit: 9d7b1c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member Author

going to self-merge this to unblock some other work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant