-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Support text and comment nodes in html pretty printing #3355
Conversation
); | ||
const pass = prettyFormatted === expected; | ||
getPrettyPrint: plugins => | ||
function(received, expected, opts) { |
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.
Had to make this function
instead of arrow, otherwise I get
● HTMLElement Plugin › supports siblings
TypeError: Cannot read property 'matcherHint' of undefined
at pass (packages/pretty-format/src/__tests__/expect-util.js:42:20)
at process._tickCallback (internal/process/next_tick.js:109:7)
Rest of the changes is prettier auto-formatting (https://github.com/facebook/jest/pull/3355/files?w=1)
Codecov Report
@@ Coverage Diff @@
## master #3355 +/- ##
==========================================
- Coverage 64.12% 64.09% -0.03%
==========================================
Files 177 177
Lines 6558 6561 +3
Branches 4 4
==========================================
Hits 4205 4205
- Misses 2352 2355 +3
Partials 1 1
Continue to review full report at Codecov.
|
7723299
to
baff25e
Compare
print: Print, | ||
indent: Indent, | ||
opts: Options, | ||
colors: Colors, | ||
) => { | ||
): string => { | ||
if (element instanceof Text) { |
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.
Not sure if you want theseinstanceof
checks, but it was the only way I could get flow
to accept my input. Will it work outside of JSDOM? Do we care?
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.
It won't work outside of having the jsdom globals added as globals in node. Assuming that's nok OK, any idea on how to make flow accept that element.nodeType === 3
is the "same" as element instanceof Text
?
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.
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.
Yes, it works in the browser (and "wannabe-browsers", like jsdom), but not in Node. The issue is if you want to use the plugin from node without polluting global namespace
86e06bc
to
af36162
Compare
@@ -790,6 +790,7 @@ const DEFAULTS: Options = { | |||
printFunctionName: true, | |||
spacing: '\n', | |||
theme: { | |||
comment: 'gray', |
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.
No idea if this is considered a breaking change, but the next version is a major anyways
This is great Simen! I fixed it up a bit and addressed the instanceof checks and made custom types for them. |
* Make sure pretty-format expect util has correct context * Support comment nodes in html pretty printing * Support text nodes in html pretty printing * Add comment key to pretty-format theme * Add type to element in html pretty printer * Remove unused arg from html pretty printer * Cleanup
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
(I've edited this since opening (and deleted my comments on the way), as I was able to fix it myself)
Support printing text and comment nodes with the HTML pretty printer.
Test plan
yarn jest
/cc @mute