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

Pretty format for DOMStringMap and NamedNodeMap #5246

Merged
merged 1 commit into from
Jan 8, 2018
Merged

Pretty format for DOMStringMap and NamedNodeMap #5246

merged 1 commit into from
Jan 8, 2018

Conversation

zouxuoz
Copy link
Contributor

@zouxuoz zouxuoz commented Jan 8, 2018

Summary

Resolve #5233

Test plan

I'm added tests for that and all tests is passed.

@codecov-io
Copy link

codecov-io commented Jan 8, 2018

Codecov Report

Merging #5246 into master will increase coverage by 0.07%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5246      +/-   ##
==========================================
+ Coverage   61.18%   61.25%   +0.07%     
==========================================
  Files         202      203       +1     
  Lines        6771     6786      +15     
  Branches        3        4       +1     
==========================================
+ Hits         4143     4157      +14     
- Misses       2627     2628       +1     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-snapshot/src/plugins.js 80% <ø> (ø) ⬆️
packages/jest-matcher-utils/src/index.js 100% <ø> (ø) ⬆️
packages/jest-diff/src/index.js 84.09% <ø> (ø) ⬆️
packages/pretty-format/src/index.js 96.45% <ø> (ø) ⬆️
...ckages/pretty-format/src/plugins/dom_collection.js 93.33% <93.33%> (ø)

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 b86d932...e537129. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Jan 8, 2018

/cc @pedrottimark

return result;
};

export const serialize = (
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

or at least rename this file to dom_collection

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Thanks!

DOMElement,
Immutable,
ReactElement,
ReactTestComponent,
} = prettyFormat.plugins;

let PLUGINS = [
DOMCollection,
Copy link
Contributor

Choose a reason for hiding this comment

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

Although the destructuring assignment above is in alphabetic order, in the array let’s move DOMCollection to follow DOMElement so that the order of testing plugins is descending in expected frequency.

@pedrottimark
Copy link
Contributor

@zouxuoz Thank you for this pull request. For consistent serialization within Jest, can you please add the DOMCollection plugin to the following files:

  • packages/jest-diff/src/index.js
  • packages/jest-matcher-utils/src/index.js

refs: Refs,
printer: Printer,
): string =>
collection.constructor.name +
Copy link
Contributor

@pedrottimark pedrottimark Jan 8, 2018

Choose a reason for hiding this comment

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

A possible improvement which you can decide whether to make, or not, is implement the depth limit:

Oops, EDIT corrected property key: maxDepth

++depth > config.maxDepth
  ? '[' + collection.constructor.name + ']'
  : /* existing expression */

For example:

Copy link
Contributor Author

@zouxuoz zouxuoz Jan 8, 2018

Choose a reason for hiding this comment

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

I think depth limit is not needed for DOM collections, because usually it's flat, but I can do it if needed.

Update: I'm added it 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, let’s keep it short and simple.

You are so quick with this super PR that I have not had time to test hypothesis that the problem is extra props in jsdom implementation and that pretty-format could serialize real DOM collections in browser. If we find problems with any other data structures, we might consider whether there is a correct and efficient test to detect jsdom objects more generically.

@cpojer cpojer merged commit 38aec14 into jestjs:master Jan 8, 2018
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snapshot serializer doesn't work with DOMStringMap and NamedNodeMap
6 participants