Skip to content

Commit d413fb4

Browse files
authored
feat(ci): Use Argos to snapshot html/css and accessibility tree (#12382)
1 parent eef60b7 commit d413fb4

12 files changed

Lines changed: 258 additions & 398 deletions

File tree

.github/workflows/argos.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
(github.event_name != 'pull_request' && github.ref_name == 'main') ||
3333
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'Argos'))
3434
)
35-
runs-on: ubuntu-latest
35+
# runs-on: ubuntu-latest
36+
runs-on: 8-core-ubuntu
3637
steps:
3738
- name: Check out repository code
3839
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -55,5 +56,8 @@ jobs:
5556
- name: Build website fast
5657
run: pnpm argos:build
5758

58-
- name: Take Argos screenshots
59+
- name: Take and upload Argos screenshots
5960
run: pnpm argos:screenshot
61+
62+
- name: Upload Argos text snapshots
63+
run: pnpm argos:upload-text-snapshots

argos/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@ We use [Argos CI](https://argos-ci.com) to detect visual regressions on Docusaur
44

55
This workspace can be run manually, but is generally run through the [Argos GitHub Action](../.github/workflows/argos.yml).
66

7+
## Workflow overview
8+
79
The workflow execute those following steps:
810

9-
- Build the website locally with `pnpm build:website:fast`
11+
- Build the website locally with `pnpm argos:build` (a variant of `pnpm build:website:fast`)
1012
- Start the website server with `pnpm serve:website` on [http://localhost:3000](http://localhost:3000)
1113
- Take screenshots of all pages found in `sitemap.xml` with Playwright
12-
- Upload all screenshots to [Argos CI](https://argos-ci.com)
14+
- Upload all screenshots to [Argos CI](https://argos-ci.com) using the [Playwright reporter](https://argos-ci.com/docs/reference/playwright)
15+
- Upload [HTML/CSS/JS files to also diff them on Argos](https://argos-ci.com/docs/learn/how-to-guides/visual-coverage/compare-non-image-files) using `pnpm argos:upload-text-snapshots`
1316

1417
This workflow runs for `main` and PR branches, and add a commit status to each PR with a visual diff that we can easily inspect.
1518

16-
---
19+
## Run manually
20+
21+
To run this manually, use:
22+
23+
```bash
24+
pnpm argos:build
25+
pnpm argos:screenshot
26+
pnpm argos:upload-text-snapshots
27+
```
28+
29+
The Playwright reporter will upload the screenshots to Argos.
1730

18-
Some additional capabilities:
31+
## How to modify
1932

2033
- Use [./tests/screenshot.spec.ts](./tests/screenshot.spec.ts) to customize the screenshots we take, eventually filter out some useless sitemap pages like versioned docs
2134
- Use [./tests/screenshot.css](./tests/screenshot.css) to hide flaky CSS elements: iframe, video, gif...

argos/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
"private": true,
77
"scripts": {
88
"screenshot": "playwright test",
9-
"upload": "pnpm dlx @argos-ci/cli upload ./screenshots/chromium",
9+
"upload": "pnpm exec -- argos upload ./screenshots/chromium",
10+
"upload-text-snapshots": "pnpm exec -- argos upload \"../website/build\" --build-name text-snapshots --files styles.css --files \"docs/**/*.html\" --files \"blog/**/*.html\"",
1011
"report": "playwright show-report"
1112
},
1213
"dependencies": {
13-
"@argos-ci/playwright": "^7.0.6",
14-
"@playwright/test": "^1.60.0",
14+
"@argos-ci/cli": "^6.9.0",
15+
"@argos-ci/playwright": "^7.4.6",
16+
"@playwright/test": "^1.62.1",
1517
"cheerio": "^1.2.0"
1618
}
1719
}

argos/playwright.config.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {devices} from '@playwright/test';
9-
import type {PlaywrightTestConfig} from '@playwright/test';
8+
import {defineConfig, devices} from '@playwright/test';
9+
import {createArgosReporterOptions} from '@argos-ci/playwright/reporter';
10+
11+
const argosOptions = createArgosReporterOptions({
12+
uploadToArgos: true, // for now, we always upload even outside of CI
13+
buildName: 'screenshots',
14+
});
1015

1116
/**
1217
* See https://playwright.dev/docs/test-configuration.
1318
*/
14-
const config: PlaywrightTestConfig = {
19+
export default defineConfig({
1520
testDir: './tests',
1621

1722
timeout: 60000,
1823

19-
reporter: [['list'], ['@argos-ci/playwright/reporter']],
24+
reporter: [['list'], ['@argos-ci/playwright/reporter', argosOptions]],
2025

2126
// Run website production built
2227
// Need to run "pnpm build:website:fast" before
@@ -32,9 +37,12 @@ const config: PlaywrightTestConfig = {
3237
name: 'chromium',
3338
use: {
3439
...devices['Desktop Chrome'],
40+
// Recommended by Argos
41+
// See https://argos-ci.com/docs/learn/reliability-and-flakiness/flaky-tests/stabilize-text-rendering
42+
launchOptions: {
43+
args: ['--disable-lcd-text', '--font-render-hinting=none'],
44+
},
3545
},
3646
},
3747
],
38-
};
39-
40-
export default config;
48+
});

argos/tests/screenshot.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ function createPathnameTest(pathname: string) {
169169
await page.waitForFunction(waitForDocusaurusHydration);
170170
await page.addStyleTag({content: stylesheet});
171171
// await expect(page).toHaveScreenshot({ fullPage: true, ...options });
172-
await argosScreenshot(page, pathnameToArgosName(pathname));
172+
await argosScreenshot(page, pathnameToArgosName(pathname), {
173+
ariaSnapshot: true,
174+
});
173175
});
174176
}
175177

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
"crowdin:upload:website": "crowdin upload sources --config ./crowdin-v2.yaml",
3636
"crowdin:download": "crowdin download --config ./crowdin-v2.yaml",
3737
"crowdin:download:website": "pnpm crowdin:download --language fr --language ko --language pt-BR --language zh-CN --language ja",
38-
"argos": "pnpm argos:build && pnpm argos:screenshot",
38+
"argos": "pnpm argos:build && pnpm argos:screenshot && argos:upload-text-snapshots",
3939
"argos:build": "cross-env DOCUSAURUS_ARGOS_BUILD=true pnpm build:website:fast --dev",
4040
"argos:screenshot": "pnpm --filter argos screenshot",
41+
"argos:upload-text-snapshots": "pnpm --filter argos upload-text-snapshots",
4142
"canary": "pnpm canary:bumpVersion && pnpm canary:publish",
4243
"canary:getCoreVersion": "node -p \"require('./packages/docusaurus/package.json').version.split('-')[0]\"",
4344
"canary:version": "echo `pnpm --silent canary:getCoreVersion`-canary-`git rev-list --count HEAD`+`git rev-parse --short HEAD`",

0 commit comments

Comments
 (0)