Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for Percy to idle before screenshot task finishes #3767

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}