Closed joshkel closed 1 month ago
You are totally right @joshkel!
Plan:
DOMRect
polyfill through our @atlaskit/pragmatic-drag-and-drop-unit-testing
packageDOMRect
Here is the polyfill that we are currently using for JSDOM
// This file polyfills DOMRect
// DOMRect is currently not polyfilled by jsdom
(() => {
if (typeof window === 'undefined') {
return;
}
if (window.DOMRect) {
return;
}
class DOMRect {
constructor(x = 0, y = 0, width = 0, height = 0) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
// Computed values.
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
this.top = height < 0 ? y + height : y;
this.right = width < 0 ? x : x + width;
this.bottom = height < 0 ? y : y + height;
this.left = width < 0 ? x + width : x;
}
static fromRect(rectangle) {
return new DOMRect(rectangle?.x, rectangle?.y, rectangle?.width, rectangle?.height);
}
toJSON() {
return JSON.stringify(this);
}
}
window.DOMRect = DOMRect;
})();
We are about to ship a polyfill package and updated test guidance
Thank you @joshkel for raising this!
The new "honey pot fix" in @atlaskit/pragmatic-drag-drop version 1.2.0 has added usage of DOMRect, which isn't provided by jsdom. This resulted in our Jest tests failing with errors similar to the following:
To fix it, test code can polyfill DOMRect. I'm currently using the implementation from jarek-foksa/geometry-polyfill, and it seems to work.
Pragmatic Drag and Drop's very helpful testing guide should be updated with this information.