Skip to content
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

Add ability to run SSR tests in pure-node environment #607

Merged
merged 2 commits into from Apr 22, 2021
Merged

Add ability to run SSR tests in pure-node environment #607

merged 2 commits into from Apr 22, 2021

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented Apr 22, 2021

What:
Fix: #605

Why:
Before that change it was impossible to run SSR test in pure-nod eenvironment, where no DOM global objects exists.

How:
Div element now created only in hydration stage (also now it is a marker of hydration occurred)

Checklist:

  • Documentation updated
  • Tests
  • Ready to be merged
  • Added myself to contributors table

It allows to run tests in real node environment, where no DOM global
objects exists.

Fix: #605
@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #607 (2abba47) into master (0543a9e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #607   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines          219       218    -1     
  Branches        28        28           
=========================================
- Hits           219       218    -1     
Impacted Files Coverage Δ
src/server/pure.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0543a9e...2abba47. Read the comment docs.

Copy link
Member

@mpeyper mpeyper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Have you checked if it resolves the issue in your test?

It would be nice if we could have sone server only tests run in the node environment without jsdom to make sure we don't break it in the future, but I'm not sure how we would do that for just some tests? I won't hold this up for it if it too hard though.

@xobotyi xobotyi changed the title Add possibility to run SSR tests in pure-node environment Add ability to run SSR tests in pure-node environment Apr 22, 2021
@xobotyi
Copy link
Contributor Author

xobotyi commented Apr 22, 2021

@mpeyper yes, i've monkeypatched local version - it solves the issue.

About server tests - it is easy with recent jest projects feature (the best they've introduced yet IMO), but here used another test runner so i dont know how to do it here.
As you can see below all my hooks are tested bont against node and jsdom environments on the single run:
image

@mpeyper
Copy link
Member

mpeyper commented Apr 22, 2021

Oh damn, that looks sweet. I'll definitely be investigating that to clean up our bloated test suite.

Thanks for the fix, I'll merge this now. New version should be out soon for you (bot will comment here).

@mpeyper mpeyper merged commit 7b3867e into testing-library:master Apr 22, 2021
@github-actions
Copy link

🎉 This PR is included in version 5.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@xobotyi xobotyi deleted the fix-ssr-node-env branch April 22, 2021 10:03
jsjoeio pushed a commit to jsjoeio/react-hooks-testing-library that referenced this pull request Feb 27, 2022
This adds a new test to verify that renderHook can be called in an
SSR-like environment based on the changes implemented in testing-library#607.
mpeyper pushed a commit that referenced this pull request Jun 18, 2022
…er versions of react

* refactor(server/pure): remove unnecessary type annotation

* feat: add ssr.test.ts

This adds a new test to verify that renderHook can be called in an
SSR-like environment based on the changes implemented in #607.

* chore: update contributors table

* refactor: remove act call in render in sever/pure

@mpeyper explained how this `act` call in server rendering is not really
necessary so we can remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage in close-to-real SSR environment?
2 participants