storycap
storycap copied to clipboard
Expose setViewport on window
The request is to, in https://github.com/reg-viz/storycap/blob/master/packages/storycap/src/node/capturing-browser.ts , add to expose()
another function, something like setViewport: (vp) => this.page.setViewport(vp)
, so that a test could do await window.setViewport(...)
Why?
We now have play
functions, and hence UI interactions. These UI interactions may differ due to the size of the UI (i.e. responsive design might hide text when the window is narrow), which fundamentally goes to the window size. So it would be nice to be able to set the window size at the beginning of the test, rather than only when the screenshot happens. Otherwise play
functions might become flaky and confusing.
Note that any other solution to the problem would be fine too - only that it would be strongly preferred for it to be possible to resize the viewport dynamically, rather than e.g. declaring in a test's parameters that it should have a given set of dimensions.
It might be possible to pass arguments to storycap to have a given viewport, but such a global option would not be preferred as individual tests might have individual viewports.
https://github.com/Jamie5/storycap/pull/1/commits/cff4d388903cebc908d2ebe2e3f7ba156af707ba works, though I imagine you would prefer to not just expose things on window itself. If this general feature is something you'd like to have I can work on something that is more wrapped properly, as it would be nice not to have to maintain forks and stuff.
I'm also interested in the ability to set the window size at the beginning of the test -- would it be possible to merge Jamie's change linked above?