Skip to content

Commit

Permalink
Take Percy snapshots sequentially
Browse files Browse the repository at this point in the history
Percy runs healthchecks in each `percySnapshot()` call and might cause a potential race condition
  • Loading branch information
colinrotherham committed Jun 7, 2023
1 parent c231f57 commit 85f4cc9
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions shared/tasks/browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,14 @@ 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
Expand Down

0 comments on commit 85f4cc9

Please sign in to comment.