-
Notifications
You must be signed in to change notification settings - Fork 472
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
Improved logging #45
Improved logging #45
Conversation
- added test to check whether Cypress doesn't log DOM - ignore .idea folder (JetBrains IDE's) - added myself to contributors
Hey. Nice PR! Waiting on this currently. @kentcdodds yo, how soon can you merge this? Thanks, |
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 great! Just one thing.
src/queries.js
Outdated
if (inBrowser && !inNode) { | ||
return `\n\n${prettyDOM(htmlElement, limit, { highlight: false })}` | ||
} | ||
return `\n\n${prettyDOM(htmlElement, limit)}` |
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.
Rather than adding the \n\n
here, let's do this in the usage:
throw new Error(['Unable to find... etc...', debugDOM(container)].filter(Boolean).join('\n\n'))
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.
In Cypress, that would result in having two empty lines at the end of the error message. debugDOM
seems to be a private function for query errors, so I thought this implementation would be preferable.
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.
Updated my comment to avoid that issue
Looks like were missing some coverage. If it's really difficult to simulate a non-browser environment at the moment, then you can use |
I'm wondering, in what kind of situation would I'll look into the coverage issue, don't know why line 59 isn't being covered by the tests. EDIT: jsdom/jsdom#2175 is fixed 😄 |
@kentcdodds I've pushed an update. The question remains whether we want to keep the browser specific code or whether if (inBrowser && !inNode) {
return prettyDOM(htmlElement, limit, { highlight: false })
} Let me know what you think! |
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.
Some thoughts and ideas.
src/queries.js
Outdated
return '' | ||
} | ||
/* istanbul ignore if */ | ||
if (inBrowser && !inNode) { |
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.
Yeah, we could probably change this to:
if (inCypress) {
return ''
} else if (inNode) {
return prettyDOM(htmlElement, limit)
} else {
return prettyDOM(htmlElement, limit, {highlight: false})
}
src/queries.js
Outdated
container, | ||
)}`, | ||
) | ||
throw new Error([ |
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.
I'm starting to think this may be a good case for something like:
throw getElementError(message, container)
where getElementError
is just:
const getElementError => new Error([message, debugDOM(container)].filter(Boolean).join('\n\n'))
What do you think?
Agreed. Changes pushed. |
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.
Super duper! Thank you so much for iterating on this so well!
Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the |
🎉 This PR is included in version 2.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
What:
Why:
document
,pretty-format
module crashes. (prettyDOM error when container is document #44)window.document
toprettyDOM
, it crashes becausedocument.outerHTML.length
results inCannot read property length of undefined
error. (prettyDOM error when container is document #44)How:
document.documentElement
inprettyDOM
to have the actual element with anouterHTML
property.debugDOM
function to determine the environment and how/whether to log the DOM element.Checklist: