@fusion.dev/helix-docs 0.202.0 → 0.203.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/content/metrics.mdx +234 -234
- package/content/visual-testing.mdx +110 -0
- package/dist/pages.generated.js +6 -0
- package/dist/sources.generated.js +345 -234
- package/package.json +11 -11
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Picture every page and component in a real browser, compare each picture with a baseline kept in git, and fail the run when one changes.
|
|
3
|
+
section: Tooling
|
|
4
|
+
title: Visual testing
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Visual testing
|
|
8
|
+
|
|
9
|
+
`helix visual` takes pictures of your pages and components in a real browser,
|
|
10
|
+
compares each one to a baseline kept in your git repository, and fails the run
|
|
11
|
+
when a picture changes. It ships in `@fusion.dev/helix-cli`, and it pictures
|
|
12
|
+
any web project, with Helix or without it.
|
|
13
|
+
|
|
14
|
+
It pictures HTML files, any server's pages, Storybook stories, and entries from
|
|
15
|
+
a JSON catalog, and it has a GitHub Action.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install --save-dev @fusion.dev/helix-cli playwright
|
|
21
|
+
npx playwright install --with-deps chromium
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Capture runs in Playwright, which you install beside the command line. The
|
|
25
|
+
rest of `helix` needs no browser, so Playwright is an optional peer, and
|
|
26
|
+
`helix visual test` names it when it is missing.
|
|
27
|
+
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
helix visual test compare every shot, and fail on a difference
|
|
32
|
+
helix visual test button only the entries named button
|
|
33
|
+
helix visual update write only the baselines the comparison rejects
|
|
34
|
+
helix visual test --shard 0 --of 4 the first of four shards, for CI
|
|
35
|
+
helix visual report open the report of the last run
|
|
36
|
+
helix visual compare a.png b.png compare two PNG files, with no browser
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **`helix visual test`** pictures every entry and compares each shot with its
|
|
40
|
+
baseline. It exits 1 when a shot differs, changes size, has no baseline, or
|
|
41
|
+
cannot be taken, and writes an image of each difference beside its baseline,
|
|
42
|
+
named `<stem><suffix>.diff.png`. Add `*.diff.png` to your `.gitignore`.
|
|
43
|
+
- **`helix visual update`** pictures every entry and writes a baseline only
|
|
44
|
+
where the comparison would fail. Review the files it writes before you
|
|
45
|
+
commit them.
|
|
46
|
+
- **`helix visual report`** opens the report the last run wrote. `--markdown`
|
|
47
|
+
prints its summary as Markdown, for a CI job's summary page. `--merge` takes
|
|
48
|
+
the reports of a run's shards and prints their changes as one set of groups.
|
|
49
|
+
- **`helix visual compare`** compares two PNG files. `--diff` writes the image
|
|
50
|
+
of the difference, and `--threshold` sets how far apart two colors may be
|
|
51
|
+
and still count as the same pixel.
|
|
52
|
+
|
|
53
|
+
Each run ends with one line that says what it compared and what it skipped.
|
|
54
|
+
`helix --json visual …` prints one JSON document on stdout and moves the
|
|
55
|
+
sentences to stderr.
|
|
56
|
+
|
|
57
|
+
## The config
|
|
58
|
+
|
|
59
|
+
`visual.config.ts`, in the directory you run `helix visual` from:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { defineConfig } from '@fusion.dev/helix-cli/visual'
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
serve: { '/theme.css': 'dist/theme.css' },
|
|
66
|
+
shots: [
|
|
67
|
+
{ name: 'wide', scheme: 'light', width: 1280 },
|
|
68
|
+
{ name: 'phone', scheme: 'light', width: 390 },
|
|
69
|
+
{ name: 'dark', scheme: 'dark', width: 1280 },
|
|
70
|
+
],
|
|
71
|
+
sources: [
|
|
72
|
+
{
|
|
73
|
+
glob: '{name}/example.html',
|
|
74
|
+
kind: 'html',
|
|
75
|
+
name: 'components',
|
|
76
|
+
root: 'src',
|
|
77
|
+
styles: ['/theme.css'],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- **`sources`** is where the entries come from. `html` reads every file its
|
|
84
|
+
`glob` matches under `root` and pictures each inside a document that links
|
|
85
|
+
`styles`. `server` pictures a server's `routes` and every route its
|
|
86
|
+
`sitemap` lists. `storybook` pictures every story in a running Storybook.
|
|
87
|
+
`catalog` pictures every `{ id, url }` in a JSON file. `pairs` compares two
|
|
88
|
+
renders of each entry with each other.
|
|
89
|
+
- **`shots`** is the pictures taken of each entry: a wide width, a phone
|
|
90
|
+
width, and dark when you give none. Each baseline is written beside its
|
|
91
|
+
entry as `<stem>.<name>.png`.
|
|
92
|
+
- **`serve`** is URL paths served from disk, relative to the config.
|
|
93
|
+
- **`settle.readyProperty`** names a property your elements carry holding a
|
|
94
|
+
promise that resolves once they have rendered. The run awaits it before each
|
|
95
|
+
shot.
|
|
96
|
+
- **`aria`** keeps each entry's accessibility snapshot beside its baselines
|
|
97
|
+
and compares it as text, so a lost label fails even when no pixel moved.
|
|
98
|
+
- **`checks`** adds judgments that need no baseline: `code` fails a code block
|
|
99
|
+
drawn in one color, `clipped` fails a box that cuts off its own text, and
|
|
100
|
+
`overlap` fails two boxes of text or controls that draw over each other.
|
|
101
|
+
|
|
102
|
+
The command's own reference, with every option, is the README of
|
|
103
|
+
`@fusion.dev/helix-cli`.
|
|
104
|
+
|
|
105
|
+
## How Fusion uses it
|
|
106
|
+
|
|
107
|
+
Fusion runs `helix visual` on every Helix example and on the site's pages on
|
|
108
|
+
every push, and keeps the baselines in git. A change to how a component draws
|
|
109
|
+
fails the run with a picture of the difference, and a retake opens a pull
|
|
110
|
+
request of new baselines for review.
|
package/dist/pages.generated.js
CHANGED
|
@@ -290,6 +290,12 @@ export const docPages = [
|
|
|
290
290
|
slug: 'visual-axes',
|
|
291
291
|
title: 'Visual axes',
|
|
292
292
|
},
|
|
293
|
+
{
|
|
294
|
+
description: 'Picture every page and component in a real browser, compare each picture with a baseline kept in git, and fail the run when one changes.',
|
|
295
|
+
section: 'Tooling',
|
|
296
|
+
slug: 'visual-testing',
|
|
297
|
+
title: 'Visual testing',
|
|
298
|
+
},
|
|
293
299
|
{
|
|
294
300
|
description: 'The compiler setting Vue needs, and how Vue passes props and binds events.',
|
|
295
301
|
parent: 'installation',
|