testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.27k stars 467 forks source link

feat: Reduce caught exceptions in `prettyDom` #1321

Closed DavidRieman closed 5 months ago

DavidRieman commented 5 months ago

What: Added tests for pretty-dom to guard against potential behavioral regressions. Then optimized shouldHighlight in pretty-dom to avoid unexceptional exceptions.

Why: When developers are using the debugging features to halt the debugger upon "caught exceptions" or "first-chance exceptions" as it may be called in some IDEs, unrelated test failures were disruptively stealing the developer's attention and contributing to premature test timeouts. These disruptions are generally unnecessary since the situation leading up to it can be easily avoided with refactoring.

The exception at hand is that JSON.parse throws when passed undefined and/or empty string values. It can be easily avoided because we know that it will throw, and we know the intent is to default the colorization selection.

How: Streamlined the logic in shouldHighlight to preserve the final result while including extra safety checks to avoid passing undefined/empty to JSON.parse.

Checklist:

codesandbox-ci[bot] commented 5 months ago

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

Sandbox Source
react-testing-library-examples Configuration
eps1lon commented 5 months ago

Basically we reduce the number of caught exceptions?

DavidRieman commented 5 months ago

Indeed, unexceptional exceptions are a thorny problem in the JS ecosystem due to continued lack of sufficient IDE support for the kind of "just my code" debugger halting features that have existed for decades in other ecosystems. (This one in particular stings me at least once a year so I finally resolved to fix it at the source.) What are our next steps?

eps1lon commented 4 months ago

Needs to be reverted in https://github.com/testing-library/dom-testing-library/pull/1325 since it caused https://github.com/testing-library/dom-testing-library/issues/1322. Relanding in https://github.com/testing-library/dom-testing-library/issues/1323