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

screen.debug() logs undefined in Output Inspector #3051

Closed
fvanwijk opened this issue Aug 15, 2022 · 10 comments
Closed

screen.debug() logs undefined in Output Inspector #3051

fvanwijk opened this issue Aug 15, 2022 · 10 comments

Comments

@fvanwijk
Copy link

fvanwijk commented Aug 15, 2022

Not sure if this is a bug report or a feature request. I remember it worked as expected long time ago, but I can't remember exactly.
(update: could be related to #165)

I'm trying to show the result of Testing Library's screen.debug() in the Output inspector.

screen.debug() returns undefined, so it makes sense that undefined is logged. However console.log is called internally so I still expect this to be in the Output explorer.

If I call console.log(prettyDOM()), it works as expected.

Maybe this happens because console.log calls are filtered by the files/tests lists? Is there a way to show console.logs for any file, just like when you run the tests from the terminal?

image

A second minor issue is that output is hard to read because of the logged color stops. Is it possible to apply those in the output?
image

Expected:
image

@smcenlly
Copy link
Member

I remember it worked as expected long time ago, but I can't remember exactly.

Wallaby does some patching of testing-library at runtime to remove color highlighting, and to allow you to use Show Value and live comments after screen.debug();.

For some reason it looks like this isn't working for your project. It could be related to your testing framework, project dependencies, or perhaps something else.

Can you please provide your Wallaby Diagnostics report? It contains the information that we need to investigate further.

@smcenlly
Copy link
Member

Bumping this issue in case you missed our reply.

@aweiss-dev
Copy link

I have the same problem while logging screen.debug().

My Diagnostics report can be found here:
https://jsfiddle.net/drmshx9w/

@smcenlly
Copy link
Member

Thanks for your diagnostics report. We have found/fixed the issue. Please update to Wallaby core v1.0.1335, it should work for you.

@fvanwijk
Copy link
Author

@smcenlly I actually did not receive any GH notifications except for when you closed the issue :)

I have force updated the core to 1.0.1335 and I still get undefined as output when logging testing library using prettyDOM() or screen.debug().
image

This is the diag report for a test repo that I created for a different issue.
https://jsfiddle.net/8tych3ur/

@smcenlly smcenlly reopened this Oct 18, 2022
@smcenlly
Copy link
Member

Your sample repo appears to be working for us when using the same version of VS Code, MacOS, node, and Wallaby.

image

We're wondering if there's some cached transform in vite / vitest for the previous version of Wallaby.

Could you please try cloning to a fresh directory to see if it works for you?

If it does work for you, please try using the Wallaby.js: Reset Wallaby Cache on your existing directory.

If you're still having problems, can you please let us know how you are installing your dependencies? We used npm install.

@smcenlly
Copy link
Member

smcenlly commented Nov 6, 2022

Closing this issue as we haven't heard back. If you're still having issues, please let us know and we will re-open the issue.

@smcenlly smcenlly closed this as completed Nov 6, 2022
@fvanwijk
Copy link
Author

There is definitely somethong wrong with GH email notifications because I didn't get any email from this thread again, despite the settings:
image


Anyway, the point is not that //? doesn't work with screen.debug() from Testing Library. When I try to log line 15 in Wallaby, I get the same output.

The issue is that I cannot log screen.debug() in the output inspector because it is calling console.log instead of returning it.

Here is another use case to illustrate what I mean:
image
I'd like to logHello(); //? output hello and not undefined

@fvanwijk
Copy link
Author

In hindsight I see that a duplicate was opened 2 weeks later:
#2510

I have core version v1.0.1379, so I would expect to see the component being logged
image

@smcenlly
Copy link
Member

Anyway, the point is not that //? doesn't work with screen.debug() from Testing Library. When I try to log line 15 in Wallaby, I get the same output.

We have applied a fix for this that should address your issue, available in Wallaby core, v1.0.1380+. We apply a number of patches to testing-library so that screen.debug() will output inline, but this was not working when using vitest.

The issue is that I cannot log screen.debug() in the output inspector because it is calling console.log instead of returning it.

This is intentional. Do not expect Wallaby to output console.log inline for functions that return undefined; it may be intentional to log a function return value and we can't automatically patch all functions in this case. Our patch for screen.debug() does not have side-effects so it's safe for us to change the behavior.

In hindsight I see that a duplicate was opened 2 weeks later:
#2510

This issue was from 2020, almost 2 years before your issue was raised and was when we originally added support for screen.debug() to display inline.

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

No branches or pull requests

3 participants