fix: handle empty quads from getContentQuads for proximity selectors #2771
Conversation
d5cfdcf to
4b3fc7c
Compare
| @@ -0,0 +1,99 @@ | |||
| const chai = require("chai"); | |||
There was a problem hiding this comment.
Please move the tests inside tests/unit-tests/proximitySelectors and if possible preferably to respective proximity selector test files.
There was a problem hiding this comment.
Moved the test file to tests/unit-tests/proximitySelectors/proximitySelector.test.js.
02972ca to
10538bc
Compare
10538bc to
0f1b1c5
Compare
|
@NivedhaSenthil , check pls |
When getContentQuads returns an empty quads array (e.g. for hidden or
off-screen elements), getBoxModel was returning { model: { border: undefined } }
instead of null. This caused getBoundingClientRect to crash with:
TypeError: Cannot read properties of undefined (reading '1')
Fix getBoxModel to return null when quads is empty so that all existing
null-checks in getBoundingClientRect and boundBox work correctly.
Also guard getPositionalDifference against null rects by returning
Number.POSITIVE_INFINITY, ensuring such elements never win proximity
comparisons in proximityElementSearch.js.
Fixes getgauge#2757
Signed-off-by: winst0niuss <chumachenko.vadym@gmail.com>
After getBoxModel started returning null for empty quads, highlightElement would crash with TypeError when trying to access result.model.border. Skip the highlight gracefully when getBoxModel returns null (e.g. a visible element that has no rendered quads on certain platforms/Node versions). Signed-off-by: winst0niuss <chumachenko.vadym@gmail.com>
Signed-off-by: winst0niuss <chumachenko.vadym@gmail.com>
0f1b1c5 to
924ba2f
Compare
Without an explicit import, the test relies on $.test.js loading chai-as-promised first — an order-dependent side effect that breaks on Windows where glob returns files in a different order. Signed-off-by: winst0niuss <chumachenko.vadym@gmail.com>
0781fab to
356f1e0
Compare
|
After merging getgauge:master, the Windows CI jobs started failing due to a bug introduced in #2772. Root cause: evaluate.test.js (added in #2772) uses .rejectedWith() from chai-as-promised without importing it. On macOS/Linux the tests pass by accident — $.test.js runs first (glob sorts $ before letters in ASCII) and loads chai-as-promised globally. On Windows, glob returns files in a different order, so evaluate.test.js runs before chai-as-promised is loaded, causing TypeError: rejectedWith is not a function. |
|
Fix: Added an explicit chai-as-promised import to evaluate.test.js so the test no longer depends on execution order. |
Signed-off-by: winst0niuss <chumachenko.vadym@gmail.com>
ec7528a to
e1e93e8
Compare
|
Added a retry (2 attempts) for Windows CI jobs to avoid flaky failures we keep seeing on GitHub runners |
|
@zabil , re-run tests pls |
|
All checks are green. Please merge 🙂 |
|
@NivedhaSenthil please merge if you are ok with the review updates. |
Fixes #2757
Problem
Proximity selectors (
toRightOf,toLeftOf,above,below,near) throwTypeError: Cannot read properties of undefined (reading '1')indomHandler.js:152.Root cause
After migrating from
dom.getBoxModeltodom.getContentQuads, the null-check logic broke. WhengetContentQuadsreturnsquads: [](element is hidden, off-screen, etc.),result.quads[0]isundefined, butgetBoxModelstill returned a non-null object — so theif (!result)guard ingetBoundingClientRectnever fired, and accessing
quad[1]crashed.Two additional call sites had the same unguarded pattern:
getPositionalDifference— did not handlenullfromgetBoundingClientRecthighlightElement— did not handlenullfromgetBoxModelChanges
domHandler.js—getBoxModel: returnnullwhenquadsis empty, making all downstream guards work correctly.domHandler.js—getPositionalDifference: returnNumber.POSITIVE_INFINITYwhen either element has no bounding box, so it never wins the proximity comparison inproximityElementSearch.js.elementHelper.js—highlightElement: skip highlight gracefully whengetBoxModelreturnsnull(e.g. visible element with no rendered quads on certain platforms).tests/unit-tests/proximitySelector.test.js: new regression test covering all five proximity selectors and a hidden element case (display:none) that triggers the empty-quads path.