viewev 0.0.0-stage → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +131 -2
- package/assets/logo/Logo-horizontal.png +0 -0
- package/dist/adapters/storybook/index.d.ts +5 -0
- package/dist/adapters/storybook/index.js +4 -0
- package/dist/adapters/storybook/index.js.map +1 -0
- package/dist/adapters/storybook/provider.d.ts +24 -0
- package/dist/adapters/storybook/provider.js +114 -0
- package/dist/adapters/storybook/provider.js.map +1 -0
- package/dist/adapters/storybook/scenarios.d.ts +30 -0
- package/dist/adapters/storybook/scenarios.js +64 -0
- package/dist/adapters/storybook/scenarios.js.map +1 -0
- package/dist/adapters/storybook/static-server.d.ts +10 -0
- package/dist/adapters/storybook/static-server.js +105 -0
- package/dist/adapters/storybook/static-server.js.map +1 -0
- package/dist/adapters/storybook/storybook-index.d.ts +32 -0
- package/dist/adapters/storybook/storybook-index.js +35 -0
- package/dist/adapters/storybook/storybook-index.js.map +1 -0
- package/dist/baselines/environment-check.d.ts +7 -0
- package/dist/baselines/environment-check.js +24 -0
- package/dist/baselines/environment-check.js.map +1 -0
- package/dist/baselines/environment-key.d.ts +8 -0
- package/dist/baselines/environment-key.js +12 -0
- package/dist/baselines/environment-key.js.map +1 -0
- package/dist/baselines/file-store.d.ts +12 -0
- package/dist/baselines/file-store.js +81 -0
- package/dist/baselines/file-store.js.map +1 -0
- package/dist/baselines/git-store.d.ts +16 -0
- package/dist/baselines/git-store.js +150 -0
- package/dist/baselines/git-store.js.map +1 -0
- package/dist/baselines/metadata.d.ts +16 -0
- package/dist/baselines/metadata.js +84 -0
- package/dist/baselines/metadata.js.map +1 -0
- package/dist/baselines/types.d.ts +33 -0
- package/dist/baselines/types.js +2 -0
- package/dist/baselines/types.js.map +1 -0
- package/dist/browser/playwright/capturer.d.ts +2 -0
- package/dist/browser/playwright/capturer.js +142 -0
- package/dist/browser/playwright/capturer.js.map +1 -0
- package/dist/browser/playwright/environment.d.ts +4 -0
- package/dist/browser/playwright/environment.js +36 -0
- package/dist/browser/playwright/environment.js.map +1 -0
- package/dist/browser/playwright/index.d.ts +1 -0
- package/dist/browser/playwright/index.js +2 -0
- package/dist/browser/playwright/index.js.map +1 -0
- package/dist/browser/types.d.ts +43 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/ci/github-summary.d.ts +5 -0
- package/dist/ci/github-summary.js +95 -0
- package/dist/ci/github-summary.js.map +1 -0
- package/dist/cli/baseline-ref.d.ts +6 -0
- package/dist/cli/baseline-ref.js +11 -0
- package/dist/cli/baseline-ref.js.map +1 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +13 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/commands/baseline.d.ts +3 -0
- package/dist/cli/commands/baseline.js +90 -0
- package/dist/cli/commands/baseline.js.map +1 -0
- package/dist/cli/commands/capture.d.ts +3 -0
- package/dist/cli/commands/capture.js +42 -0
- package/dist/cli/commands/capture.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.js +25 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.js +19 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/report.d.ts +3 -0
- package/dist/cli/commands/report.js +16 -0
- package/dist/cli/commands/report.js.map +1 -0
- package/dist/cli/commands/scenarios.d.ts +3 -0
- package/dist/cli/commands/scenarios.js +30 -0
- package/dist/cli/commands/scenarios.js.map +1 -0
- package/dist/cli/commands/test.d.ts +3 -0
- package/dist/cli/commands/test.js +123 -0
- package/dist/cli/commands/test.js.map +1 -0
- package/dist/cli/context.d.ts +21 -0
- package/dist/cli/context.js +22 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/doctor.d.ts +12 -0
- package/dist/cli/doctor.js +104 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/format.d.ts +17 -0
- package/dist/cli/format.js +106 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/cli/impact.d.ts +13 -0
- package/dist/cli/impact.js +57 -0
- package/dist/cli/impact.js.map +1 -0
- package/dist/cli/program.d.ts +11 -0
- package/dist/cli/program.js +70 -0
- package/dist/cli/program.js.map +1 -0
- package/dist/cli/session.d.ts +27 -0
- package/dist/cli/session.js +53 -0
- package/dist/cli/session.js.map +1 -0
- package/dist/comparison/compare.d.ts +11 -0
- package/dist/comparison/compare.js +41 -0
- package/dist/comparison/compare.js.map +1 -0
- package/dist/comparison/types.d.ts +34 -0
- package/dist/comparison/types.js +2 -0
- package/dist/comparison/types.js.map +1 -0
- package/dist/config/load.d.ts +23 -0
- package/dist/config/load.js +93 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +299 -0
- package/dist/config/schema.js +134 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/artifacts.d.ts +6 -0
- package/dist/core/artifacts.js +2 -0
- package/dist/core/artifacts.js.map +1 -0
- package/dist/core/baseline-run.d.ts +37 -0
- package/dist/core/baseline-run.js +85 -0
- package/dist/core/baseline-run.js.map +1 -0
- package/dist/core/capture-settings.d.ts +6 -0
- package/dist/core/capture-settings.js +21 -0
- package/dist/core/capture-settings.js.map +1 -0
- package/dist/core/discovery.d.ts +3 -0
- package/dist/core/discovery.js +17 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/impact.d.ts +19 -0
- package/dist/core/impact.js +28 -0
- package/dist/core/impact.js.map +1 -0
- package/dist/core/pool.d.ts +5 -0
- package/dist/core/pool.js +21 -0
- package/dist/core/pool.js.map +1 -0
- package/dist/core/result.d.ts +111 -0
- package/dist/core/result.js +53 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/selection.d.ts +8 -0
- package/dist/core/selection.js +8 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/test-run.d.ts +38 -0
- package/dist/core/test-run.js +140 -0
- package/dist/core/test-run.js.map +1 -0
- package/dist/impact/git.d.ts +17 -0
- package/dist/impact/git.js +55 -0
- package/dist/impact/git.js.map +1 -0
- package/dist/impact/types.d.ts +24 -0
- package/dist/impact/types.js +23 -0
- package/dist/impact/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/reporting/artifacts.d.ts +8 -0
- package/dist/reporting/artifacts.js +23 -0
- package/dist/reporting/artifacts.js.map +1 -0
- package/dist/reporting/html.d.ts +4 -0
- package/dist/reporting/html.js +244 -0
- package/dist/reporting/html.js.map +1 -0
- package/dist/reporting/report.d.ts +12 -0
- package/dist/reporting/report.js +55 -0
- package/dist/reporting/report.js.map +1 -0
- package/dist/reporting/results-json.d.ts +35 -0
- package/dist/reporting/results-json.js +37 -0
- package/dist/reporting/results-json.js.map +1 -0
- package/dist/scenarios/glob.d.ts +7 -0
- package/dist/scenarios/glob.js +21 -0
- package/dist/scenarios/glob.js.map +1 -0
- package/dist/scenarios/model.d.ts +61 -0
- package/dist/scenarios/model.js +31 -0
- package/dist/scenarios/model.js.map +1 -0
- package/dist/scenarios/schema.d.ts +8 -0
- package/dist/scenarios/schema.js +70 -0
- package/dist/scenarios/schema.js.map +1 -0
- package/dist/shared/environment.d.ts +23 -0
- package/dist/shared/environment.js +2 -0
- package/dist/shared/environment.js.map +1 -0
- package/dist/shared/errors.d.ts +23 -0
- package/dist/shared/errors.js +29 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/png.d.ts +3 -0
- package/dist/shared/png.js +14 -0
- package/dist/shared/png.js.map +1 -0
- package/dist/shared/size.d.ts +4 -0
- package/dist/shared/size.js +2 -0
- package/dist/shared/size.js.map +1 -0
- package/docs/architecture.md +180 -0
- package/docs/ci.md +212 -0
- package/docs/impact.md +46 -0
- package/package.json +58 -4
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Viewev architecture
|
|
2
|
+
|
|
3
|
+
Viewev is a modular monolith: one npm package with clear internal boundaries. This document is
|
|
4
|
+
the source of truth for those boundaries and for the decisions behind them.
|
|
5
|
+
|
|
6
|
+
## Principles
|
|
7
|
+
|
|
8
|
+
- Product-agnostic, framework-agnostic: no design-system logic in the core.
|
|
9
|
+
- Provider-independent: scenario discovery is separate from execution.
|
|
10
|
+
- Automation-independent: the core never sees Playwright types.
|
|
11
|
+
- Local-first: no hosted service, database or account.
|
|
12
|
+
- Deterministic: reproducible screenshots matter more than features.
|
|
13
|
+
- Explicit baselines: a changed screenshot is never approved silently.
|
|
14
|
+
- No speculative abstractions: an interface exists only where it protects a real boundary.
|
|
15
|
+
|
|
16
|
+
## Modules and dependency rules
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/
|
|
20
|
+
cli/ commander wiring, output, exit codes. The composition root.
|
|
21
|
+
config/ zod schema, loader, defineConfig
|
|
22
|
+
core/ lifecycle orchestration and the result model (interfaces only)
|
|
23
|
+
scenarios/ VisualScenario, ScenarioProvider, validation
|
|
24
|
+
adapters/storybook/ index.json -> scenarios, built-in static server
|
|
25
|
+
browser/ ScreenshotCapturer interface and types
|
|
26
|
+
browser/playwright/ the only code that imports Playwright
|
|
27
|
+
comparison/ pure image comparison with Pixelmatch
|
|
28
|
+
baselines/ filesystem layout, metadata, environment checks
|
|
29
|
+
reporting/ results.json, report artifacts and the static HTML report
|
|
30
|
+
shared/ errors and exit codes, size, environment info
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
ESLint enforces the rules (`eslint.config.js`):
|
|
34
|
+
|
|
35
|
+
- Only `src/browser/playwright` may import Playwright.
|
|
36
|
+
- `core` imports interfaces only: no adapters, no Playwright implementation, no `pixelmatch` or
|
|
37
|
+
`pngjs`, no `cli`.
|
|
38
|
+
- Only `cli` wires concrete adapters and implementations together.
|
|
39
|
+
|
|
40
|
+
## Scenario model
|
|
41
|
+
|
|
42
|
+
A scenario is a UI state Viewev can capture. Providers resolve everything provider-specific
|
|
43
|
+
(for Storybook, a story id becomes an `iframe.html` URL) so the core only sees a URL.
|
|
44
|
+
|
|
45
|
+
- `id` is stable and independent of the URL or port. It is also a file name, so it is limited
|
|
46
|
+
to lowercase letters, digits, `.`, `_`, `@` and `-`, and Windows reserved names are rejected.
|
|
47
|
+
- `variant` holds extra axes such as a theme. It is part of the scenario identity and opaque
|
|
48
|
+
to the core. Variants are modelled now and implemented later.
|
|
49
|
+
- Storybook's `index.json` contains no story parameters, only ids, titles, import paths, types
|
|
50
|
+
and tags. Per-scenario options therefore come from config rules or Storybook tags, never from
|
|
51
|
+
story parameters.
|
|
52
|
+
|
|
53
|
+
## Test lifecycle
|
|
54
|
+
|
|
55
|
+
1. Load and validate configuration.
|
|
56
|
+
2. Discover scenarios through the configured provider, then validate them.
|
|
57
|
+
3. Filter by include and exclude patterns (and, later, optional impact analysis).
|
|
58
|
+
4. Open one capture session; run scenarios with bounded concurrency, each in a fresh context.
|
|
59
|
+
5. For each scenario: capture, read the baseline, compare.
|
|
60
|
+
6. Record the outcome (`passed`, `regression`, `missing-baseline`, `error`) and write artifacts.
|
|
61
|
+
7. Compute obsolete baselines (a baseline with no scenario).
|
|
62
|
+
8. Write `results.json` and the HTML report.
|
|
63
|
+
9. Map the result to an exit code.
|
|
64
|
+
|
|
65
|
+
Exit codes: `0` passed, `1` visual failures, `2` execution errors (take precedence over `1`
|
|
66
|
+
because the run is incomplete), `3` configuration or usage error.
|
|
67
|
+
|
|
68
|
+
## Capture
|
|
69
|
+
|
|
70
|
+
Screenshots are always of the viewport, never the full page. Content larger than the viewport is
|
|
71
|
+
clipped, and the capture result reports this so it can be surfaced as a warning.
|
|
72
|
+
|
|
73
|
+
Determinism strategy (implemented in Phase 2): pinned Playwright and Chromium, fixed viewport and
|
|
74
|
+
device scale factor, fixed locale, timezone, colour scheme and reduced motion, waiting for
|
|
75
|
+
`document.fonts.ready` and the scenario's readiness selector, disabled animations and transitions,
|
|
76
|
+
and repeated capture until two consecutive screenshots are identical. Dynamic content is handled
|
|
77
|
+
by explicit configuration, never by hiding large areas.
|
|
78
|
+
|
|
79
|
+
## Comparison
|
|
80
|
+
|
|
81
|
+
- Pixelmatch with explicit semantics: `colorThreshold` (0 to 1) is the per-pixel perceptual
|
|
82
|
+
distance. The tolerance for a scenario is the larger of `maxDiffPixels` and `maxDiffRatio`
|
|
83
|
+
times the pixel count; more differing pixels than that fail the scenario. Anti-aliased pixels
|
|
84
|
+
are counted.
|
|
85
|
+
- A dimension mismatch is a failure, never a silent resize.
|
|
86
|
+
- Defaults (`colorThreshold: 0.1`, `maxDiffPixels: 0`) are validated in Phase 2 by a
|
|
87
|
+
repeated-capture determinism test.
|
|
88
|
+
|
|
89
|
+
## Baselines
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
.viewev/baselines/<environment-key>/<scenario-id>.png
|
|
93
|
+
.viewev/baselines/<environment-key>/<scenario-id>.json # sidecar metadata
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- The environment key is `<platform>-<browser>`, for example `linux-chromium`. Chromium renders
|
|
97
|
+
text differently on macOS, Linux and Windows, so a baseline is only compared with baselines of
|
|
98
|
+
the same key. Viewev runs on all three; which baselines a project commits is its choice. We
|
|
99
|
+
recommend committing only the Linux baselines produced in CI as the shared gate.
|
|
100
|
+
- One sidecar per image avoids merge conflicts. It records the scenario id, environment (browser
|
|
101
|
+
and automation versions, OS), viewport, device scale factor, screenshot size, a SHA-256 of the
|
|
102
|
+
PNG and any variant. `schemaVersion` is the metadata format version; history is Git's job.
|
|
103
|
+
- `viewev test` never writes baselines. `baseline create` writes only missing ones.
|
|
104
|
+
`baseline update` overwrites existing ones and requires a filter or `--all`. `baseline prune`
|
|
105
|
+
removes obsolete ones.
|
|
106
|
+
- A test can read approved baselines directly from a Git ref. The file store remains the writer;
|
|
107
|
+
branch lookup is a read-only baseline source, outside comparison. The target ref must already
|
|
108
|
+
be available in the local Git object database.
|
|
109
|
+
- Baselines are stored in plain Git. Git LFS is not used for now.
|
|
110
|
+
|
|
111
|
+
## Pull requests
|
|
112
|
+
|
|
113
|
+
CI compares the screenshot from the PR code against the baselines from the target branch. In
|
|
114
|
+
GitHub Actions, Viewev reads that branch from `GITHUB_BASE_REF`; other CI systems can pass
|
|
115
|
+
`--base-ref` or configure `baselines.baseRef`. The target ref must be fetched before the command
|
|
116
|
+
runs. Viewev never generates the approved baseline from the PR itself.
|
|
117
|
+
|
|
118
|
+
Intended visual changes travel as baseline changes in the PR (implemented; templates in
|
|
119
|
+
[ci.md](ci.md)). Run `viewev test --proposed-dir <PR baselines>`; Viewev reads approved baselines
|
|
120
|
+
from the target branch:
|
|
121
|
+
|
|
122
|
+
1. A scenario that fails against the target-branch baseline is checked against the baseline the
|
|
123
|
+
PR proposes, if the PR changes one.
|
|
124
|
+
2. If the actual screenshot matches the proposed baseline, the scenario gets a distinct status
|
|
125
|
+
("changed in this PR, baseline updated") that is shown prominently in the report and in the
|
|
126
|
+
GitHub job summary, so reviewers always see which UI changes the PR causes.
|
|
127
|
+
3. Approval is a reviewed and merged baseline change; CODEOWNERS on the baseline directory
|
|
128
|
+
ensures a human signs off.
|
|
129
|
+
4. If the actual screenshot matches neither baseline, the scenario is a regression.
|
|
130
|
+
|
|
131
|
+
Obsolete baselines fail the run by default (`baselines.failOnObsolete`). Deleting a baseline in
|
|
132
|
+
the PR is a proposed, reviewable change in the same way.
|
|
133
|
+
|
|
134
|
+
CI security: tests run on `pull_request` with read-only permissions and no secrets. Baseline
|
|
135
|
+
updates run in a separate workflow started by a maintainer, on trusted refs. `pull_request_target`
|
|
136
|
+
is never combined with a checkout of PR code.
|
|
137
|
+
|
|
138
|
+
## Variants
|
|
139
|
+
|
|
140
|
+
A variant is another way of rendering every story, such as a theme or a narrow viewport. The
|
|
141
|
+
config lists them; the Storybook adapter expands each story into one scenario per variant with
|
|
142
|
+
ids like `button--primary@g100`, passing Storybook globals through the story URL. The core
|
|
143
|
+
never knows what a variant means. Baseline sidecars record the variant, and without variants
|
|
144
|
+
nothing changes.
|
|
145
|
+
|
|
146
|
+
## Dependencies
|
|
147
|
+
|
|
148
|
+
| Dependency | Why |
|
|
149
|
+
| ------------------------------------------ | -------------------------------------------------- |
|
|
150
|
+
| `commander` | CLI parsing |
|
|
151
|
+
| `zod` | Validation of config, provider output and metadata |
|
|
152
|
+
| `playwright-core` (Phase 2, exact version) | Browser automation, behind `ScreenshotCapturer` |
|
|
153
|
+
| `pixelmatch`, `pngjs` (Phase 3) | Pixel comparison and PNG encode and decode |
|
|
154
|
+
|
|
155
|
+
Sharp is not used in v1: nothing in the MVP needs resizing.
|
|
156
|
+
|
|
157
|
+
## Phases
|
|
158
|
+
|
|
159
|
+
1. Foundation: tooling, domain types, configuration, CLI skeleton (done).
|
|
160
|
+
2. Scenario discovery and capture: Storybook provider, capturer interface, Playwright adapter
|
|
161
|
+
(done).
|
|
162
|
+
3. Comparison and baselines: Pixelmatch, baseline store, `test` and `baseline` commands (done).
|
|
163
|
+
4. Reporting and CLI polish: static HTML report, `report` and `doctor` commands (done).
|
|
164
|
+
5. CI and branch-aware baselines: GitHub Actions summary, PR baseline model, Git ref lookup and
|
|
165
|
+
optional impact analysis are implemented. The workflow templates still need validation in a
|
|
166
|
+
consumer repository. Carbon-specific integration is deferred; Storybook remains the generic
|
|
167
|
+
framework integration.
|
|
168
|
+
|
|
169
|
+
## Decision log
|
|
170
|
+
|
|
171
|
+
| Decision | Outcome |
|
|
172
|
+
| ------------------ | ------------------------------------------------------------------------------------- |
|
|
173
|
+
| PR approval model | Intended changes are reviewed baseline changes in the PR; UI changes are always shown |
|
|
174
|
+
| Platforms | macOS, Linux and Windows; baselines keyed by environment |
|
|
175
|
+
| Capture area | Viewport only |
|
|
176
|
+
| Sharp | Dropped from v1; `pngjs` instead |
|
|
177
|
+
| Variants | Implemented in the Storybook adapter and baseline metadata |
|
|
178
|
+
| Obsolete baselines | Fail by default |
|
|
179
|
+
| Git LFS | Not for now |
|
|
180
|
+
| Package manager | npm |
|
package/docs/ci.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Running Viewev in GitHub Actions
|
|
2
|
+
|
|
3
|
+
> These workflows are templates. They follow the design in
|
|
4
|
+
> [architecture.md](architecture.md) but have not yet been run in a real repository, so expect to
|
|
5
|
+
> adjust them when you first wire them up.
|
|
6
|
+
|
|
7
|
+
## How pull requests are judged
|
|
8
|
+
|
|
9
|
+
- **Approved baselines** are read directly from the target branch's Git tree. GitHub Actions sets
|
|
10
|
+
`GITHUB_BASE_REF`, which Viewev detects automatically. Other CI systems can pass `--base-ref` or
|
|
11
|
+
set `baselines.baseRef` in the config.
|
|
12
|
+
- **Proposed baselines** are the ones the pull request itself changes (`--proposed-dir`). A
|
|
13
|
+
scenario that differs from the approved baseline is reported as **changed** only if the new
|
|
14
|
+
screenshot matches the proposed baseline. Otherwise it is a **regression** and fails the run.
|
|
15
|
+
- Nothing is approved by CI. A visual change is approved when a person reviews the baseline
|
|
16
|
+
images in the pull request and merges it. Protect the baseline directory with CODEOWNERS.
|
|
17
|
+
|
|
18
|
+
## Baselines must come from one environment
|
|
19
|
+
|
|
20
|
+
Chromium renders text differently on macOS, Linux and Windows, so baselines are stored per
|
|
21
|
+
platform (`linux-chromium`, `darwin-chromium`, `win32-chromium`) and only compared with the same
|
|
22
|
+
platform. Commit only the **Linux** baselines, produced in CI, as the shared gate. Run CI in the
|
|
23
|
+
Playwright container whose version matches the `playwright-core` version Viewev pins (shown by
|
|
24
|
+
`viewev doctor`), so fonts and Chromium match from run to run.
|
|
25
|
+
|
|
26
|
+
macOS and Windows developers can keep local baselines for their own checks, but should not
|
|
27
|
+
commit them. Add this to `.gitignore`:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
.viewev/baselines/darwin-*
|
|
31
|
+
.viewev/baselines/win32-*
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Pull request workflow
|
|
35
|
+
|
|
36
|
+
`.github/workflows/visual.yml`
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
name: Visual tests
|
|
40
|
+
|
|
41
|
+
on: pull_request
|
|
42
|
+
|
|
43
|
+
permissions:
|
|
44
|
+
contents: read # untrusted code runs here: no write access, no secrets
|
|
45
|
+
|
|
46
|
+
jobs:
|
|
47
|
+
visual:
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
# The tag must match the playwright-core version that Viewev pins.
|
|
50
|
+
container: mcr.microsoft.com/playwright:v1.60.0-noble
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v4 # the pull request and target branch history
|
|
53
|
+
with:
|
|
54
|
+
fetch-depth: 0 # Viewev reads approved baselines from the target branch's Git tree
|
|
55
|
+
|
|
56
|
+
- uses: actions/setup-node@v4
|
|
57
|
+
with:
|
|
58
|
+
node-version-file: .nvmrc
|
|
59
|
+
cache: npm
|
|
60
|
+
- run: npm ci
|
|
61
|
+
- run: npm run build-storybook # your command that writes the static Storybook
|
|
62
|
+
|
|
63
|
+
- name: Visual tests
|
|
64
|
+
run: >
|
|
65
|
+
npx viewev test
|
|
66
|
+
--proposed-dir .viewev/baselines
|
|
67
|
+
|
|
68
|
+
- name: Propose baselines for any change
|
|
69
|
+
if: always()
|
|
70
|
+
run: |
|
|
71
|
+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
72
|
+
npx viewev baseline update --all
|
|
73
|
+
npx viewev baseline prune --yes
|
|
74
|
+
git add -A .viewev/baselines
|
|
75
|
+
git diff --cached --name-status -- .viewev/baselines > proposal.txt
|
|
76
|
+
tar -cf proposal.tar $(git diff --cached --name-only --diff-filter=AM -- .viewev/baselines) 2>/dev/null || true
|
|
77
|
+
|
|
78
|
+
- uses: actions/upload-artifact@v4
|
|
79
|
+
if: always()
|
|
80
|
+
with:
|
|
81
|
+
name: viewev-report
|
|
82
|
+
path: .viewev/report
|
|
83
|
+
|
|
84
|
+
- uses: actions/upload-artifact@v4
|
|
85
|
+
if: always()
|
|
86
|
+
with:
|
|
87
|
+
name: viewev-proposal
|
|
88
|
+
path: |
|
|
89
|
+
proposal.txt
|
|
90
|
+
proposal.tar
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The job summary on the run page lists regressions, changed scenarios, missing baselines and
|
|
94
|
+
errors (Viewev writes it to `GITHUB_STEP_SUMMARY` automatically). The full report is the
|
|
95
|
+
`viewev-report` artifact.
|
|
96
|
+
|
|
97
|
+
For a Yarn project, add Viewev with `yarn add --dev viewev@beta`, install dependencies in CI with
|
|
98
|
+
the lockfile-appropriate command (`yarn install --immutable` for modern Yarn or
|
|
99
|
+
`yarn install --frozen-lockfile` for Yarn Classic), and invoke the CLI with `yarn viewev`.
|
|
100
|
+
|
|
101
|
+
Pull requests from forks get a read-only token, so they can run the tests and upload artifacts
|
|
102
|
+
but cannot receive baseline commits; a maintainer applies the proposal manually.
|
|
103
|
+
|
|
104
|
+
## Proposing baselines automatically
|
|
105
|
+
|
|
106
|
+
The job above runs the pull request's own code, so it must never hold write access. It only
|
|
107
|
+
produces an artifact. A second workflow, running trusted code from the default branch, validates
|
|
108
|
+
that artifact and commits it to the pull request branch. It only acts when a maintainer has
|
|
109
|
+
added the `update-visual-baselines` label.
|
|
110
|
+
|
|
111
|
+
`.github/workflows/visual-baselines.yml`
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
name: Apply visual baseline proposal
|
|
115
|
+
|
|
116
|
+
on:
|
|
117
|
+
workflow_run:
|
|
118
|
+
workflows: ['Visual tests']
|
|
119
|
+
types: [completed]
|
|
120
|
+
|
|
121
|
+
permissions:
|
|
122
|
+
contents: write
|
|
123
|
+
pull-requests: read
|
|
124
|
+
actions: read
|
|
125
|
+
|
|
126
|
+
jobs:
|
|
127
|
+
apply:
|
|
128
|
+
# Same-repository branches only; fork branches cannot be pushed to.
|
|
129
|
+
if: >
|
|
130
|
+
github.event.workflow_run.event == 'pull_request' &&
|
|
131
|
+
github.event.workflow_run.head_repository.full_name == github.repository
|
|
132
|
+
runs-on: ubuntu-latest
|
|
133
|
+
steps:
|
|
134
|
+
- name: Check for the label
|
|
135
|
+
id: label
|
|
136
|
+
env:
|
|
137
|
+
GH_TOKEN: ${{ github.token }}
|
|
138
|
+
PR: ${{ github.event.workflow_run.pull_requests[0].number }}
|
|
139
|
+
run: |
|
|
140
|
+
labels=$(gh pr view "$PR" --repo "$GITHUB_REPOSITORY" --json labels --jq '.labels[].name')
|
|
141
|
+
if echo "$labels" | grep -qx 'update-visual-baselines'; then echo "apply=true" >> "$GITHUB_OUTPUT"; fi
|
|
142
|
+
|
|
143
|
+
- uses: actions/checkout@v4
|
|
144
|
+
if: steps.label.outputs.apply == 'true'
|
|
145
|
+
with:
|
|
146
|
+
ref: ${{ github.event.workflow_run.head_branch }}
|
|
147
|
+
|
|
148
|
+
- uses: actions/download-artifact@v4
|
|
149
|
+
if: steps.label.outputs.apply == 'true'
|
|
150
|
+
with:
|
|
151
|
+
name: viewev-proposal
|
|
152
|
+
path: proposal
|
|
153
|
+
run-id: ${{ github.event.workflow_run.id }}
|
|
154
|
+
github-token: ${{ github.token }}
|
|
155
|
+
|
|
156
|
+
- name: Validate and apply
|
|
157
|
+
if: steps.label.outputs.apply == 'true'
|
|
158
|
+
run: |
|
|
159
|
+
set -euo pipefail
|
|
160
|
+
pattern='^\.viewev/baselines/linux-chromium/[a-z0-9][a-z0-9._@-]*\.(png|json)$'
|
|
161
|
+
|
|
162
|
+
# Never trust the artifact: check every path before extracting anything.
|
|
163
|
+
if [ -s proposal/proposal.tar ]; then
|
|
164
|
+
tar -tf proposal/proposal.tar | while read -r path; do
|
|
165
|
+
echo "$path" | grep -Eq "$pattern" || { echo "Unexpected path: $path"; exit 1; }
|
|
166
|
+
done
|
|
167
|
+
tar -xf proposal/proposal.tar
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
# Deleted baselines are listed as "D<TAB>path" in proposal.txt.
|
|
171
|
+
awk -F'\t' '$1 == "D" { print $2 }' proposal/proposal.txt | while read -r path; do
|
|
172
|
+
echo "$path" | grep -Eq "$pattern" || { echo "Unexpected path: $path"; exit 1; }
|
|
173
|
+
rm -f -- "$path"
|
|
174
|
+
done
|
|
175
|
+
|
|
176
|
+
- name: Commit
|
|
177
|
+
if: steps.label.outputs.apply == 'true'
|
|
178
|
+
run: |
|
|
179
|
+
git config user.name "viewev[bot]"
|
|
180
|
+
git config user.email "viewev@users.noreply.github.com"
|
|
181
|
+
git add -A .viewev/baselines
|
|
182
|
+
git diff --cached --quiet || git commit -m "chore: update visual baselines"
|
|
183
|
+
git push
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The push triggers the pull request workflow again. This time the proposed baselines match the
|
|
187
|
+
screenshots, so the run reports the visual changes as **changed** instead of failing, and the
|
|
188
|
+
reviewers see the old and new images in the pull request.
|
|
189
|
+
|
|
190
|
+
Make sure the token that pushes is allowed to trigger workflows (a push made with the default
|
|
191
|
+
`GITHUB_TOKEN` does not start new workflow runs; use a GitHub App token or a fine-grained
|
|
192
|
+
personal access token if you want the check to refresh automatically).
|
|
193
|
+
|
|
194
|
+
## Require review of baseline changes
|
|
195
|
+
|
|
196
|
+
`.github/CODEOWNERS`
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
/.viewev/baselines/ @your-org/design-system-maintainers
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Turn on "Require review from Code Owners" for the target branch. Then a visual change can only
|
|
203
|
+
be merged after the owners approved the changed baseline images.
|
|
204
|
+
|
|
205
|
+
## Generating Linux baselines locally
|
|
206
|
+
|
|
207
|
+
On macOS or Windows you can produce the Linux baselines in the same container CI uses:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
docker run --rm -v "$PWD":/work -w /work mcr.microsoft.com/playwright:v1.60.0-noble \
|
|
211
|
+
npx viewev baseline update --all
|
|
212
|
+
```
|
package/docs/impact.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Optional impact analysis
|
|
2
|
+
|
|
3
|
+
`viewev test --changed` can run only the scenarios affected by changed files. Viewev does not
|
|
4
|
+
assume how source files relate to stories; each project supplies a small analysis module.
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
// viewev.config.mjs
|
|
8
|
+
export default {
|
|
9
|
+
provider: { type: 'storybook', staticDir: 'storybook-static' },
|
|
10
|
+
impact: {
|
|
11
|
+
module: './viewev-impact.mjs',
|
|
12
|
+
baseRef: 'origin/main',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The module's default export receives `changedFiles`, all discovered `scenarios`, `repoRoot`, and
|
|
18
|
+
`baseRef`. It returns either `{ mode: 'all', reason }` or
|
|
19
|
+
`{ mode: 'impact', scenarios: { [scenarioId]: ['reason'] } }`:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// viewev-impact.mjs
|
|
23
|
+
export default ({ changedFiles, scenarios }) => {
|
|
24
|
+
const changed = new Set(changedFiles);
|
|
25
|
+
const selected = {};
|
|
26
|
+
|
|
27
|
+
for (const scenario of scenarios) {
|
|
28
|
+
const source = scenario.origin.source?.replace(/^\.\//, '');
|
|
29
|
+
if (source !== undefined && changed.has(source)) {
|
|
30
|
+
selected[scenario.id] = [`source changed: ${source}`];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { mode: 'impact', scenarios: selected };
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run `viewev test --changed`; `--base <ref>` overrides `impact.baseRef`. Changed files are measured
|
|
39
|
+
from the Git merge base and include committed, staged, working-tree, and non-ignored untracked
|
|
40
|
+
changes. The target ref must be available locally. If Git cannot determine the changes or the
|
|
41
|
+
analysis module fails or returns invalid data, Viewev runs every filtered scenario and records
|
|
42
|
+
why it fell back. This favors a slower run over missing a possible regression.
|
|
43
|
+
|
|
44
|
+
Impact analysis only selects scenarios. It does not select approved baselines: baseline lookup
|
|
45
|
+
uses the target branch configured by `baselines.baseRef`, `--base-ref`, or the GitHub Actions pull
|
|
46
|
+
request environment.
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viewev",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Visual evaluation for the web. Open-source visual regression testing for web interfaces.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"viewev": "dist/cli/bin.js"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"docs",
|
|
24
|
+
"assets/logo/Logo-horizontal.png",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/viewev/viewev.git"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"prepack": "npm run build",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"format:check": "prettier --check .",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
41
|
+
"test:watch": "vitest"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"commander": "^12.1.0",
|
|
45
|
+
"pixelmatch": "^7.1.0",
|
|
46
|
+
"playwright-core": "1.60.0",
|
|
47
|
+
"pngjs": "^7.0.0",
|
|
48
|
+
"zod": "^3.23.8"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@eslint/js": "^9.12.0",
|
|
52
|
+
"@types/node": "^20.16.0",
|
|
53
|
+
"@types/pngjs": "^6.0.5",
|
|
54
|
+
"eslint": "^9.12.0",
|
|
55
|
+
"prettier": "^3.3.3",
|
|
56
|
+
"typescript": "^5.6.2",
|
|
57
|
+
"typescript-eslint": "^8.8.0",
|
|
58
|
+
"vitest": "^2.1.2"
|
|
59
|
+
}
|
|
60
|
+
}
|