Open 10upsimon opened 1 week ago
@10upsimon to summarize our recent discussions
constrainToViewport
to false
to keep things closer to how they are with Backstop by default and what our images contain to-date. The constrain: true case should be an edge case anyways as there's only been the one (?) so far where it's been importantselectors: #document
for those scenarios. While this is not ideal, it saves the effort of applying this automatically for now which we can do in a follow up as this involves a more complicated change in the babel traversal to "find" that property for relevant stories--filter [filter]
Feature Description
Enhancement 01
While working on #9375 it was discovered that elements that should be fixed to the bottom of the viewport (or other such element) - via
position: fixed; bottom: 0;
style implementations - are appearing as floating in the middle of nowhere in the actual VRT test bitmaps. An example of this can be seen below:Upon assessing the viewport definitions at
tests/backstop/viewports.js
, specifically taking the small viewport into account...... It was discovered that the apparent floating element was indeed ending at the 580px vertical mark, indicating that - according to the defined viewport size - it was indeed correctly positioned.
Further investigation revealed that none of the VRT test images were adhering to the viewport constraints. This is due to the default selector in Backstop being
document
. Therefore, the entire document as being captured.The
selectors
property can be applied to scenarios to specify which selector you'd like Backstop to "capture". An obvious fix for this seemed to be the application ofselectors: [ 'viewport ]
to each scenario.In theory, this would have been an acceptable approach, however some stories are more style-guide in nature, and require the full canvas of of the story to be captured during testing, and our existing implementation of Backstop and/or Puppeteer does not appear to respect this selector. Examples stories include:
Digging deeper, it was clear that two key features are needing to be introduced to solve this issue:
In order to achieve this, a few key aspects will need to be introduced, namely:
constrainToViewport
with a default value oftrue
tests/backstop/scenarios.js
for both modern and legacy story traversalsselectors
property for each scenario to one of the following:selectors: [ '#document ],
for stories that should be constrained to the viewport dimensions (default), more details on this further belowselectors: [ 'document' ]
for stories that should not be constrained to the viewport dimensions.storybook/preview.js
that conditionally renders a new div wrapper with IDdocument
for viewport constraint stories. This additional element would have CSS that constrains it's dimensions to the viewport, and prevents overflow of content. This is required in order to fix the default behaviour of Backstop not adhering to the[ 'viewport' ]
selector. This element should purposefully be named#document
so that all existing VRT images that do continue to pass are named identical to the default[ 'document' ]
selector, thus limiting the failures. If this was not the case, ALL existing VRT tests would fail.Following the above, a story who wishes to break out of the viewport constraint would simply pass the applicable parameter:
Thus allowing the fill canvas to be captured as prior.
Not only will this transform the VRT captures to be true to our viewport definitions, it'll also reduce the size of the VRT reference folder and the test payload itself. Although this may not have an execution-time based impact, it's still less energy, a less wasteful operation overall.
Enhancement 02
While exploring possible solutions related to the above, it was becoming increasingly clear that having to run the entire VRT suite over and over was becoming a) time consuming and b) more prone to error should system resources become unstable (resulting in false failures, timeouts etc).
Part of this VRT enhancement sees the ability to specify a single or multiple scenario labels that should be run as part of the VRT test. This is a simple yet effective enhancement, and will greatly reduce developer overhead when needing to run and re-run VRT tests locally when working on a single or small handful of component updates.
Given the fact that story scenarios are assigned to a single constant, this can easily be achieve by:
process.argv
--labels
passed to the npmtest:visualtest
commandscenarios.filter()
and matching against those passed to the--labels
argThis would allow developers to run single or multiple story scenarios for purposes of VRT via a command like or similar to the following:
npm run test:visualtest -- --labels="KeyMetrics/MetricSelectionPanel"
This would be a welcome enhancement for local development.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
test:visualtest
job should be constrained to the sizes defined intests/backstop/viewports.js
unless otherwise specified via a newconstrainToViewport
story scenario property.storybook/preview.js
that conditionally renders the required markup for the above to be satisfied, and should be the last decorator in the file. This decorator should be aptly documented as such, given the importance that it remains the last decorator in the list.document
with applicable inline styles that constrain the rendered story to the viewport width and height, with no overflow. This element ID is aptly nameddocument
to preserve file naming conventions as per the point above.test:visualtest
job via the addition of an optional--args
argument that can be passed to the job cli command, i.enpm run test:visualtest -- --labels="Some/Label"
.constrainToViewport
parameter, specifying a boolean value offalse
. Stories that should adhere to the viewport constraints (default behaviour) should not be updated, as this will be the default outcome.test:visualtest
job.test:visualtest
job should render no test failures.Implementation Brief
Test Coverage
QA Brief
Changelog entry