-
Notifications
You must be signed in to change notification settings - Fork 469
Pr/440 show line in debug #733
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
Pr/440 show line in debug #733
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6c6df90:
|
Codecov Report
@@ Coverage Diff @@
## master #733 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 25 +1
Lines 675 702 +27
Branches 181 183 +2
=========================================
+ Hits 675 702 +27
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly ok to me (what are the chances we could create an actual codeframe? https://babeljs.io/docs/en/next/babel-code-frame.html)
2f5ee1d
to
74ca2c2
Compare
After doing some research based on the feedback, I believe we have 2 options to implement this feature 🧑🏭 If we only want to display the frame like
|
I like option 2. I don't think we'd need anything special in config. We could do something like this: https://github.com/testing-library/react-testing-library/blob/master/src/flush-microtasks.js#L28 |
74ca2c2
to
18fb7dd
Compare
src/get-user-code-frame.js
Outdated
const nodeRequire = module && module.require | ||
readFileSync = nodeRequire.call(module, 'fs').readFileSync | ||
codeFrameColumns = nodeRequire.call(module, '@babel/code-frame') | ||
.codeFrameColumns | ||
} catch { | ||
// We're in a browser environment | ||
/* istanbul ignore next */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that these lines run while the module is loaded, I don't know of a practical way to mock them for a single test to force them to throw. That's why I'm ignoring coverage for now. If you know of a way to do this, I'd appreciate the guidance 🙏
e36f525
to
439a4d7
Compare
This is fantastic! I'll give the code a deeper look later, but one thing: could we put the codeframe at the bottom? |
Oh and the line above the codeframe appears to be listing the wrong file, it should show the one that is shown in the codeframe right? |
So actually that line comes from jest, it's where console.log is actually called. I have looked into it but I haven't found a way to prevent it :( |
Super! Let's add another line between the debug output and the line listing where the file is, and let's also make that line muted like the console.log line. Thanks! |
08a4c55
to
32aa265
Compare
This is now fixed and looks like this 👀 I still need to take a look at the CI error, it shouldn't be failing since locally it doesn't with the same script 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thank you. Just a few things.
src/__tests__/get-user-code-frame.js
Outdated
|
||
test('it returns only client code frame when code frames from node_modules are first', () => { | ||
const stack = `Error: Kaboom | ||
at Object.<anonymous> (/home/john/projects/projects/sample-error/node_modules/@es2050/console/build/index.js:4:10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says john/projects/projects
, but the snapshot just says john/projects/
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this particular test, that frame should actually be ignored since it's inside node_modules. The one we care about is one line after ${userStackFrame}
.
However, the frame that is ignored does have a typo (/projects/projects
). I've corrected this and simplified the paths used for all tests to avoid confusion. They all now start with /sample-error
instead of /home/john/<etc>
5b91123
to
742dbbd
Compare
…ame into variable
be70a1f
to
e04c63d
Compare
e04c63d
to
19901e1
Compare
e04c63d
to
d641ec1
Compare
d641ec1
to
6c6df90
Compare
Hey @kentcdodds, please let me know if the latest changes look ok. All comments have been addressed but the travis error still puzzles me. It fails in a seemingly unrelated file (role.js) but passes locally. I also tried temporarily rolling back my changes, creating a very simple commit but the error still happened. I was wondering if this had happened before |
Yeah, that's odd. I'm not sure what's up with. Anyone else want to investigate? |
Tried it locally myself and everything worked fine. So I'm going to just hope this is an issue with CI for this PR and we'll go ahead and merge it. I'll deal with it if it persists beyond this PR CI issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is solid. Thanks!
Looks like there was a weird issue in CI. Cleared cache and ran again and everything's fine now. |
🎉 This PR is included in version 7.24.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
@all-contributors please add @victorandcode for code and tests |
I've put up a pull request to add @victorandcode! 🎉 |
Thanks for taking a look :) |
What:
Add the call frame to the output of
screen.debug
before the prettified DOMWhy:
For easier debugging.
Resolves #440
How:
Before

After

Here's the code for the test

Checklist:
docs site