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

fix: reduce console.error suppressions to only while acting #542

Closed
wants to merge 4 commits into from

Conversation

mpeyper
Copy link
Member

@mpeyper mpeyper commented Jan 15, 2021

What:

Another option vs #541

Why:

Making it just work for more users without having to set options.

How:

By only suppressing the error boundary output while acting, the test code retains access to the unaltered (or altered in their own way) version of console.error.

Technically, the test code will have access to our suppressed version of console.error within an act callback, however they would have to be using it for something other than logging an error (e.g. asserting a mocked version was called) within that callback to have an issue. Calling it to log an error with it would work as expected.

There is an option to return the unaltered act to them and only use the wrapped version internally around render calls, which would alleviate the above issue, however that might leave them susceptible to showing the output if their act update caused and error in the subsequent render passes.

The tradeoff with this implementation is that we cannot pass an option to disable it like in #541 as the act function needs to be wrapped in the global scope before the the renderer receives the options. We could potentially use an environment variable to disable is globally like we do for other things if we really want an escape hatch on it.

Checklist:

  • Tests
  • Ready to be merged

The code here is pretty crude, especially in the act wrapper. I'll clean it up if we want to go this way.

@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #542 (6146599) into master (b87c30c) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #542   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        16    +2     
  Lines          210       234   +24     
  Branches        23        26    +3     
=========================================
+ Hits           210       234   +24     
Impacted Files Coverage Δ
src/helpers/createTestHarness.tsx 100.00% <ø> (ø)
src/dom/index.ts 100.00% <100.00%> (ø)
src/dom/pure.ts 100.00% <100.00%> (ø)
src/helpers/act.ts 100.00% <100.00%> (ø)
src/helpers/console.ts 100.00% <100.00%> (ø)
src/helpers/promises.ts 100.00% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/native/index.ts 100.00% <100.00%> (ø)
src/native/pure.ts 100.00% <100.00%> (ø)
src/server/index.ts 100.00% <100.00%> (ø)
... and 3 more

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 b87c30c...6146599. Read the comment docs.

src/helpers/act.ts Outdated Show resolved Hide resolved
@joshuaellis
Copy link
Member

I'm struggling to understand though why we'd want to impliment this "just working" feat as opposed to getting users to add one param? This seems like overall it's more effort to maintain?

@mpeyper
Copy link
Member Author

mpeyper commented Jan 15, 2021

I agree that it's more to maintain and we should be wary of that.

The main reason to consider over #541 is that by limiting the side effect (replacing console.error), it should work out-of-the-box for most, if not all, users.

In #541, setting the option to false gives them back the original console.error but they then also have to handle the react output, whether that be suppressing it themselves or additional calls they need to consider in their expectations. In this change they can use console.error like before and the react output is filtered out if and doesn't pollute their expectations.

I'm starting to think an environment variable escape hatch is worth it if we go this way. I'm still very much on the fence about it though as that act wrapper scares me a bit.

@joshuaellis
Copy link
Member

Maybe let's release a beta, get the folks on discord to try it out & see how they feel – RFC. We could also add @latest to the install doc to coerce some into using the beta? But an escape hatch would also be good too I think.

RE: Act wrapper, my concern is they change it one impl in either react-dom or react-test-renderer and then we have to create more than one wrapper... But we can always see how it goes. It seems this is a good starting point to trial?

Copy link
Member

@joshuaellis joshuaellis left a comment

Choose a reason for hiding this comment

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

Comments above

Added RHTL_DISABLE_ERROR_FILTERING environment variable toggle to globally disable console filtering.

Fixes #546
@joshuaellis
Copy link
Member

That’s funny, I was about to pick this up, so do you think this should be the route to go with? Whilst incl. an ENV escape hatch?

@mpeyper
Copy link
Member Author

mpeyper commented Jan 18, 2021

Even though the code here is a bit more hectic than #541, I feel like this would be the easiest to unwind later of we want to because it doesn't introduce a new option (other than the env variable)

@mpeyper
Copy link
Member Author

mpeyper commented Jan 18, 2021

Feels like everyone else is saying go for #541 though 😕

@joshuaellis
Copy link
Member

Wouldn’t the variable work the same as the option? Therefore this PR is 541 but a smarter(?)

@mpeyper
Copy link
Member Author

mpeyper commented Jan 18, 2021

Wouldn’t the variable work the same as the option

Similar but not quite the same. The env variable is much more global than the option which is constrained to a single test. In practice though you'd probably get every test in a file passing the option and it might as well be global at that point.

@mpeyper
Copy link
Member Author

mpeyper commented Jan 22, 2021

Closing in favour of #549

@mpeyper mpeyper closed this Jan 22, 2021
@mpeyper mpeyper deleted the fix/reduce-error-suppression branch March 1, 2021 22:03
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

2 participants