Skip to content

Commit

Permalink
Merge pull request #3767 from alphagov/percy-idle
Browse files Browse the repository at this point in the history
Wait for Percy to idle before screenshot task finishes
  • Loading branch information
colinrotherham committed Jun 9, 2023
2 parents 28d2ab8 + c599ed5 commit 2e7f92d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/govuk-frontend-review/percy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { executablePath } = require('puppeteer')
*/
module.exports = {
discovery: {
concurrency: 1,
launchOptions: {
executable: executablePath()
}
Expand Down
33 changes: 12 additions & 21 deletions shared/tasks/browser.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import percySnapshot from '@percy/puppeteer'
import { waitForPercyIdle } from '@percy/sdk-utils'
import { download } from 'govuk-frontend-helpers/jest/browser/download.mjs'
import { goToComponent, goToExample } from 'govuk-frontend-helpers/puppeteer'
import { filterPath, getComponentFiles, getComponentNames } from 'govuk-frontend-lib/files'
Expand Down Expand Up @@ -27,31 +28,21 @@ export async function screenshots () {
const componentNames = await getComponentNames()
const exampleNames = ['text-alignment', 'typography']

// Screenshot stack
const input = []

// Add components to screenshot
input.push(...componentNames.map((screenshotName) =>
/** @type {const} */ ([screenshotComponent, screenshotName])))

// Add examples to screenshot
input.push(...exampleNames.map((screenshotName) =>
/** @type {const} */ ([screenshotExample, screenshotName])))

// Batch 4x concurrent screenshots
while (input.length) {
const batch = input.splice(0, 4)

// Take screenshots
const screenshotTasks = batch.map(async ([screenshotFn, screenshotName]) =>
screenshotFn(await browser.newPage(), screenshotName))
// Screenshot components
for (const componentName of componentNames) {
await screenshotComponent(await browser.newPage(), componentName)
}

// Wait until batch finishes
await Promise.all(screenshotTasks)
// Screenshot examples
for (const exampleName of exampleNames) {
await screenshotExample(await browser.newPage(), exampleName)
}

// Close browser
return browser.close()
await browser.close()

// Wait for Percy to finish
return waitForPercyIdle()
}

/**
Expand Down
8 changes: 8 additions & 0 deletions shared/tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
"sass-embedded": "^1.62.0",
"slash": "^5.1.0",
"yargs-parser": "^21.1.1"
},
"peerDependencies": {
"@percy/sdk-utils": ">=1.25"
},
"peerDependenciesMeta": {
"@percy/sdk-utils": {
"optional": true
}
}
}

0 comments on commit 2e7f92d

Please sign in to comment.