Galooshi / happo

Visual diffing in CI for user interfaces
505 stars 16 forks source link

Include margin of topmost element in dimension calculations #108

Closed lencioni closed 8 years ago

lencioni commented 8 years ago

We currently recurse through the DOM tree using getBoundingClientRect() to determine the shape of the box that we want to take a screenshot of. This is working well, except when the topmost element has margin on it, since getBoundingClientRect() does not include margin. This means that you might miss some important details about the visual appearance of your component if you aren't being super careful.

I think we should use getComputedStyle() to determine the margin of the topmost element and use that in our rectangle dimension calculations. I want to avoid doing this for every node in the tree, since it is not the fastest method. I think doing this on the topmost element will likely get us 99% of the benefit, so it seems like an easy win.