Skip to content

Conversation

@devongovett
Copy link
Member

@devongovett devongovett commented Jul 24, 2020

Related to #760, #699

This sets up a test harness for server side rendering support. The main objective is to ensure that every component supports being rendered in an environment without access to DOM globals (e.g. window/document), and that the HTML that is rendered can be hydrated without any React warnings/errors on the client side (e.g. non-matching props between server and client).

This is accomplished by setting up a separate Jest test suite that runs in a node environment instead of a jsdom environment. A utility function called testSSR will then render each component in this environment to ensure no errors on the server side. Then, the HTML output of this is sent to a separate worker thread which is running in a JSDOM environment. The worker attempts to use the React code that originally was used to create the element along with the HTML that was sent from the "server" to hydrate. Console errors/warnings are captured, and any that are emitted throw an error and fail the test.

I've included a few example tests here, but not all of the components. Also some of the tests I've added fail currently due to errors thrown. The plan is to add tests for all components, and then fix them one by one. Once that is done, we'll add this additional test suite to CI to ensure no regressions.

You can run the new tests with the yarn test:ssr command.

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

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.

3 participants