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: Support HTMLCollection and NodeList in DOMCollection plugin #7125

Merged
merged 4 commits into from Oct 11, 2018

Conversation

Projects
None yet
4 participants
@pedrottimark
Copy link
Collaborator

pedrottimark commented Oct 8, 2018

Summary

Fixes #7121

Problem: When pretty-format serializes a jsdom object instance for which no plugin matches, it takes a “stupid amount of time” on the property with key Symbol(impl) and then fails.

Solution: Support HTML collection classes to write assertions for received values:

  • element properties childNodes, children, elements, options
  • getElementsByTagName and so on
  • querySelectorAll

Also added support for config.min option to omit class name.

Be aware that class names can be moving targets even in browsers:

  • form.elements returned HTMLFormControlsCollection
  • fieldset.elements returned HTMLCollection

despite the claim at Mozilla Developer Network

The HTMLFormControlsCollection interface represents a collection of HTML form control elements. It represents the lists returned by the HTMLFormElement interface's elements property and the HTMLFieldSetElement interface's elements property.

So there is some risk for test writers that snapshots might need to be updated at major version upgrades of jsdom package.

Test plan

  • added 8 tests for collection classes
  • added 1 test for config.min option
  • added 1 test for config.maxDepth option

@pedrottimark pedrottimark requested a review from SimenB Oct 8, 2018

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Oct 8, 2018

Codecov Report

Merging #7125 into master will not change coverage.
The diff coverage is 88.88%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #7125   +/-   ##
======================================
  Coverage    66.6%   66.6%           
======================================
  Files         253     253           
  Lines       10629   10629           
  Branches        3       4    +1     
======================================
  Hits         7079    7079           
  Misses       3549    3549           
  Partials        1       1
Impacted Files Coverage Δ
...ckages/pretty-format/src/plugins/dom_collection.js 93.33% <88.88%> (ø) ⬆️

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 c4646b9...69dc91f. Read the comment docs.


// Omitted a test for form.elements because constructor.name
// is HTMLCollection in jsdom version 11
// might become HTMLFormControlsCollectio in jsdom 12

This comment has been minimized.

@SimenB

SimenB Oct 9, 2018

Collaborator

jsdom 12 is released, and while we won't upgrade for some time, maybe we can normalize the name to HTMLFormControlsCollection?

This comment has been minimized.

@pedrottimark

pedrottimark Oct 9, 2018

Author Collaborator

Verified outside Jest that form.elements still HTMLCollection class in jsdom@12.2.0 so added the test. Wrote a comment so that we will know to update the criterion if it ever changes.

'}'
: '[' +
printListItems(
Array.prototype.slice.call(collection),

This comment has been minimized.

@SimenB

SimenB Oct 9, 2018

Collaborator

Array.from?

This comment has been minimized.

@pedrottimark

pedrottimark Oct 9, 2018

Author Collaborator

Yes, I will leave the compiling to Babel :)

@pedrottimark

This comment has been minimized.

Copy link
Collaborator Author

pedrottimark commented Oct 9, 2018

Documenting decision to serialize in list item format:

  • con: comma after item of markup looks awkward
  • pro: minimize change to snapshot if class names change in future jsdom versions
  • pro: minimize change to snapshot if received value changes to or from Array.from idiom
@SimenB

SimenB approved these changes Oct 11, 2018

@SimenB SimenB merged commit 5fcaa24 into facebook:master Oct 11, 2018

0 of 10 checks passed

ci/circleci: lint-and-typecheck CircleCI is running your tests
Details
ci/circleci: test-browser CircleCI is running your tests
Details
ci/circleci: test-jest-circus CircleCI is running your tests
Details
ci/circleci: test-node-10 CircleCI is running your tests
Details
ci/circleci: test-node-6 CircleCI is running your tests
Details
ci/circleci: test-node-8 CircleCI is running your tests
Details
ci/circleci: test-or-deploy-website CircleCI is running your tests
Details
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
deploy/netlify Deploy preview processing.
Details

@pedrottimark pedrottimark deleted the pedrottimark:dom-collection branch Oct 12, 2018

@SimenB SimenB referenced this pull request Jan 26, 2019

Merged

fix: upgrade pretty-format to v24 #195

1 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment