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

Restore prettyDOM logging for Cypress #1018

Merged

Conversation

istateside
Copy link
Contributor

@istateside istateside commented Aug 26, 2021

What:
This PR brings back the prettyDOM logging when the library is used within a cypress test (including from within cypress-testing-library)

Why:
testing-library/cypress-testing-library#172

Back in 2018, a decision was made to remove prettyDOM logging when used within a Cypress test. This was done because Cypress's default subject is the full document, and pretty-printing the outerHTML of the entire document would occasionally cause memory errors.

This change was made here- https://github.com/testing-library/dom-testing-library/pull/336/files#diff-2a50dc385b740f1ed6423e95977cc8dcccced5b7d8088e1dd7a02d062872cf1eR18-R19

Discussion around the decision is here - #44 (comment)

Since then, a number of changes have been made to the prettyDOM function that removes (lessens?) this risk. Most importantly, there is now a default max length on these error messages of 7000 characters.

Users also have the ability to opt into defining their own messages printed from the library by passing a getElementError(message, container) function when performing the initial configuration for the cypress-testing-library.

How:
Via extensive use of DEL key
I've removed the Cypress-specific checks that were implemented in prettyDOM, and removed the test checking for this behavior.

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • TypeScript definitions updated N/A
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 26, 2021

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 e716357:

Sandbox Source
react-testing-library-examples Configuration

@eps1lon
Copy link
Member

eps1lon commented Aug 27, 2021

I don't have any context why this code is required but I'm all for removing code that's only relevant to another testing library.

@testing-library/cypress Is this change ok for you?

@istateside Seems like we have some uncovered lines now. Either we need new tests for these or we should remove them.

@istateside
Copy link
Contributor Author

I'll try to work on getting the coverage increased today 👍

@kentcdodds
Copy link
Member

Looks good to me 👍

@istateside istateside force-pushed the kf/restore-pretty-dom-for-cypress branch from 90f331f to e716357 Compare September 7, 2021 14:50
container,
)}`
: null,
`Ignored nodes: comments, <script />, <style />\n${prettifiedDOM}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the handling of prettifiedDOM.length === 0 from the default getElementError function. From what I could tell, the only case where that was true was when the function was called from within Cypress. Since we've removed the Cypress special-casing in this PR, this branch no longer seemed useful.

@codecov
Copy link

codecov bot commented Sep 7, 2021

Codecov Report

Merging #1018 (e716357) into main (bb79e30) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1018   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          927       916   -11     
  Branches       294       286    -8     
=========================================
- Hits           927       916   -11     
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-16 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/config.ts 100.00% <ø> (ø)
src/pretty-dom.js 100.00% <100.00%> (ø)

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 bb79e30...e716357. Read the comment docs.

@kentcdodds kentcdodds merged commit 460115a into testing-library:main Sep 7, 2021
@kentcdodds
Copy link
Member

@all-contributors please add @istateside for code and tests

1 similar comment
@kentcdodds
Copy link
Member

@all-contributors please add @istateside for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @istateside! 🎉

@kentcdodds
Copy link
Member

Maintainers: I apologize for the admin-merge here. For some reason I thought this was the cypress repo and I know that not as many people are working in that one so I thought it would be appropriate. I'll try to remember to just approve the PR in the future. I hope this didn't cause any issues.

@github-actions
Copy link

github-actions bot commented Sep 7, 2021

🎉 This PR is included in version 8.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants