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
Send Percy screenshots via npm script (not Jest) #3009
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ jobs: | |
|
||
- description: JavaScript component tests | ||
name: test-component | ||
run: npx percy exec -- jest --color --selectProjects "JavaScript component tests" | ||
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript component tests" | ||
|
||
steps: | ||
- name: Checkout | ||
|
@@ -160,5 +160,28 @@ jobs: | |
|
||
- name: Run verify task | ||
run: ${{ matrix.run }} | ||
env: | ||
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
|
||
regression: | ||
name: Send screenshots to Percy | ||
runs-on: ubuntu-latest | ||
needs: [install, build] | ||
|
||
env: | ||
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
PORT: 8888 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review app uses port |
||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Restore dependencies | ||
uses: ./.github/workflows/actions/install-node | ||
|
||
- name: Restore build | ||
uses: ./.github/workflows/actions/build | ||
|
||
- name: Start review application | ||
run: npm run serve & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starts the review app in the background using |
||
|
||
- name: Send screenshots to Percy | ||
run: npx percy exec -- npm run test:screenshots |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ We generate 2 screenshots for each default example of every component. One examp | |
|
||
The screenshots are public, so you can check them without logging in. A BrowserStack account is needed to approve or reject any changes (if you don't have access, ask your tech lead for help). If you're the reviewer of the pull request code, it's your responsibility to approve or request changes for any visual changes Percy highlights. | ||
|
||
When you run the tests locally (for example, using `npm test`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`. | ||
When you run the tests locally (for example, using `npm run test:screenshots`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for keeping the docs in sync 🙌🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @36degrees No problem. I didn't quite know if we should keep the Based on the "…‘tests’ aren’t really tests” feedback But we can always revisit another day. Thanks again 😊 |
||
|
||
### PRs from forks | ||
When Github Actions is running against a PR from a fork, the Percy secret is not available and Percy does not generate any screenshots. Other tests will continue to run as normal. You will see the following messages in the output: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { join } from 'path' | ||
import { launch } from 'puppeteer' | ||
import percySnapshot from '@percy/puppeteer' | ||
import { isPercyEnabled } from '@percy/sdk-utils' | ||
|
||
import { getDirectories, getListing } from '../lib/file-helper.js' | ||
import { goToComponent } from '../lib/puppeteer-helpers.js' | ||
|
||
import configPaths from '../config/paths.js' | ||
import configPuppeteer from '../puppeteer.config.js' | ||
|
||
/** | ||
* Send all component screenshots to Percy | ||
* for visual regression testing | ||
* | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function screenshotComponents () { | ||
const browser = await launch(configPuppeteer.launch) | ||
const componentNames = await getDirectories(configPaths.components) | ||
|
||
// Screenshot each component | ||
const input = [...componentNames] | ||
|
||
// Screenshot 4x components concurrently | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you arrive at 4x? Might be useful to capture in the commit message in case we want to revisit in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried 5x initially but 4x was faster Good point though, worth trying 2x and 3x as well (you never know!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you click into the Send screenshots to Percy job to see the timings:
The total action time varies due to GitHub cache retrieval API times being wobbly I'll keep it at 4x but add a comment |
||
while (input.length) { | ||
const batch = input.splice(0, 4) | ||
|
||
await Promise.all(batch | ||
.map(async (componentName) => screenshotComponent(await browser.newPage(), componentName)) | ||
) | ||
} | ||
|
||
// Close browser | ||
return browser.close() | ||
} | ||
|
||
/** | ||
* Send single component screenshots to Percy | ||
* for visual regression testing | ||
* | ||
* @param {import('puppeteer').Page} page - Puppeteer page object | ||
* @param {string} componentName - Component name | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function screenshotComponent (page, componentName) { | ||
const componentFiles = await getListing(configPaths.components, `**/${componentName}/**`) | ||
|
||
// Screenshot preview page (with JavaScript) | ||
await goToComponent(page, componentName) | ||
await percySnapshot(page, `js: ${componentName}`) | ||
|
||
// Check for "JavaScript enabled" components | ||
if (componentFiles.includes(join(componentName, `${componentName}.mjs`))) { | ||
await page.setJavaScriptEnabled(false) | ||
|
||
// Screenshot preview page (without JavaScript) | ||
await page.reload({ waitUntil: 'load' }) | ||
await percySnapshot(page, `no-js: ${componentName}`) | ||
} | ||
|
||
// Close page | ||
return page.close() | ||
} | ||
|
||
if (!await isPercyEnabled()) { | ||
throw new Error('Percy healthcheck failed') | ||
} | ||
|
||
await screenshotComponents() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the CPU load from the @percy/puppeteer Chromium tabs we can now run JavaScript component tests with 2x workers
We use the same flag for JavaScript behaviour tests above