Skip to content

feat: add instance and renderer back to RenderResults #33

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

Closed
wants to merge 1 commit into from
Closed

feat: add instance and renderer back to RenderResults #33

wants to merge 1 commit into from

Conversation

wKovacs64
Copy link

Closes #32.

Summary

The instance and renderer fields are documented in the README but were removed from RenderResult in e6ac5ad. I think they add value and (at least renderer) should still be included. This PR re-introduces them to the object returned from render.

Alternatives:
  • only include renderer (as instance is just renderer.root anyway)
  • leave them out of RenderResult and remove them from the README

Test plan

N/A

@thymikee
Copy link
Member

Od rather remove it from the Readme, as that was the intention, just forgot to update it. What's your use case for exposing the renderer?

@wKovacs64
Copy link
Author

Debugging, primarily. react-testing-library's debug function is what I wanted but react-native-testing-library's debug is shallow so it was not helpful in my case. renderer.toJSON was my best bet at the time.

@thymikee
Copy link
Member

thymikee commented Oct 16, 2018

We could add this as an API, how about something like:

degug(<Component />, {deep: true})

?

or returning toJSON from render, if you ever want to snapshot whole component, which actually may make sense for some smaller ones.

I'm also good with adding both.

@wKovacs64
Copy link
Author

debug(<Component />, { deep: true }) would be great! I could also see returning toJSON to be useful if you want to keep renderer hidden.

@thymikee
Copy link
Member

Yea, we explicitly don't want users to access .getInstance() method. Would you be so kind and update this PR with what we've come up here? 🙂

thymikee pushed a commit that referenced this pull request Oct 16, 2018
## The devDependency [@callstack/eslint-config](https://github.com/callstack/eslint-config-callstack) was updated from `2.0.0` to `3.0.0`.
This version is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

---

<details>
<summary>Release Notes for v3.0.0</summary>

<ul>
<li>breaking: update <code>eslint-config-prettier</code> to v3.0.1</li>
<li>breaking: update <code>babel-eslint</code> to v10.0.1</li>
<li>breaking: update <code>eslint-plugin-flowtype</code> to v3.0.0</li>
<li>breaking: require ESLint 5 as peer dependency (because of above mentioned deps bump)</li>
</ul>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 6 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/79c5f38a5a26b773fb2d8999bad44f7e06070831"><code>79c5f38</code></a> <code>v3.0.0</code></li>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/3201e419a2fb25a1cc68df724c239a78246591f4"><code>3201e41</code></a> <code>breaking: require ESLint 5 as peer dependency</code></li>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/ca82ca09ad4de6d8039e909a11559b92a84b0be9"><code>ca82ca0</code></a> <code>chore: update yarn.lock with latest deps</code></li>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/4528e06ecbd759c328a9825ccc8b6a141ed8ab74"><code>4528e06</code></a> <code>Greenkeeper/initial (#37)</code></li>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/4a73ea786f8bac2d28e0e004f4029d3a594a710f"><code>4a73ea7</code></a> <code>Mention issues with CRA (#33)</code></li>
<li><a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/commit/845b88002ed93415a9d229a07b02d4dced6ef265"><code>845b880</code></a> <code>v2.0.0</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/callstack/eslint-config-callstack/compare/0c260dafa7c2522ea46ac3f4cb5fc9cfb21b7f9e...79c5f38a5a26b773fb2d8999bad44f7e06070831">full diff</a></p>
</details>

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴
@thymikee thymikee closed this in #35 Oct 16, 2018
@wKovacs64
Copy link
Author

Thanks, sorry I wasn't able to get to the revamp - you beat me to it! 🙂

@wKovacs64 wKovacs64 deleted the render-results branch October 16, 2018 16:06
@thymikee
Copy link
Member

No worries, thanks for you contribution, much appreciated!

@wKovacs64
Copy link
Author

Are you still thinking of adding deep debug? I guess that's essentially just a prettified version of toJSON?

@thymikee
Copy link
Member

I think we can make it a thing, the API however would rather be debug(<Component />, '', {deep: true}) as we allow second parameter to be a string message.

On the other hand we could check the type of second parameter so you could either use:

debug(<Component />, 'message'); // shorthand, current API
debug(<Component />, {deep: true, message: 'message'}); // debug with more options

wdyt? cc @Esemesek

@Esemesek
Copy link
Collaborator

I don't like those configurations. Methods like debug should be short for convenience. We often use those to get a quick feedback, adding configuration as a second parameter will complicate things and will encourage us to add more configurable fields in the future. We could make it happen, but with slight API change:

debug(<Component />, 'message'); // defaults to shallow
debug.shallow(<Component />, 'message'); // same as above
debug.deep(<Component />, 'message'); // deep debug

Additionally, we won't break existing API.
wdyt?

@thymikee
Copy link
Member

um, like it!

@Esemesek
Copy link
Collaborator

Just like console.log, console.warn etc C:

@wKovacs64
Copy link
Author

That looks great.

@thymikee
Copy link
Member

we should also use highlight option from pretty-format for nice colors in debug 😉

@thymikee
Copy link
Member

@wKovacs64 would you like to build it?

@wKovacs64
Copy link
Author

I don't know jack about Flow, so it'd probably be somewhat of a train wreck. 😉

thymikee added a commit that referenced this pull request Oct 16, 2018
<!-- Please provide enough information so that others can review your pull request. -->
<!-- Keep pull requests small and focused on a single change. -->

### Summary

Adds API proposed by #33 (comment).
Also component output is now highlighted:

<img width="259" alt="screenshot 2018-10-16 at 19 33 25" src="https://user-images.githubusercontent.com/5106466/47035614-c10efb80-d17a-11e8-99ac-00f648880008.png">


### Test plan

Added tests for `debug`.
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.

None yet

3 participants