Skip to content

Commit 1cda598

Browse files
authored
Merge pull request #6068 from alphagov/percy-snapshot-scope
Use scope option in percy snapshots
2 parents f416e3f + e58ad88 commit 1cda598

1 file changed

Lines changed: 13 additions & 21 deletions

File tree

shared/tasks/browser.mjs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export async function screenshots() {
7272
export async function screenshotComponent(browser, componentName, options) {
7373
const componentFiles = await getComponentFiles(componentName)
7474

75+
// Percy snapshot options
76+
// Scope is .app-wihtespace-highlight rather than .govuk-main-wrapper like with
77+
// the examples so that margin that isn't part of the component doesn't get
78+
// included in the screenshot
79+
/** @type {SnapshotOptions} */
80+
const snapshotOptions = { scope: '.app-whitespace-highlight' }
81+
7582
// Navigate to component
7683
const page = await goToComponent(browser, componentName, options)
7784

@@ -81,15 +88,15 @@ export async function screenshotComponent(browser, componentName, options) {
8188
: componentName
8289

8390
// Screenshot preview page (with JavaScript)
84-
await percySnapshot(page, `js: ${screenshotName}`)
91+
await percySnapshot(page, `js: ${screenshotName}`, snapshotOptions)
8592

8693
// Check for "JavaScript enabled" components
8794
if (componentFiles.some(filterPath([`**/${componentName}.mjs`]))) {
8895
await page.setJavaScriptEnabled(false)
8996

9097
// Screenshot preview page (without JavaScript)
9198
await page.reload({ waitUntil: 'load' })
92-
await percySnapshot(page, `no-js: ${screenshotName}`)
99+
await percySnapshot(page, `no-js: ${screenshotName}`, snapshotOptions)
93100
}
94101

95102
// Close page
@@ -107,31 +114,16 @@ export async function screenshotComponent(browser, componentName, options) {
107114
export async function screenshotExample(browser, exampleName) {
108115
const page = await goToExample(browser, exampleName)
109116

110-
// Dismiss app banner
111-
await page.setCookie({
112-
name: 'dismissed-app-banner',
113-
value: 'yes',
114-
url: page.url()
115-
})
116-
117-
await page.reload({ waitUntil: 'load' })
118-
119-
// Remove feature flag banner
120-
await page.evaluate(() => {
121-
const featureFlagBanner = document.querySelector('.app-feature-flag-banner')
122-
123-
if (featureFlagBanner) {
124-
featureFlagBanner.remove()
125-
}
126-
})
127-
128117
// Screenshot preview page
129-
await percySnapshot(page, `js: ${exampleName} (example)`)
118+
await percySnapshot(page, `js: ${exampleName} (example)`, {
119+
scope: '.govuk-main-wrapper'
120+
})
130121

131122
// Close page
132123
return page.close()
133124
}
134125

135126
/**
136127
* @import { Browser } from 'puppeteer'
128+
* @import { SnapshotOptions } from '@percy/core'
137129
*/

0 commit comments

Comments
 (0)