visual-regression-ci 0.0.0-stage β 0.9.1
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 +953 -2
- package/package.json +76 -4
- package/src/ci/actionReport.js +340 -0
- package/src/ci/prComment.js +420 -0
- package/src/cli/capture.js +243 -0
- package/src/cli/compare.js +190 -0
- package/src/cli/config.js +287 -0
- package/src/cli/database.js +69 -0
- package/src/cli/display.js +119 -0
- package/src/cli/errors.js +17 -0
- package/src/cli/index.js +577 -0
- package/src/cli/installBrowsers.js +59 -0
- package/src/cli/invocation.js +66 -0
- package/src/cli/jsonTarget.js +100 -0
- package/src/cli/logger.js +15 -0
- package/src/cli/manifest.js +139 -0
- package/src/cli/naming.js +60 -0
- package/src/cli/reporter.js +172 -0
- package/src/cli/result.js +225 -0
- package/src/cli/serve.js +64 -0
- package/src/server/app.js +135 -0
- package/src/server/db.js +691 -0
- package/src/server/importRuns.js +839 -0
- package/src/server/paths.js +107 -0
- package/src/server/public/css/styles.css +2362 -0
- package/src/server/public/js/common.js +32 -0
- package/src/server/public/js/dashboard.js +140 -0
- package/src/server/public/js/import-upload.js +169 -0
- package/src/server/public/js/review-actions.js +379 -0
- package/src/server/public/js/shortcuts.js +242 -0
- package/src/server/public/js/slider.js +104 -0
- package/src/server/public/js/tabs.js +85 -0
- package/src/server/public/js/theme.js +83 -0
- package/src/server/routes/api.js +141 -0
- package/src/server/routes/views.js +68 -0
- package/src/server/security.js +79 -0
- package/src/server/uploadImport.js +227 -0
- package/src/server/urls.js +31 -0
- package/src/server/viewModels.js +366 -0
- package/src/server/views/history.ejs +111 -0
- package/src/server/views/index.ejs +283 -0
- package/src/server/views/layout.ejs +11 -0
- package/src/server/views/partials/footer.ejs +11 -0
- package/src/server/views/partials/header.ejs +93 -0
- package/src/server/views/run-detail.ejs +295 -0
- package/src/shared/packageSpec.js +49 -0
- package/src/shared/text.js +59 -0
package/README.md
CHANGED
|
@@ -1,3 +1,954 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Visual Regression Tool & CI πΈ
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An open-source, self-hosted visual regression testing engine and interactive review dashboard. An automated, zero-cost alternative to Chromatic and Percy designed for developers, local staging environments, and continuous integration pipelines. Monitors, detects, and tracks pixel-level regressions across HTML, CSS, and responsive viewports.
|
|
4
|
+
|
|
5
|
+
> **[Live demo](https://abhishek-k-33.github.io/Visual_Regression_Testing/)**: try the review dashboard in your browser, nothing to install. Open the failing `demo-05-regression` run, compare the screenshots side by side, with the slider and as a diff, then approve or reject it (approvals are simulated and reset on reload).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## π Key Highlights
|
|
10
|
+
|
|
11
|
+
- πΈ **Deterministic Multi-Viewport Capture**: Playwright-powered headless Chromium capture with automatic CSS transition/animation freezing, caret hiding, and dynamic DOM element masking.
|
|
12
|
+
- π **Pixel-Level Diffing & Dimension Normalization**: Powered by `pixelmatch` and `pngjs` with automatic canvas dimension padding (`PNG.bitblt`) to handle layout shifts without crashes.
|
|
13
|
+
- ποΈ **High-Performance SQLite Persistence**: Embedded SQLite storage (`better-sqlite3`) with Write-Ahead Logging (WAL) mode for fast, concurrent run tracking, Git commit/branch context, and snapshot history.
|
|
14
|
+
- π₯οΈ **Linear/Vercel-Inspired Review Dashboard**: Full-width developer dashboard (dark and light themes, phone-friendly layout, WCAG AA contrast) featuring real-time search, status filtering, pagination, Side-by-Side comparison, Draggable Split Sliders, and Diff Highlight visualizers.
|
|
15
|
+
- π **One-Click Baseline Promotion**: Promote approved visual regressions to new golden baselines on disk directly from the web interface.
|
|
16
|
+
- π₯ **Review CI Runs Locally**: drop the `visual-regression-diffs.zip` artifact on the dashboard (or run `visual-ci import visual-regression-diffs.zip`) to recreate a failed CI run (screenshots, diffs and the baselines CI compared against) locally, after validating every file in the artifact.
|
|
17
|
+
- π **Security Basics**: Baseline promotion restricted to PNGs inside `storage/runs/` β `storage/baselines/` (symlink-aware), `/storage` serves only screenshot PNGs, localhost-only binding by default, and parameterized SQL queries.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## π οΈ Architecture & Workflow
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
ββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββββββββββββββ
|
|
25
|
+
β β β β β β
|
|
26
|
+
β visual.config.json βββββββΊβ Playwright Capture βββββββΊβ Pixel Diffing Engine β
|
|
27
|
+
β (routes, viewports) β β (Deterministic Freeze) β β (Dimension Normalizer)β
|
|
28
|
+
ββββββββββββββββββββββββ βββββββββββββββββββββββββββ βββββββββββββ¬ββββββββββββ
|
|
29
|
+
β
|
|
30
|
+
ββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
|
|
31
|
+
β β β β βΌ
|
|
32
|
+
β Promote Baseline ββββββββ€ Web Review Dashboard βββββββ SQLite Persistence
|
|
33
|
+
β (Overwrites Master) β β (Slider, Side-by-Side) β (storage/data.sqlite)
|
|
34
|
+
ββββββββββββββββββββββββ βββββββββββββββββββββββββββ
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
1. **Capture:** Playwright launches headless Chromium, injects deterministic CSS rules to halt animations, masks volatile elements (e.g., ads, timestamps), and takes full-page screenshots across all configured viewports.
|
|
38
|
+
2. **Compare:** The engine loads the approved baseline image from `storage/baselines/`. If dimensions differ, it transparently pads the smaller image to match the larger bounding box, runs anti-aliasing-aware pixel diffing, highlights differing pixels in neon red, and computes the mismatch percentage.
|
|
39
|
+
3. **Persist:** Test runs, Git metadata (branch name and commit hash), mismatch metrics, and filepaths are stored in `storage/data.sqlite`.
|
|
40
|
+
4. **Review & Approve:** Developers open the review dashboard (`http://localhost:4000`), inspect diffs via the interactive split slider, and approve intentional changes with a single click.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## π» Tech Stack
|
|
45
|
+
|
|
46
|
+
| Component | Technology | Description |
|
|
47
|
+
| :--- | :--- | :--- |
|
|
48
|
+
| **Runtime** | Node.js (v22+ LTS) | Native ES modules (`"type": "module"`) |
|
|
49
|
+
| **Browser Engine** | Playwright (Chromium) | Multi-viewport deterministic rendering |
|
|
50
|
+
| **Diff Engine** | Pixelmatch & PNGjs | Pixel comparison, dimension normalization |
|
|
51
|
+
| **Backend Framework** | Express.js (v4) | RESTful API & static asset serving |
|
|
52
|
+
| **View Engine** | EJS (Embedded JavaScript) | Server-rendered responsive templates |
|
|
53
|
+
| **Database** | SQLite (`better-sqlite3`) | Embedded database with WAL concurrency |
|
|
54
|
+
| **CLI Framework** | Commander.js (v13) | Command-line interface and flags |
|
|
55
|
+
| **Test Suite** | Vitest (v3) | Unit and integration testing |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## π Directory Structure
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
Visual Regression Testing Project/
|
|
63
|
+
βββ package.json # The visual-ci npm package: bin, files allowlist (.js/.ejs/.css under src/), engines, scripts
|
|
64
|
+
βββ LICENSE # MIT
|
|
65
|
+
βββ RELEASING.md # Release checklist: npm (trusted publishing), the GHCR image, the GitHub release (not in the npm package)
|
|
66
|
+
βββ visual.config.json # Visual regression test specifications
|
|
67
|
+
βββ Dockerfile # Standardized Playwright + Ubuntu font container
|
|
68
|
+
βββ docker-compose.yml # Orchestration for dashboard & test runner
|
|
69
|
+
βββ .dockerignore # Docker build context exclusions
|
|
70
|
+
βββ action.yml # The GitHub Action (composite): runs visual-ci in the Docker image, uploads the run
|
|
71
|
+
βββ .github/ # GitHub automation
|
|
72
|
+
β βββ dependabot.yml # Weekly updates of the actions (and of release.yml's pinned SHAs)
|
|
73
|
+
β βββ workflows/
|
|
74
|
+
β βββ visual-ci.yml # GitHub Actions visual regression pipeline
|
|
75
|
+
β βββ action-selftest.yml # Proves the action's failure paths on a real runner (diff artifact imports; error uploads nothing)
|
|
76
|
+
β βββ release.yml # On a v* tag: tests, npm publish (trusted publishing), GHCR image, GitHub release, v0/v1 tag
|
|
77
|
+
β βββ pages.yml # Builds the static demo and deploys it to GitHub Pages
|
|
78
|
+
βββ docs/ # Detailed engineering milestone records
|
|
79
|
+
β βββ PHASE_1_EXECUTION.md # Foundation & Playwright Capture Engine
|
|
80
|
+
β βββ PHASE_2_EXECUTION.md # Pixel Diffing & Dimension Normalizer
|
|
81
|
+
β βββ PHASE_3_EXECUTION.md # SQLite Storage & Interactive Dashboard
|
|
82
|
+
β βββ PHASE_4_EXECUTION.md # Cross-Platform Docker Containerization
|
|
83
|
+
β βββ PHASE_5_EXECUTION.md # GitHub Actions CI & Markdown Reporting
|
|
84
|
+
βββ src/
|
|
85
|
+
β βββ cli/ # CLI commands and screenshot engine
|
|
86
|
+
β β βββ index.js # CLI entry point (`visual-ci capture`, `test`, `import`, `serve`, `install-browsers`)
|
|
87
|
+
β β βββ serve.js # `visual-ci serve` port/host options (flags > PORT/VISUAL_CI_HOST > 4000/127.0.0.1)
|
|
88
|
+
β β βββ installBrowsers.js # `visual-ci install-browsers`: runs our own Playwright's `install chromium`
|
|
89
|
+
β β βββ invocation.js # How to run visual-ci again, for hints (`npx -y visual-regression-ci@<version>` where it is not installed)
|
|
90
|
+
β β βββ database.js # loadDatabase(): db.js + a better-sqlite3 check, one clear error with the fix
|
|
91
|
+
β β βββ capture.js # Playwright multi-viewport capture engine
|
|
92
|
+
β β βββ compare.js # Pixel comparison and canvas dimension normalizer
|
|
93
|
+
β β βββ manifest.js # Writes run.json, the per-run record that travels with CI artifacts
|
|
94
|
+
β β βββ result.js # `test --json` result (schema visual-ci-result), exit codes, error codes
|
|
95
|
+
β β βββ errors.js # CliError: an error carrying a result error code
|
|
96
|
+
β β βββ display.js # redactUrl (credentials/tokens), display paths, host path redaction
|
|
97
|
+
β β βββ jsonTarget.js # --json target checks (never run.json/summary, even via links or case)
|
|
98
|
+
β β βββ logger.js # Human output; moves to stderr with `--json -`
|
|
99
|
+
β β βββ naming.js # Screenshot file names; rejects route/viewport pairs that would collide
|
|
100
|
+
β β βββ config.js # Config loader with comment-stripping parser
|
|
101
|
+
β β βββ reporter.js # Markdown report generator & GITHUB_STEP_SUMMARY
|
|
102
|
+
β βββ ci/
|
|
103
|
+
β β βββ actionReport.js # The action's result step: JSON result -> outputs, container -> runner paths, upload decision
|
|
104
|
+
β β βββ prComment.js # The action's pull request comment: render the result, update the bot's sticky comment
|
|
105
|
+
β βββ shared/
|
|
106
|
+
β β βββ text.js # No-dependency text helpers (sanitizeForDisplay, mdCode) for the CLI, the server and the action
|
|
107
|
+
β β βββ packageSpec.js # Printed npx commands pin the npm package: `visual-regression-ci@<version>`
|
|
108
|
+
β βββ server/ # Web review dashboard & REST API
|
|
109
|
+
β βββ app.js # Express server configuration; startServer({ port, host })
|
|
110
|
+
β βββ db.js # SQLite schema and queries
|
|
111
|
+
β βββ importRuns.js # Imports CI runs (artifact zip or folder) safely: validation, limits, id collisions
|
|
112
|
+
β βββ uploadImport.js # POST /api/imports: capped streaming upload, one import at a time, disk guard
|
|
113
|
+
β βββ paths.js # Storage root and PNG path allowlist checks
|
|
114
|
+
β βββ security.js # Host allowlist + CSRF checks for the unauthenticated dashboard
|
|
115
|
+
β βββ viewModels.js # Shapes DB rows into what the templates render (incl. /storage URLs)
|
|
116
|
+
β βββ urls.js # url()/pageLocals(): base-path handling so pages also work under a sub-path
|
|
117
|
+
β βββ routes/ # Express routers (`/api`, `/`)
|
|
118
|
+
β β βββ api.js # REST API for runs and snapshot approval
|
|
119
|
+
β β βββ views.js # HTML views: dashboard, run details, route history
|
|
120
|
+
β βββ views/ # EJS templates (Linear/Vercel style, dark + light themes)
|
|
121
|
+
β β βββ partials/ # Shared header (head, theme init script, navbar) and footer (scripts)
|
|
122
|
+
β β βββ index.ejs # Main dashboard table with KPI cards
|
|
123
|
+
β β βββ run-detail.ejs # Inspection studio (Slider, Side-by-Side, Diff)
|
|
124
|
+
β β βββ history.ejs # One route + viewport across runs (sparkline, thumbnails)
|
|
125
|
+
β β βββ layout.ejs # Error page
|
|
126
|
+
β βββ public/ # Static assets (CSS, client JS as ES modules)
|
|
127
|
+
β βββ css/styles.css # Stylesheet: colour tokens on :root (dark) + :root[data-theme="light"]
|
|
128
|
+
β βββ js/
|
|
129
|
+
β βββ common.js # Base path, API URL and screen-reader announce helpers
|
|
130
|
+
β βββ theme.js # Light/dark toggle (every page), remembers the choice
|
|
131
|
+
β βββ dashboard.js # Real-time search, filtering, and pagination
|
|
132
|
+
β βββ tabs.js # Snapshot view tabs (WAI-ARIA tabs pattern)
|
|
133
|
+
β βββ slider.js # Split slider (ARIA slider: keyboard + pointer events)
|
|
134
|
+
β βββ import-upload.js # "Import CI run" button and drag-and-drop upload (live dashboard only)
|
|
135
|
+
β βββ review-actions.js # Approve / Reject buttons and "Approve all pending"
|
|
136
|
+
β βββ shortcuts.js # Run page keyboard shortcuts (j/k/a/r/1-3/?) and help dialog
|
|
137
|
+
βββ scripts/
|
|
138
|
+
β βββ check-package.js # prepublishOnly: npm pack --dry-run must hold only the allowlist, nothing secret-looking
|
|
139
|
+
β βββ image-source-hash.sh # SHA-256 of the image's source files: the published image's label, checked by the action
|
|
140
|
+
β βββ image-info.sh # Digest + source-hash label of a published image, from the registry (no pull)
|
|
141
|
+
β βββ sync-readme-version.js # The "version" script: npm version also sets the versions README.md pins
|
|
142
|
+
β βββ demo-app.js # Static demo site (the visual CI target) with original/regressed/redesign variants
|
|
143
|
+
β βββ serve-demo.js # Serves the demo site on :4567 (npm run demo:serve; DEMO_VARIANT=regressed|redesign for a changed page)
|
|
144
|
+
β βββ demo.js # Interactive regression demo (npm run demo)
|
|
145
|
+
β βββ demo.config.json # Demo-only config (route /__vrt_demo), never touches committed baselines
|
|
146
|
+
β βββ build-static-demo.js # Builds the read-only GitHub Pages demo (npm run demo:pages)
|
|
147
|
+
β βββ pages-demo.config.json # Config for the Pages demo runs (temp storage only)
|
|
148
|
+
βββ storage/ # Local artifacts directory
|
|
149
|
+
β βββ baselines/ # Golden-master baselines (committed to git, reviewed in PRs)
|
|
150
|
+
β βββ runs/ # Per run: screenshots, diffs, compared-baseline copies and run.json (git-ignored)
|
|
151
|
+
β βββ data.sqlite # SQLite database file (git-ignored)
|
|
152
|
+
βββ tests/ # Vitest unit and integration test suites
|
|
153
|
+
βββ capture.test.js # Capture engine unit tests
|
|
154
|
+
βββ capture-integration.test.js# Deterministic capture integration tests
|
|
155
|
+
βββ cli-strict.test.js # CLI strict mode: missing baselines fail in CI
|
|
156
|
+
βββ cli-json.test.js # test --json and exit codes: errors, diffs, stdout mode, target guards, crashes
|
|
157
|
+
βββ result.test.js # Result builder, error classification, atomic JSON writer
|
|
158
|
+
βββ shared-text.test.js # src/shared/text.js: sanitiser, no imports, who imports it from where
|
|
159
|
+
βββ display.test.js # URL redaction, host path redaction, display paths
|
|
160
|
+
βββ json-target.test.js # --json target guard: symlinks, hard links, case folding, directories
|
|
161
|
+
βββ capture-errors.test.js # Fake Playwright: launch/navigation/mask/close errors are classified right
|
|
162
|
+
βββ demo-app.test.js # Demo site variants (original page stays byte-identical)
|
|
163
|
+
βββ build-static-demo.test.js # Static Pages build end to end: statuses, safety checks, links
|
|
164
|
+
βββ per-run-baselines.test.js # Per-run baseline copies, stale-approval conflicts, DB migration
|
|
165
|
+
βββ approve-all.test.js # Approve all pending: all-or-nothing batch, conflicts, rollback on failure
|
|
166
|
+
βββ approve-all-api.test.js # POST /api/runs/:id/approve-all, CSRF, and the run page button
|
|
167
|
+
βββ compare.test.js # Pixel comparison and padding tests
|
|
168
|
+
βββ config.test.js # Config validation and path traversal tests
|
|
169
|
+
βββ db.test.js # SQLite queries and path jail tests
|
|
170
|
+
βββ manifest.test.js # run.json written by the CLI for every test run
|
|
171
|
+
βββ import.test.js # visual-ci import: real CI run, malicious zips, manifest validation, approval, CLI
|
|
172
|
+
βββ upload-import.test.js # POST /api/imports: CSRF, 413/415/503/507, aborts, sanitised errors, responsiveness
|
|
173
|
+
βββ import-ui.test.js # Chromium: import by file picker and drag-and-drop, progress, errors, axe, static mode
|
|
174
|
+
βββ docker.test.js # Docker image tag matches the pinned Playwright version
|
|
175
|
+
βββ action.test.js # action.yml + workflows: structure, no expressions in scripts, steps run by their real if:, fake docker, end to end
|
|
176
|
+
βββ sync-readme-version.test.js # The version script: rewrites only pinned versions, covers every README pin
|
|
177
|
+
βββ release.test.js # release.yml: triggers, permissions, no tokens, dry run; guard/publish/tag steps run with fake npm and gh
|
|
178
|
+
βββ action-report.test.js # Action outputs from the JSON result: path mapping, upload modes, missing/invalid results
|
|
179
|
+
βββ pr-comment.test.js # PR comment: mdCode escaping, rendering and caps, sticky upsert (bot only), the step's run()
|
|
180
|
+
βββ server.test.js # Express REST API and dashboard view tests (incl. route history)
|
|
181
|
+
βββ serve.test.js # visual-ci serve / startServer: free port, -c storageDir, PORT, SIGINT/SIGTERM, exit 2 cases
|
|
182
|
+
βββ install-browsers.test.js # visual-ci install-browsers: our Playwright's CLI, exact argv (fake spawn), --dry-run, exit codes
|
|
183
|
+
βββ lazy-imports.test.js # Loader hook breaks better-sqlite3 (package or binary) or Playwright: what still works, test warns once, import/serve exit 2
|
|
184
|
+
βββ invocation.test.js # cliCommand() and packageSpec: the command hints show (pinned npx visual-regression-ci@<version> where it is not installed)
|
|
185
|
+
βββ package.test.js # npm pack --dry-run: what ships, stray files left out, check-package.js refuses them; package.json, LICENSE
|
|
186
|
+
βββ fixtures/broken-modules/ # node --import hook (VRT_BREAK): better-sqlite3 missing or without its binary, Playwright missing
|
|
187
|
+
βββ storage-dir.test.js # Custom storageDir honoured by CLI and dashboard
|
|
188
|
+
βββ urls.test.js # Base-path URL helpers
|
|
189
|
+
βββ viewModels.test.js # Template data shaping, /storage URL mapping, history model, snapshot counts
|
|
190
|
+
βββ theme-contrast.test.js # Parses styles.css: light theme covers every token, WCAG AA contrast per theme
|
|
191
|
+
βββ responsive-theme.test.js # Chromium: no sideways scroll at 360/375px in both themes, 44px tap targets, theme toggle
|
|
192
|
+
βββ helpers/ # Shared test helpers (CSS token/contrast math, seeded dashboard storage)
|
|
193
|
+
βββ reporter.test.js # Markdown reporter & CI step summary tests
|
|
194
|
+
βββ a11y-axe.test.js # axe-core scan of every page type in headless Chromium
|
|
195
|
+
βββ keyboard-ui.test.js # Keyboard & screen-reader behaviour: tabs, slider, shortcuts, skip link
|
|
196
|
+
βββ helpers/ui-fixture.js # Browser-test fixture: app on a free port, temp storage, generated PNGs
|
|
197
|
+
βββ helpers/zip.js # Tiny zip writer for tests (builds malicious archives on the fly)
|
|
198
|
+
βββ helpers/gha-expr.js # Evaluates the GitHub Actions expressions (if:, env:) the action uses, for step-by-step tests
|
|
199
|
+
βββ helpers/fake-run.js # Writes a valid CI run folder (images + run.json) without a browser
|
|
200
|
+
βββ verify-phase-1.js # Phase 1 deliverable verification script
|
|
201
|
+
βββ verify-phase-2.js # Phase 2 deliverable verification script
|
|
202
|
+
βββ verify-phase-3.js # Phase 3 deliverable verification script
|
|
203
|
+
βββ verify-phase-4.js # Phase 4 deliverable verification script
|
|
204
|
+
βββ verify-phase-5.js # Phase 5 deliverable verification script
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## π Getting Started
|
|
210
|
+
|
|
211
|
+
### Prerequisites
|
|
212
|
+
|
|
213
|
+
- **Node.js**: `v22.x` LTS or higher
|
|
214
|
+
- **npm**: `10.x` or higher
|
|
215
|
+
|
|
216
|
+
### Install as a package (in your own project)
|
|
217
|
+
|
|
218
|
+
visual-ci is a command-line tool you add to your project as a dev dependency. It needs **Node.js 22 or newer**. On npm the package is called **`visual-regression-ci`** (npm doesn't allow `visual-ci`: it is too close to an existing package); the command it installs is still `visual-ci`.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm i -D visual-regression-ci
|
|
222
|
+
npx visual-ci install-browsers # the Chromium build visual-ci's Playwright needs
|
|
223
|
+
npx visual-ci test -u http://localhost:3000 # with a visual.config.json in the project
|
|
224
|
+
npx visual-ci serve # review the results on http://localhost:4000
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
> **0.9.x is a pre-1.0 release.** It is complete and tested, but options and outputs may still change before 1.0.0. Pin the exact version (`npm i -D -E visual-regression-ci`) if you want no surprises.
|
|
228
|
+
|
|
229
|
+
`npx visual-ci ...` runs the copy installed in your project. In `package.json` scripts, plain `visual-ci ...` works too. Where visual-ci is **not** installed, use the exact version, e.g. `npx -y visual-regression-ci@0.9.1 import ...` (that is what the pull request comment and the CLI's hints print): a bare `npx visual-ci` there would download whatever version is the newest on npm.
|
|
230
|
+
|
|
231
|
+
**The run database needs better-sqlite3**, a native module with prebuilt binaries for Linux (glibc and musl), macOS and Windows on x64 and arm64. If it can't be loaded (another platform, or a broken install), `visual-ci test` still runs and keeps its exit code: it warns once that the run won't appear in the dashboard, and `run.json` and the `--json` result are written as usual. `serve` and `import` need the database and exit with `2`, saying how to fix it: reinstall on a supported platform, or build it from source with `npm run build-release` inside `node_modules/better-sqlite3` (needs Python, make and a C++ compiler). `capture`, `install-browsers`, `--help` and `--version` don't load it (nor Playwright, except `capture`).
|
|
232
|
+
|
|
233
|
+
**What the package contains:** only `.js`, `.ejs` and `.css` files under `src/`, plus `README.md` and `LICENSE` (the `files` allowlist). Before publishing, `prepublishOnly` runs `scripts/check-package.js`, which reads `npm pack --dry-run` and refuses anything else, anything that looks like a secret or a database (`.env*`, `*.sqlite*`, `*.pem`, `*.key`, `.npmrc`), and any file git does not track (`git ls-files`; `files` does not look at `.gitignore`). Run it yourself with `npm run check:package`.
|
|
234
|
+
|
|
235
|
+
### Installation (from a checkout of this repository)
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Clone the repository
|
|
239
|
+
git clone https://github.com/abhishek-k-33/Visual_Regression_Testing.git
|
|
240
|
+
cd Visual_Regression_Testing
|
|
241
|
+
|
|
242
|
+
# Install dependencies
|
|
243
|
+
npm install
|
|
244
|
+
|
|
245
|
+
# Install the Chromium build that this Playwright version needs
|
|
246
|
+
# (add --with-deps on Linux to also install its system libraries)
|
|
247
|
+
node src/cli/index.js install-browsers
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## βοΈ Configuration (`visual.config.json`)
|
|
253
|
+
|
|
254
|
+
Configure your target URL, routes, viewports, and masking rules in `visual.config.json`. The loader supports comments (`//` and `/* */`):
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"baseUrl": "http://127.0.0.1:4567",
|
|
259
|
+
"routes": [
|
|
260
|
+
"/",
|
|
261
|
+
"/pricing",
|
|
262
|
+
"/about"
|
|
263
|
+
],
|
|
264
|
+
"viewports": [
|
|
265
|
+
{
|
|
266
|
+
"name": "desktop",
|
|
267
|
+
"width": 1440,
|
|
268
|
+
"height": 900
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "mobile",
|
|
272
|
+
"width": 375,
|
|
273
|
+
"height": 812
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
"maskSelectors": [
|
|
277
|
+
".advertisement",
|
|
278
|
+
"[data-dynamic-timestamp]",
|
|
279
|
+
"#live-chat-widget"
|
|
280
|
+
],
|
|
281
|
+
"threshold": 0.01,
|
|
282
|
+
"storageDir": "./storage"
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Configuration Options
|
|
287
|
+
|
|
288
|
+
| Option | Type | Default | Description |
|
|
289
|
+
| :--- | :--- | :--- | :--- |
|
|
290
|
+
| `baseUrl` | `string` | *(Required)* | The base URL of the web application being tested. |
|
|
291
|
+
| `routes` | `string[]` | `["/"]` | Array of relative routes to capture. Each route/viewport pair must map to its own file name (e.g. `/a/b` and `/a_b` both become `a_b-<viewport>.png`), or the config is rejected. |
|
|
292
|
+
| `viewports` | `object[]` | Desktop & Mobile | Viewport dimensions (`name`, `width`, `height`). |
|
|
293
|
+
| `maskSelectors` | `string[]` | `[]` | Selectors whose elements are painted over with solid black boxes (`#000000`) in the screenshot, using Playwright's screenshot `mask`. CSS selectors work (Playwright selector syntax is also accepted); pseudo-elements such as `::after` are not supported, and an invalid entry fails the capture with an error naming it. |
|
|
294
|
+
| `threshold` | `number` | `0.01` | Maximum allowable pixel mismatch ratio (0.01 = 1.0%). |
|
|
295
|
+
| `storageDir` | `string` | `"./storage"` | Directory (inside the project) for baselines, runs and the SQLite DB. The CLI and the dashboard both use it; the dashboard reads it from `./visual.config.json`. `docker-compose.yml` mounts `./storage`, so update the volumes if you change it, and add `<storageDir>/runs/` to `.gitignore` (databases are already ignored). |
|
|
296
|
+
|
|
297
|
+
### Environment Variables
|
|
298
|
+
The app reads these from the environment (it does not load a `.env` file):
|
|
299
|
+
|
|
300
|
+
| Variable | Default | Used by | Description |
|
|
301
|
+
| :--- | :--- | :--- | :--- |
|
|
302
|
+
| `PORT` | `4000` | Dashboard | Port to listen on. |
|
|
303
|
+
| `HOST` | `127.0.0.1` | Dashboard (`npm start`, `node src/server/app.js`, Docker) | Interface to bind; `0.0.0.0` exposes it on your network (no authentication). `visual-ci serve` ignores it (tcsh and some other shells set `HOST` to the machine's name). |
|
|
304
|
+
| `VISUAL_CI_HOST` | `127.0.0.1` | `visual-ci serve` | Interface to bind when `--host` is not given. |
|
|
305
|
+
| `ALLOWED_HOSTS` | *(none)* | Dashboard | Comma-separated hostnames allowed in the `Host` header besides `localhost` and IP addresses. |
|
|
306
|
+
| `VISUAL_STORAGE_DIR` | *(unset)* | CLI & dashboard | Overrides `storageDir` for both (e.g. to point the dashboard at a config passed with `--config`). |
|
|
307
|
+
| `VISUAL_IMPORT_MAX_UPLOAD_BYTES` | `209715200` (200 MB) | Dashboard | Largest artifact zip the dashboard accepts for import (`POST /api/imports`). The CLI import has no upload cap. |
|
|
308
|
+
| `VISUAL_IMPORT_IDLE_TIMEOUT_MS` | `30000` (30 s) | Dashboard | An import upload that receives no data for this long is dropped (frees the one-import-at-a-time slot). |
|
|
309
|
+
| `DEMO_PORT` | `4567` | Demo site | Port for `npm run demo:serve` / `npm run demo`. |
|
|
310
|
+
| `CI` | *(unset)* | CLI | When `true`, `test` defaults to `--strict`. |
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## π CLI Commands
|
|
315
|
+
|
|
316
|
+
> **Changed in this version:** errors now exit with code **2** instead of 1. Exit code 1 means only "visual differences found" (or a missing baseline in strict mode), so CI scripts can tell a regression from a broken run. See [Exit codes](#exit-codes).
|
|
317
|
+
|
|
318
|
+
### 1. Run Automated Visual Regression Tests
|
|
319
|
+
Captures screenshots across all viewports, compares against golden baselines, records results in SQLite, and reports metrics. The repo is configured against the bundled demo site, so start it first (or point `baseUrl` at your own app):
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
npm run demo:serve # in another terminal
|
|
323
|
+
npm run test:visual
|
|
324
|
+
```
|
|
325
|
+
*Or using the CLI directly:*
|
|
326
|
+
```bash
|
|
327
|
+
node src/cli/index.js test
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### CLI Flags
|
|
331
|
+
- `-c, --config <path>`: Specify a custom configuration file path.
|
|
332
|
+
- `-r, --run-id <id>`: Assign a custom identifier to the test run (defaults to `run_<timestamp>`).
|
|
333
|
+
- `-u, --base-url <url>`: Override the `baseUrl` (useful for staging/preview environments).
|
|
334
|
+
- `-s, --summary-file <path>`: Custom file name or path for the markdown test report.
|
|
335
|
+
- `--update-baselines`: Automatically promote all current screenshots to golden master baselines.
|
|
336
|
+
- `--strict` / `--no-strict`: In strict mode a route with no baseline **fails** (`MISSING_BASELINE`) instead of adopting the current screenshot as its baseline. Strict is the default when `CI=true`, so CI can never pass by comparing a page to itself.
|
|
337
|
+
- `--json <file>`: Also write a machine-readable result to `<file>` (relative to the working directory; parent folders are created). It is written atomically (temp file + rename), and also when the run fails with an error or crashes. `--json -` writes the JSON to **stdout** and sends all human output, warnings included, to stderr, so `node src/cli/index.js test --json - | jq .status` works. Details:
|
|
338
|
+
- Through npm, use `npm run -s test:visual -- --json -`: without `-s` npm prints its own banner to stdout, ahead of the JSON.
|
|
339
|
+
- Through Docker Compose, use `docker compose run -T runner node src/cli/index.js test --json -`: with a TTY (the default) stderr is merged into stdout.
|
|
340
|
+
- The target must be a file name: a directory (`.`, `out/`) is refused, and so is the run's own `run.json` or markdown summary, however it is reached (a symlinked folder or `VISUAL_STORAGE_DIR`, a link to the file, or a different letter case on macOS/Windows).
|
|
341
|
+
- Once the target is accepted, any file already at that path is removed before the run starts, so a reused path never shows an older run's result. A refused target is never touched. Usage errors (unknown flag, missing value) are rejected before the command runs and leave the path alone, so always check the exit code before reading the file.
|
|
342
|
+
|
|
343
|
+
#### Exit codes
|
|
344
|
+
|
|
345
|
+
| Code | Meaning |
|
|
346
|
+
| :--- | :--- |
|
|
347
|
+
| `0` | Every snapshot matched (or got a new baseline: first run, `--update-baselines`). |
|
|
348
|
+
| `1` | Visual differences: at least one `DIFF`, or a `MISSING_BASELINE` in strict mode. |
|
|
349
|
+
| `2` | Error: config not found or invalid, a page that could not load, Playwright's browser not installed, an invalid argument or usage error (unknown flag, missing value), or a crash. Also used by `capture` and `import` when they fail. |
|
|
350
|
+
|
|
351
|
+
`--help` and `--version` exit `0`. A usage error is rejected before the command runs, so it writes no JSON file (and leaves an existing one alone): treat "exit 2" with a missing or older-than-the-run JSON as a usage error.
|
|
352
|
+
|
|
353
|
+
#### JSON result (`--json`)
|
|
354
|
+
|
|
355
|
+
Schema `visual-ci-result`, version `1`. Future versions only add fields; existing ones keep their name, type and meaning.
|
|
356
|
+
|
|
357
|
+
```json
|
|
358
|
+
{
|
|
359
|
+
"schema": "visual-ci-result",
|
|
360
|
+
"version": 1,
|
|
361
|
+
"tool": { "name": "visual-ci", "version": "0.9.1" },
|
|
362
|
+
"command": "test",
|
|
363
|
+
"status": "failed",
|
|
364
|
+
"exit_code": 1,
|
|
365
|
+
"error": null,
|
|
366
|
+
"run": {
|
|
367
|
+
"id": "run_1764000000000",
|
|
368
|
+
"mode": "compare",
|
|
369
|
+
"strict": true,
|
|
370
|
+
"base_url": "http://127.0.0.1:4567",
|
|
371
|
+
"branch": "main",
|
|
372
|
+
"commit_sha": "3f2cβ¦",
|
|
373
|
+
"created_at": "2026-11-25T10:00:00.000Z",
|
|
374
|
+
"duration_ms": 5321,
|
|
375
|
+
"threshold_percentage": 1,
|
|
376
|
+
"run_dir": "storage/runs/run_1764000000000",
|
|
377
|
+
"manifest": "storage/runs/run_1764000000000/run.json",
|
|
378
|
+
"summary": "storage/runs/run_1764000000000/summary.md"
|
|
379
|
+
},
|
|
380
|
+
"counts": { "total": 2, "passed": 1, "changed": 1, "missing_baseline": 0, "new_baseline": 0 },
|
|
381
|
+
"snapshots": [
|
|
382
|
+
{
|
|
383
|
+
"route": "/",
|
|
384
|
+
"viewport": "desktop",
|
|
385
|
+
"status": "DIFF",
|
|
386
|
+
"mismatch_percentage": 3.42,
|
|
387
|
+
"current": "storage/runs/run_1764000000000/index-desktop.png",
|
|
388
|
+
"baseline": "storage/baselines/index-desktop.png",
|
|
389
|
+
"baseline_snapshot": "storage/runs/run_1764000000000/baselines/index-desktop.png",
|
|
390
|
+
"diff": "storage/runs/run_1764000000000/index-desktop-diff.png"
|
|
391
|
+
}
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
- `status` is `passed` (exit 0), `failed` (exit 1) or `error` (exit 2); `exit_code` is the process exit code.
|
|
397
|
+
- `error` is `null`, or `{ "code", "message" }` with `code` one of `CONFIG_NOT_FOUND`, `CONFIG_INVALID` (including an invalid `maskSelectors` entry), `NAVIGATION_FAILED` (a page that could not load), `BROWSER_MISSING` (Chromium or its system libraries not installed: run `visual-ci install-browsers --with-deps`; the message gives the exact command for how you run visual-ci), `INVALID_ARGUMENT`, `INTERNAL` (anything else, including crashes). Messages are sanitised: control and bidi characters are escaped, the working directory is shown as `.` and the home directory as `~`.
|
|
398
|
+
- **No secrets:** `base_url` and every message (JSON and terminal) have URL credentials (`user:pass@`) removed and the values of token-like query parameters (`token`, `access_token`, `auth`, `key`, `apikey`, `api_key`, `password`, `secret`, `sig`, `signature`, any case) replaced by `***`.
|
|
399
|
+
- `run` is `null` when the run never started (e.g. the config could not be loaded). On a later error it holds what is known; `manifest` and `summary` are `null` when those files were not written.
|
|
400
|
+
- `mode` is `compare` or `update-baselines`. `threshold_percentage` and `mismatch_percentage` are percentages (`1` = 1%), rounded to 6 decimals.
|
|
401
|
+
- Snapshot `status` is `MATCH`, `DIFF`, `NEW_BASELINE` or `MISSING_BASELINE`.
|
|
402
|
+
- `baseline` is the **shared** baseline file in `baselines/` (for `MISSING_BASELINE`, where it is expected; the file does not exist). Approvals change it later, so it can differ from what this run compared against.
|
|
403
|
+
- `baseline_snapshot` is the **run's own copy** of the baseline it was compared against, inside the run folder, so it travels with the CI artifact (`storage/runs/`): use it to show "before" for a run, e.g. in a PR comment. For a new baseline it is the run's screenshot; `null` when there was no baseline.
|
|
404
|
+
- `diff` is `null` when no comparison was made.
|
|
405
|
+
- `counts`: `passed` = `MATCH`, `changed` = `DIFF`, `missing_baseline`, `new_baseline`, and `total`.
|
|
406
|
+
- **Paths** are relative to the working directory and use `/`, so they mean the same inside the Docker runner (workspace `/app`) and on the host checkout that mounts `storage/`. A path outside the working directory (e.g. `VISUAL_STORAGE_DIR=/tmp/vrt`) is given absolute.
|
|
407
|
+
|
|
408
|
+
### 2. Capture Screenshots Only
|
|
409
|
+
Capture deterministic full-page screenshots without diffing:
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
npm run capture
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### 3. Start the Web Review Dashboard
|
|
416
|
+
Launches the Express dashboard and REST API server:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
npx visual-ci serve # where visual-ci is installed (from a checkout: npm start, or node src/cli/index.js serve)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
*Access the dashboard at:* **[http://localhost:4000](http://localhost:4000)**
|
|
423
|
+
|
|
424
|
+
```text
|
|
425
|
+
visual-ci serve [options]
|
|
426
|
+
|
|
427
|
+
-p, --port <n> Port to listen on, 0 for any free port (default: $PORT, else 4000)
|
|
428
|
+
--host <host> Interface to listen on (default: $VISUAL_CI_HOST, else 127.0.0.1)
|
|
429
|
+
-c, --config <path> Config to read storageDir from (only storageDir is used), so the dashboard
|
|
430
|
+
shows the same storage as `test -c` / `import -c`; VISUAL_STORAGE_DIR still wins
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
It prints the URL once it is listening; **Ctrl+C** stops it cleanly (exit `0`). An invalid port, a port already in use or a missing `-c` file exits with `2`. `npm start` and `node src/server/app.js` still start the same server (with `PORT` and `HOST` from the environment). `visual-ci serve` reads `VISUAL_CI_HOST`, never the plain `HOST`: some shells (tcsh, for one) set `HOST` to the machine's name, which would quietly put the dashboard on the network. It warns whenever it listens on anything but loopback (`localhost`, `127.x.x.x`, `::1`).
|
|
434
|
+
|
|
435
|
+
The server listens on `127.0.0.1` only. To reach it from other machines, start it with `--host 0.0.0.0` (or `HOST=0.0.0.0 npm start` from a checkout). The dashboard has no authentication, so only do this on a trusted network. If you then open it through a hostname rather than an IP address, list that name in `ALLOWED_HOSTS` (see below).
|
|
436
|
+
|
|
437
|
+
#### Install the browser (`visual-ci install-browsers`)
|
|
438
|
+
|
|
439
|
+
```text
|
|
440
|
+
visual-ci install-browsers [--with-deps] [--dry-run]
|
|
441
|
+
|
|
442
|
+
--with-deps Also install the system libraries Chromium needs (Linux; runs the package
|
|
443
|
+
manager, with sudo when not root)
|
|
444
|
+
--dry-run Only print what would be installed, and where
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
It runs **visual-ci's own Playwright** (`install chromium`), so the browser is the build that the pinned Playwright version launches; `npx playwright install` could pick up a different Playwright (for example your project's own). Its output goes straight to the terminal; it exits `0` on success and `2` if the installer fails. When Chromium is missing, `test` and `capture` fail with `BROWSER_MISSING` and say which command to run.
|
|
448
|
+
|
|
449
|
+
**Cross-site protection.** Because the dashboard has no login, the server defends against other websites driving it through your browser:
|
|
450
|
+
|
|
451
|
+
- **CSRF:** `POST` requests to `/api` must carry an `X-Requested-With` header, and are refused if the browser reports a cross-site `Origin` or `Sec-Fetch-Site`. Scripts calling the API need to send the header, e.g. `curl -X POST -H 'X-Requested-With: cli' http://localhost:4000/api/snapshots/42/approve`.
|
|
452
|
+
- **DNS rebinding:** requests are only served when the `Host` header is `localhost` or an IP address. If you reach the dashboard through a hostname (e.g. `ci-box.internal` or a reverse proxy), list it: `ALLOWED_HOSTS=ci-box.internal npm start` (comma-separated).
|
|
453
|
+
- **Behind a reverse proxy:** the proxy must forward the browser's original `Host` header unchanged, including any port (e.g. nginx `proxy_set_header Host $http_host;`; Caddy and Traefik do this by default). Otherwise approve/reject is refused with *"Origin does not match Host"*, and rebinding protection for reads is weakened.
|
|
454
|
+
|
|
455
|
+
### 4. Run Inside Docker (Cross-OS Rendering Consistency)
|
|
456
|
+
To eliminate font and sub-pixel antialiasing differences across macOS, Windows, and Linux:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
# Build the standardized Playwright container
|
|
460
|
+
npm run docker:build
|
|
461
|
+
|
|
462
|
+
# Run visual regression tests inside the container
|
|
463
|
+
npm run docker:test
|
|
464
|
+
|
|
465
|
+
# Start the review dashboard inside the container
|
|
466
|
+
npm run docker:dashboard
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### 5. Managing Baselines
|
|
470
|
+
Approved baselines live in `storage/baselines/` and are **committed to git**. That keeps them in sync with the code on every branch, and GitHub shows the image diff when a PR changes one.
|
|
471
|
+
|
|
472
|
+
Create or update them **inside the Docker image**, the same environment CI uses, so fonts and anti-aliasing match pixel for pixel:
|
|
473
|
+
|
|
474
|
+
```bash
|
|
475
|
+
npm run demo:serve # or start your own app
|
|
476
|
+
npm run docker:update-baselines # writes storage/baselines/*.png
|
|
477
|
+
git add storage/baselines && git commit -m "test: update visual baselines"
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Baselines captured outside the container (or approved in the dashboard after a non-Docker run) may differ slightly from CI's rendering. `npm run demo` and the `verify-phase-*` scripts use their own `__vrt_*.png` baselines, which are git-ignored.
|
|
481
|
+
|
|
482
|
+
With rootful Docker on Linux, files the container writes into `storage/` are owned by root. Hand them back with `sudo chown -R "$(id -u):$(id -g)" storage` (not needed with Docker Desktop or rootless Podman).
|
|
483
|
+
|
|
484
|
+
### 6. Review a CI Run Locally (dashboard upload or `visual-ci import`)
|
|
485
|
+
When the visual check fails in GitHub Actions, review it in your own dashboard instead of unpacking images by hand:
|
|
486
|
+
|
|
487
|
+
1. Open the failed workflow run on GitHub and download the **`visual-regression-diffs`** artifact (bottom of the run's *Summary* page). You get `visual-regression-diffs.zip`.
|
|
488
|
+
2. Import it, from your checkout of the branch, in either of two ways:
|
|
489
|
+
- **In the dashboard** (`npx visual-ci serve` where visual-ci is installed, or `npm start` in a checkout, then [http://localhost:4000](http://localhost:4000)): click **Import CI run** and pick the zip, or drop the zip anywhere on the dashboard page. When it is done the dashboard opens the imported run (or lists them, if the artifact held several); errors are shown under the page heading.
|
|
490
|
+
- **On the command line:**
|
|
491
|
+
```bash
|
|
492
|
+
node src/cli/index.js import ~/Downloads/visual-regression-diffs.zip
|
|
493
|
+
# or, without a checkout or an install (visual-ci from npm, at the version that ran in CI):
|
|
494
|
+
npx -y visual-regression-ci@0.9.1 import ~/Downloads/visual-regression-diffs.zip
|
|
495
|
+
```
|
|
496
|
+
`-y` skips npx's "Ok to proceed?" question; the exact version (`@0.9.0`) makes npx run that release rather than whatever is newest (the first run downloads it and its dependencies). The pull request comment prints this command with the version the action used.
|
|
497
|
+
It prints each imported run with its dashboard link, e.g. `http://localhost:4000/runs/run_1732440000000` (using `PORT` if you set it), and the command that opens the dashboard, written for how you ran the import (`npx visual-ci serve` when visual-ci is installed in the project, the same `npx -y visual-regression-ci@<version>` command when run through npx, `node src/cli/index.js serve` in a checkout).
|
|
498
|
+
3. Imported runs carry an **Imported** badge on the dashboard and in the run header.
|
|
499
|
+
|
|
500
|
+
```text
|
|
501
|
+
visual-ci import <path> [options]
|
|
502
|
+
|
|
503
|
+
<path> The artifact .zip, a folder holding <run-id>/run.json (e.g. an unpacked
|
|
504
|
+
artifact), a single run folder, or its run.json
|
|
505
|
+
-c, --config <path> Config to read storageDir from (only storageDir is used; no baseUrl needed)
|
|
506
|
+
-r, --run-id <id> Local id for the run (only when importing a single run)
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
- **Where it goes:** the same storage folder the dashboard uses (`VISUAL_STORAGE_DIR`, else `storageDir` from the config, else `./storage`). Screenshots, diffs and the per-run baseline copies go to `runs/<id>/`; your shared `baselines/` folder is never written by an import.
|
|
510
|
+
- **Ids:** a run keeps its CI id. If that id is already used by a different local run (compared ignoring case, as macOS and Windows file systems do), it is imported as `<id>-imp2` (then `-imp3`, ...). Importing the same artifact again changes nothing and says *already imported*. `--run-id` picks the id yourself (it must be free).
|
|
511
|
+
- **Approving an imported run:** approval copies the CI screenshot into your local `baselines/`, then you commit it as usual. It only works while your local baseline is **exactly the one CI compared against** (CI's hash is kept from `run.json`). If it differs (your branch is behind or ahead of the commit CI tested, or the baseline was changed or approved since), the run page says *"Your local baseline differs from the one CI compared against, so approving would be refused"* and disables **Approve** for that snapshot (and **Approve all pending**); the API answers `409 Conflict`. Check out the commit CI tested (or update your branch) or re-run the tests locally, then review that result. Reject still works.
|
|
512
|
+
- **Only artifacts with `run.json`:** artifacts from before `run.json` existed can't be imported (*"no run.json found"*); re-run CI.
|
|
513
|
+
- **What is checked:** the archive is untrusted. Only `run.json` and `*.png` files are extracted, into a private staging folder inside the storage root that is removed afterwards. Absolute paths, `..`, backslashes, control or invisible formatting characters in names (e.g. terminal escape sequences, bidi overrides), symlinks and duplicate entries are refused or skipped; anything quoted from the archive in a message is escaped. When importing a folder, symlinks are never followed below the folder you name, and a folder or file swapped for a symlink or a pipe while it is being read is skipped; at most 2000 entries, 50 MB per image, 1 MB per `run.json` and 500 MB in total, counted while unpacking, not taken from the archive's headers. Every `run.json` is validated strictly (schema and version, run id, routes, viewports, statuses, numbers; no control or bidi characters in any string); file names are re-derived from each snapshot's route and viewport rather than trusted; every referenced image must be a real PNG (at most 16384 x 65536 pixels) whose SHA-256 matches the manifest, and the compared baseline's hash must be present. If any run in the input fails a check, nothing is imported.
|
|
514
|
+
- **Dashboard upload limits:** the zip may be at most **200 MB** (`VISUAL_IMPORT_MAX_UPLOAD_BYTES`; the page refuses a bigger file before sending it, and the server stops reading once the limit is passed). **One import at a time:** a second upload while one is running is refused with `503` and `Retry-After` (not queued); try again when the first has finished. **Idle timeout:** an upload that sends nothing for 30 s (`VISUAL_IMPORT_IDLE_TIMEOUT_MS`) is disconnected and its temp file removed, so a stalled client can't hold the one-import slot. **Disk guard:** an upload is refused with `507` when the storage folder's disk, or the disk of `runs/` (where the archive is unpacked, if it is a different one), has less than max(2 x the upload limit, 1 GB) free (skipped where the platform can't tell). Server-side failures answer `500` with only an error code; the details are in the dashboard's log. The command-line import has none of these limits besides the archive checks above.
|
|
515
|
+
- **Who can import:** anyone who can reach the dashboard can import runs, the same trust level as approving baselines (there is no login). Keep the default `HOST=127.0.0.1` unless you are on a trusted network; uploads get the same cross-site (CSRF) and DNS-rebinding protection as approvals (see *Cross-site protection* above).
|
|
516
|
+
- **The server stays responsive while importing:** each file's SHA-256 and PNG header are computed while it is unpacked, so validation never reads whole files synchronously, and the dashboard keeps answering other requests during an import.
|
|
517
|
+
- **Same code for both:** the work is done by `importRuns(source, { storageRoot, db, runId })` in `src/server/importRuns.js`, which reports failures with an HTTP-style `status` (`400` unreadable or unsafe input, `409` id taken, `413` too large, `422` no valid run).
|
|
518
|
+
- **Interrupted imports:** an upload is streamed to a hidden `.upload-*` file and the archive unpacked into a hidden `.import-*` folder in the storage root; both are removed afterwards whatever happens (also when the browser cancels the upload), and leftovers of a crashed process are cleaned up by the next import once they are an hour old. Hidden (dot-named) paths are never served under `/storage`.
|
|
519
|
+
|
|
520
|
+
### 7. Build the Static Demo (GitHub Pages)
|
|
521
|
+
Builds the read-only dashboard behind the [live demo](https://abhishek-k-33.github.io/Visual_Regression_Testing/) into `_site/` (git-ignored):
|
|
522
|
+
|
|
523
|
+
```bash
|
|
524
|
+
npm run demo:pages
|
|
525
|
+
# = node scripts/build-static-demo.js --out _site --base /Visual_Regression_Testing
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
It serves the bundled demo site, runs the real CLI five times in a throwaway temp storage folder (baseline, pass, an intentional redesign that gets approved, pass, and a regression left for review), then renders the dashboard, run and history pages (`history/<slug>/<viewport>.html` for every route and viewport) with the same templates in *static* mode: a demo banner is shown and Approve/Reject only update the page. Only the screenshots the pages show are copied; the build fails if the output would contain a database, `run.json`, Markdown summaries or a broken link. `--base` is the sub-path the site is served under (`/` for a domain root); `--repo-url` sets the banner's GitHub link. Your own `storage/` is never read or changed.
|
|
529
|
+
|
|
530
|
+
---
|
|
531
|
+
|
|
532
|
+
## π₯οΈ Web Review Dashboard
|
|
533
|
+
|
|
534
|
+
The dashboard provides a **Linear/Vercel-inspired developer interface**:
|
|
535
|
+
|
|
536
|
+
### Main Dashboard (`GET /`)
|
|
537
|
+
- **Three KPI Statistics Cards**:
|
|
538
|
+
- **Total Runs**: Displays overall test executions with blue gradient and play icon.
|
|
539
|
+
- **Passed / Approved**: Shows successful runs with emerald green gradient and check icon.
|
|
540
|
+
- **Visual Regressions**: Highlights failing runs with coral red gradient and alert icon.
|
|
541
|
+
- **Import CI run**: button (and drop target for the whole page) that uploads a CI artifact zip; see [Review a CI Run Locally](#6-review-a-ci-run-locally-dashboard-upload-or-visual-ci-import). Not shown in the read-only static demo.
|
|
542
|
+
- **Real-Time Toolbar**: Client-side filter toggle buttons (`All`, `Passed`, `Approved`, `Regressions`) and quick search input.
|
|
543
|
+
- **Test Runs Table**: Displays status pills, cyan monospace Run IDs, Git context badges (`πΏ branch`, `#commit`; long branch names are truncated, full name on hover), snapshot counts per status (only the ones present: diff, rejected, new baseline, approved, match), creation times (UTC), and prominent **Inspect** buttons.
|
|
544
|
+
- **Pagination**: Minimal footer with item range indicator and navigation controls.
|
|
545
|
+
|
|
546
|
+
### Run Detail Studio (`GET /runs/:id`)
|
|
547
|
+
An unknown run id returns the error page with status `404`. For every route and viewport, three interactive visual tabs are available:
|
|
548
|
+
1. **Side-by-Side View**: Compares the baseline *as it was when the run happened* with the current execution in aligned frames. Each run keeps a copy of the baseline it compared against in `runs/<id>/baselines/`, so later approvals don't change what an old run shows. (Runs recorded before this was added show the current baseline instead.)
|
|
549
|
+
2. **Interactive Overlay Slider**: Draggable vertical divider (mouse, pen and touch via Pointer Events) to wipe between before and after images in real time. It is also a keyboard slider (see below).
|
|
550
|
+
3. **Diff Highlight View**: Full-resolution image canvas with differing pixels painted in bright neon red alongside exact mismatch percentages.
|
|
551
|
+
4. **One-Click Baseline Promotion**: Clicking **"Approve & Update Baseline"** copies the current screenshot over the baseline file on disk and transitions the status to `APPROVED`. If the baseline has changed since the run (e.g. a newer run was approved first), approval is refused with `409 Conflict` rather than silently reverting the newer baseline; re-run the tests and review the fresh result. Approving is still allowed when the baseline already equals the run's screenshot. Runs recorded before this check existed are not protected.
|
|
552
|
+
5. **Imported runs** (`visual-ci import`): marked **Imported** (with the import time in the header). For each snapshot awaiting review, the page checks whether your local baseline is still the one CI compared against; if not, it shows a notice and disables Approve (and Approve all pending), since approval would be refused with `409`.
|
|
553
|
+
6. **Approve all pending**: when a run has snapshots awaiting review (`DIFF` or `MISSING_BASELINE`), the run header shows **"Approve all pending (N)"**. After a confirmation it approves them all at once, **all or nothing**: every snapshot is checked first, and if any baseline has changed since the run, nothing is approved and the conflicting route/viewport pairs are listed. If a baseline changes while the batch is running, or copying a file or saving to the database fails part-way, every baseline already replaced is put back (old baselines are kept as hidden backups until the batch succeeds; if one can't be restored, the error says which and where its backup is). Approved and rejected snapshots are left as they are. In the static demo it is simulated like the single buttons.
|
|
554
|
+
|
|
555
|
+
**REST API** (writes need the `X-Requested-With` header, see *Cross-site protection* above):
|
|
556
|
+
|
|
557
|
+
| Method & path | Does |
|
|
558
|
+
| :--- | :--- |
|
|
559
|
+
| `GET /api/runs` | Lists runs with snapshot counts |
|
|
560
|
+
| `GET /api/runs/:id` | One run and its snapshots |
|
|
561
|
+
| `POST /api/snapshots/:id/approve` | Promotes one screenshot to the baseline (`409` if the baseline changed since the run) |
|
|
562
|
+
| `POST /api/snapshots/:id/reject` | Marks one snapshot rejected |
|
|
563
|
+
| `POST /api/imports` | Imports a CI artifact: the raw zip as the body (`Content-Type: application/zip`, `application/x-zip-compressed` or `application/octet-stream`, no multipart). `201 { success, runs: [{ id, url, status, snapshots, renamedFrom?, alreadyImported? }] }`, or `200` when every run was already imported; errors `{ success: false, error }` with `400`/`422` (unreadable or invalid artifact), `413` (over the upload limit or an archive limit), `415` (wrong content type), `503` + `Retry-After` (another import is running), `507` (low disk space), `500` (server-side failure; generic message, details in the log). Example: `curl -X POST -H 'X-Requested-With: cli' -H 'Content-Type: application/zip' --data-binary @visual-regression-diffs.zip http://localhost:4000/api/imports` |
|
|
564
|
+
| `POST /api/runs/:id/approve-all` | Approves every pending snapshot of the run, all or nothing: `200 { success, approved: [ids], runStatus, snapshots }` (`approved: []` when nothing is pending), `409 { success: false, error, conflicts: [{ id, route, viewport }] }`, `404` for an unknown run |
|
|
565
|
+
|
|
566
|
+
Each snapshot card links to the **History** of its route and viewport (see below), and has an `id="snapshot-<id>"` anchor that the history page links to.
|
|
567
|
+
|
|
568
|
+
### Themes (light / dark)
|
|
569
|
+
- **How the theme is picked**: an inline script in `<head>` (before the stylesheet, so there is no flash of the wrong theme) sets `<html data-theme="light|dark">`. A choice you made with the toggle wins; otherwise it follows the system setting (`prefers-color-scheme`), and keeps following live system changes until you pick one. Without JavaScript the dashboard stays dark.
|
|
570
|
+
- **Toggle**: the sun/moon button in the navbar (`aria-pressed="true"` means dark is on). It stores your choice in `localStorage` under the key **`vrt-theme`** (`"light"` or `"dark"`); clear that key to go back to following the system. Other open tabs follow the change. Works the same in the static GitHub Pages demo, under its sub-path.
|
|
571
|
+
- **Colours** are custom properties: `:root` holds the dark palette, `:root[data-theme="light"]` overrides every colour token. Screenshots and diff images are never recoloured. `tests/theme-contrast.test.js` checks that the key text/background pairs (text on every surface, links, status pills, buttons, KPI cards, demo banner) meet WCAG AA (4.5:1 text, 3:1 large text and control borders) in both themes.
|
|
572
|
+
|
|
573
|
+
### Phones (680px and narrower)
|
|
574
|
+
- The runs table and the history table become stacked cards with a label per field; long run ids and branch names are cut with an ellipsis.
|
|
575
|
+
- Filter tabs form a 2x2 grid and the search box takes the full width.
|
|
576
|
+
- On run pages, Approve / Reject (and Approve all pending) stack full width with tap targets at least 44px tall, baseline and current screenshots stack, and the slider handle is bigger (dragging it no longer scrolls the page).
|
|
577
|
+
- `tests/responsive-theme.test.js` checks in headless Chromium that the dashboard, a run with diffs, a history page and the error page never scroll sideways at 360px and 375px in either theme, including inside their tables (which become cards on phones). On tablets (681β1200px) wide tables may scroll inside their own box, but the page itself never does.
|
|
578
|
+
|
|
579
|
+
### Route History (`GET /history/:slug/:viewport`)
|
|
580
|
+
How one route has looked at one viewport over time, e.g. `/history/index/desktop` for `/` on desktop. The slug is the same one the route's baseline file uses (`index-desktop.png`), so route spellings that share a baseline (such as `/a/b` and `/a_b`) share a history. Viewport names must match `[A-Za-z0-9_-]{1,64}`; unknown or invalid ones return a `404` page.
|
|
581
|
+
- **Header**: route, viewport and a link to the current shared baseline image (when one exists).
|
|
582
|
+
- **Sparkline**: server-rendered inline SVG of the mismatch percentage, oldest to newest, with min / max / latest (also in its `aria-label`). No chart library.
|
|
583
|
+
- **One row per run** (latest 100, newest first; a card per run on phones, thumbnail on top): link to that run's snapshot card, time (UTC), branch and commit, status pill, mismatch %, and a lazy-loaded thumbnail of the screenshot.
|
|
584
|
+
- **Baseline changed marker**: shown on a run that was compared against a different baseline than the run before it (e.g. the first run after an approval), and as a dashed line on the sparkline. Runs recorded before baseline hashes existed are not marked.
|
|
585
|
+
|
|
586
|
+
### Accessibility & Keyboard Shortcuts
|
|
587
|
+
The dashboard can be used with the keyboard alone and with a screen reader:
|
|
588
|
+
- **Skip link**: the first <kbd>Tab</kbd> on every page shows *Skip to main content*, which jumps to the page's `<main id="main">` landmark. Every focusable element shows a visible focus ring (`:focus-visible`).
|
|
589
|
+
- **Comparison tabs** follow the WAI-ARIA tabs pattern: only the selected tab is in the Tab order; <kbd>β</kbd>/<kbd>β</kbd> move between tabs (wrapping), <kbd>Home</kbd>/<kbd>End</kbd> jump to the first/last, and the inactive panels are `hidden`.
|
|
590
|
+
- **Comparison slider** is a `role="slider"` named after the route and viewport, with values like *40% current, 60% baseline*: <kbd>β</kbd>/<kbd>β</kbd> (and <kbd>β</kbd>/<kbd>β</kbd>) Β±5, <kbd>Page Down</kbd>/<kbd>Page Up</kbd> Β±20, <kbd>Home</kbd> 0, <kbd>End</kbd> 100.
|
|
591
|
+
- **Screen readers**: screenshots have alt text naming the route, viewport and image (baseline, current or diff); decorative icons are hidden; dashboard filters are `aria-pressed` toggle buttons and the search box has a label. Approve/reject results are announced through a polite live region; errors appear next to the snapshot (or the run header) in a `role="alert"` region instead of a blocking `alert()`. Screenshot frames that scroll (tall pages) can be focused and scrolled from the keyboard.
|
|
592
|
+
|
|
593
|
+
**Run page shortcuts** (press <kbd>?</kbd> or the *Press ? for keyboard shortcuts* button in the run header for the help dialog):
|
|
594
|
+
|
|
595
|
+
| Key | Does |
|
|
596
|
+
| :--- | :--- |
|
|
597
|
+
| <kbd>j</kbd> / <kbd>k</kbd> | Next / previous snapshot card. The first <kbd>j</kbd> goes to the first card still awaiting review; after that every card in page order. The current card is outlined and focused. |
|
|
598
|
+
| <kbd>a</kbd> | Approve the current snapshot (same as its **Approve & Update Baseline** button) |
|
|
599
|
+
| <kbd>r</kbd> | Reject the current snapshot (same as its **Reject** button, including the confirmation) |
|
|
600
|
+
| <kbd>1</kbd> <kbd>2</kbd> <kbd>3</kbd> | Side-by-side, slider or diff view of the current snapshot |
|
|
601
|
+
| <kbd>?</kbd> | Open the shortcuts help; <kbd>Esc</kbd> closes it |
|
|
602
|
+
|
|
603
|
+
Clicking or tabbing into a card also makes it the current one. Shortcuts are ignored while you type in a field, with <kbd>Ctrl</kbd>/<kbd>Alt</kbd>/<kbd>Cmd</kbd> held, on key repeat and while a dialog is open. There is deliberately no shortcut for *Approve all pending*. Single-key shortcuts can conflict with screen readers and speech input (WCAG 2.1.4), so the help dialog has a switch to turn them off; the choice is saved in the browser's `localStorage` (if storage is blocked, the switch still works until reload). They work the same in the static demo, where approvals are simulated.
|
|
604
|
+
|
|
605
|
+
`tests/a11y-axe.test.js` runs [axe-core](https://github.com/dequelabs/axe-core) on the dashboard, a run page (also with the slider and the help dialog open), an imported run with stale-baseline notices, a history page and the error page, and fails on any *serious* or *critical* violation, with every rule enabled (including `color-contrast`) in both the dark and light themes.
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## π§© Use it in your repo (GitHub Action)
|
|
610
|
+
|
|
611
|
+
The repository is also a GitHub Action (`action.yml`). It runs `visual-ci test` against an app your job has already started, inside this project's Docker image (the same fonts and rendering as your committed baselines), writes the step summary, and uploads the run's screenshots and diffs as an artifact you can import into the dashboard. On pull requests it keeps one comment with the result up to date (see [Pull request comment](#pull-request-comment)).
|
|
612
|
+
|
|
613
|
+
```yaml
|
|
614
|
+
- uses: actions/checkout@v4
|
|
615
|
+
- run: npm ci
|
|
616
|
+
- run: npm start & # start your app in the background
|
|
617
|
+
- uses: abhishek-k-33/Visual_Regression_Testing@v0
|
|
618
|
+
with:
|
|
619
|
+
base-url: http://127.0.0.1:3000
|
|
620
|
+
wait-on: http://127.0.0.1:3000/
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
> **Which version:** `@v0` is the newest 0.x release (it moves with each release: 0.9.0, 0.9.1, ...). `@v1` comes with version 1.0.0; until then use `@v0`. A full commit SHA (`@<40-character sha>`) pins the action's own code; an exact tag (`abhishek-k-33/Visual_Regression_Testing@v0.9.1`) pins it as long as nobody moves the tag. Neither pins the Docker image the action pulls: a tag in the registry can be pointed at another image. That is why the action checks the image before it runs it (see below), and why `image: build` exists, which always builds the image from the pinned code instead. `@main` runs the newest, unreleased code.
|
|
624
|
+
>
|
|
625
|
+
> **Faster from a release:** used as `@v0` (or an exact tag), the action pulls the published image `ghcr.io/abhishek-k-33/visual-ci:<version>` instead of building it, which saves about 45 s per job. It takes the image only if (1) it was built from exactly the same files as the action (a source hash in the image's label), so `@main` or a commit after a release builds its own image, as does `uses: ./` in this repository, and (2) its **build provenance attestation** verifies: `gh attestation verify` must show that this repository's `release.yml` built it from the tag `v<version>`. It then pulls and runs that exact digest (`ghcr.io/abhishek-k-33/visual-ci@sha256:...`), so the image checked is the image run. If any check fails (or `gh` is missing), it builds, and a notice says why. `image: build` always builds.
|
|
626
|
+
>
|
|
627
|
+
> **Built images can render slightly differently.** The Dockerfile pins the Playwright base image (`mcr.microsoft.com/playwright:v1.64.1-noble`), but its font packages (`fonts-noto-color-emoji`, `fonts-liberation`, ...) are whatever Ubuntu's archive has on the day of the build. Their versions are not pinned on purpose: Ubuntu removes superseded versions from its update archive, so a pinned version would make the build fail later. So an image built today (the fallback, `image: build`, `uses: ./`) can differ by a few anti-aliased pixels from the published image of the same version. Create your baselines with the same image your checks use: the published image when the action uses it, or the same build (see [Baselines](#baselines-in-your-repo)).
|
|
628
|
+
|
|
629
|
+
Your repository needs a `visual.config.json` (routes, viewports, threshold; see *Configuration* above) and committed baselines in `storage/baselines/` (see [Baselines](#baselines-in-your-repo) below). A complete workflow:
|
|
630
|
+
|
|
631
|
+
```yaml
|
|
632
|
+
name: Visual regression
|
|
633
|
+
on: [pull_request]
|
|
634
|
+
permissions:
|
|
635
|
+
contents: read # the artifact upload needs no token permission
|
|
636
|
+
pull-requests: write # the pull request comment (with comment: false, contents: read is enough)
|
|
637
|
+
jobs:
|
|
638
|
+
visual:
|
|
639
|
+
runs-on: ubuntu-latest # Linux only
|
|
640
|
+
steps:
|
|
641
|
+
- uses: actions/checkout@v4
|
|
642
|
+
with:
|
|
643
|
+
persist-credentials: false # the workspace is mounted into the browser container
|
|
644
|
+
- uses: actions/setup-node@v4
|
|
645
|
+
with:
|
|
646
|
+
node-version: 22
|
|
647
|
+
- run: npm ci && npm run build
|
|
648
|
+
- run: npm start > app.log 2>&1 &
|
|
649
|
+
- id: visual
|
|
650
|
+
uses: abhishek-k-33/Visual_Regression_Testing@v0
|
|
651
|
+
with:
|
|
652
|
+
base-url: http://127.0.0.1:3000
|
|
653
|
+
wait-on: http://127.0.0.1:3000/
|
|
654
|
+
- if: always()
|
|
655
|
+
run: echo "visual-ci: $STATUS, $CHANGED changed, artifact $URL"
|
|
656
|
+
env:
|
|
657
|
+
STATUS: ${{ steps.visual.outputs.status }}
|
|
658
|
+
CHANGED: ${{ steps.visual.outputs.changed }}
|
|
659
|
+
URL: ${{ steps.visual.outputs.artifact-url }}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
### Inputs
|
|
663
|
+
|
|
664
|
+
| Input | Default | Description |
|
|
665
|
+
| :--- | :--- | :--- |
|
|
666
|
+
| `base-url` | *(required)* | URL of the app to test (`http://` or `https://`). Overrides `baseUrl` in the config. If it contains credentials or a token, pass it from a secret (`${{ secrets.PREVIEW_URL }}`): see below. |
|
|
667
|
+
| `config` | `visual.config.json` | Config file, relative to `working-directory` and inside it (no `..`). |
|
|
668
|
+
| `working-directory` | `.` | Folder (relative to the repository root, no `..`) to run in. Holds the config, and `storage/` unless the config sets `storageDir`. |
|
|
669
|
+
| `strict` | `true` | `true`: a route with no baseline fails the check (`MISSING_BASELINE`). `false`: it gets a new baseline from this run. |
|
|
670
|
+
| `update-baselines` | `false` | `true`: replace every baseline with this run's screenshots; the check passes. See [Baselines](#baselines-in-your-repo). |
|
|
671
|
+
| `run-id` | `gh-<run_id>-<run_attempt>` | Run id: letters, digits, `-` and `_`, at most 128. Set a different one for each use when the action runs more than once in a job. |
|
|
672
|
+
| `wait-on` | *(none)* | `http(s)` URL to poll (every second, 5 s per try) until it answers with a 2xx/3xx status, before testing. |
|
|
673
|
+
| `wait-timeout` | `60` | Seconds to wait for `wait-on` before failing (whole number). |
|
|
674
|
+
| `artifact-name` | `visual-regression-diffs` | Artifact name. Must be **unique within the workflow run**, or the upload (and the job) fails, even on a pass: in a matrix, or when the action runs more than once in a job, give each use its own name (e.g. `visual-diffs-${{ matrix.os }}`) and `run-id`. |
|
|
675
|
+
| `upload-artifact` | `on-failure` | When to upload the run folder: `on-failure`, `always` or `never` (see below). An empty folder is never uploaded. |
|
|
676
|
+
| `retention-days` | *(repository default)* | Days to keep the artifact, 1-90. |
|
|
677
|
+
| `image` | *(published or built)* | `build`: always build the action's own `Dockerfile`. An image reference: `docker pull` it and use it (it must contain this tool at `/app`, at the same version as the action; if it can't be pulled, the step fails). Empty: use the published `ghcr.io/abhishek-k-33/visual-ci:<version>` when it was built from the same files as the action and its attestation verifies, and otherwise (and always with `uses: ./`) build (see *What it does*). |
|
|
678
|
+
| `comment` | `true` | `true`: on `pull_request` events (only those), keep one comment with the result on the pull request (needs `pull-requests: write`, see [Pull request comment](#pull-request-comment)). `false`: never comment. |
|
|
679
|
+
| `comment-id` | `default` | Which comment this use of the action owns: letters, digits, `.`, `_` and `-`, at most 64. Give each use its own (e.g. `${{ matrix.browser }}`) for one comment per use; uses with the same id overwrite each other's comment. |
|
|
680
|
+
| `github-token` | `${{ github.token }}` | Token for the comment. Keep the default: the comment is then written by `github-actions[bot]`, and only comments by `github-actions[bot]` are ever updated. With a personal access token or a GitHub App token (another author) every run adds a new comment (see below). An empty or unavailable token makes the comment step fail before it starts: a warning, the result is unchanged. |
|
|
681
|
+
|
|
682
|
+
Inputs are validated before anything runs (booleans must be exactly `true` or `false`, the run id and `comment-id` must match their rules, numbers must be whole numbers); an invalid input fails the job with an error naming the input. The action's own messages don't repeat input values, and inputs reach its shell scripts only through environment variables, so a value can't inject commands. `github-token` only goes to the comment step (`actions/github-script`): never to a shell step or the browser container. The image step uses the job's own token (`github.token`) for one thing, `gh attestation verify` of the published image, before the browser container exists; the container never gets a token.
|
|
683
|
+
|
|
684
|
+
**Secrets in inputs:** the runner itself prints every step's `with:` and `env:` values in the job log (e.g. `INPUT_BASE_URL`). A `base-url` with a password or token in it is shown there in clear unless it comes from `secrets.` (GitHub masks secret values in logs), so put such a URL in a repository secret. The JSON result and the CLI output remove credentials themselves.
|
|
685
|
+
|
|
686
|
+
### Outputs
|
|
687
|
+
|
|
688
|
+
| Output | Description |
|
|
689
|
+
| :--- | :--- |
|
|
690
|
+
| `status` | `passed`, `failed` (visual differences, or a missing baseline in strict mode) or `error`. Always set, also when the runner check or the input validation failed (then `error`). |
|
|
691
|
+
| `exit-code` | `0` passed, `1` visual differences, `2` error. The action (and so the job) fails unless it is `0`. Always set, like `status`. |
|
|
692
|
+
| `total` | Snapshots (routes x viewports) checked. |
|
|
693
|
+
| `changed` | Snapshots with differences above the threshold. |
|
|
694
|
+
| `new-baselines` | Baselines created or replaced by this run. |
|
|
695
|
+
| `run-id` | The run id used. |
|
|
696
|
+
| `report-path` | The JSON result ([schema `visual-ci-result` v1](#json-result---json)) on the runner, in `$RUNNER_TEMP/visual-ci/`. Empty if none was written. |
|
|
697
|
+
| `summary-path` | The run's Markdown summary on the runner. Empty if none was written. |
|
|
698
|
+
| `run-dir` | The run folder (screenshots, diffs, `run.json`) on the runner. Empty if it does not exist. |
|
|
699
|
+
| `artifact-name` | Name of the uploaded artifact; empty unless the upload succeeded. |
|
|
700
|
+
| `artifact-id` | ID of the uploaded artifact; empty unless the upload succeeded. |
|
|
701
|
+
| `artifact-url` | Download URL of the uploaded artifact; empty unless the upload succeeded. |
|
|
702
|
+
| `comment-url` | URL of the pull request comment this run created or updated; empty otherwise. |
|
|
703
|
+
| `comment-action` | `created`, `updated`, `skipped` (a passing run with no earlier comment, a pull request from a fork, an invalid `comment-id`) or `failed` (a warning says why, e.g. a missing permission). Empty when the comment step did not run (`comment: false`, or not a `pull_request` event) or `actions/github-script` could not start it (e.g. an empty `github-token`). |
|
|
704
|
+
|
|
705
|
+
All paths are absolute paths on the runner. The outputs are set even when the job fails, so later steps with `if: always()` can use them: `status` and `exit-code` always; the others once the inputs were valid (they are empty when visual-ci never produced a result). A missing or unreadable JSON result is reported as `status: error` with an error annotation, never as a pass. The three `artifact-*` outputs come from the upload's own result, so they are empty whenever no artifact exists.
|
|
706
|
+
|
|
707
|
+
### What it does
|
|
708
|
+
|
|
709
|
+
1. Fails unless the runner is Linux, then validates the inputs.
|
|
710
|
+
2. Gets the image. With `image` set: pulls it. Used from the workspace (`uses: ./`, the action folder is inside `$GITHUB_WORKSPACE`): always builds it from the action's own `Dockerfile` (`docker build -t visual-ci-action:local "$GITHUB_ACTION_PATH"`), since that is the code under test and a published image of the same version would hold older code. With `image: build`: always builds. Used from GitHub (`uses: abhishek-k-33/Visual_Regression_Testing@v0`): looks up `ghcr.io/abhishek-k-33/visual-ci:<version from the action's package.json>` in the registry without pulling it (`scripts/image-info.sh`: `docker buildx imagetools inspect`, which gives its digest and then that digest's labels). It uses that digest only if its `io.github.abhishek-k-33.visual-ci.source-sha256` label equals the hash of the action's own image files (`scripts/image-source-hash.sh`) and `gh attestation verify oci://ghcr.io/abhishek-k-33/visual-ci@<digest> --repo abhishek-k-33/Visual_Regression_Testing --signer-workflow abhishek-k-33/Visual_Regression_Testing/.github/workflows/release.yml --source-ref refs/tags/v<version>` succeeds; then it pulls that digest (with a 10-minute timeout) and runs it by digest. Otherwise (no image for that version yet, a private package, another commit such as `@main`, a failed verification, no `gh`) it says why in a notice and builds. This comes first, so your app has the build time to start. Before that it copies the action's own scripts (`src/ci`, `src/shared`, `package.json`) read-only to `$RUNNER_TEMP/visual-ci-scripts`, which is never mounted into the container. The result and comment steps, which hold the token, load their code from that copy, so a page that compromised the browser can't change it even when the action folder is your workspace (`uses: ./`).
|
|
711
|
+
3. If `wait-on` is set, polls it with `curl` until it answers or `wait-timeout` passes.
|
|
712
|
+
4. Runs `node /app/src/cli/index.js test --json ... --strict|--no-strict` in it with `docker run --rm --network host --user "$(id -u):$(id -g)" -e HOME=/tmp -e CI=true`, the workspace mounted at `/github/workspace` (working directory `/github/workspace/<working-directory>`), the action's own folder `$RUNNER_TEMP/visual-ci` at `/visual-ci-temp` (for the JSON result) and the step summary file. Nothing else of `$RUNNER_TEMP` is mounted: it holds the runner's command files (`GITHUB_ENV`, `GITHUB_PATH`, ...) and the event payload, which a page compromising the browser could otherwise rewrite. `--network host` lets the container reach your app on `localhost`; `--user` keeps every file it writes owned by the runner user (no root-owned `storage/`). The branch and commit come from `GITHUB_HEAD_REF`/`GITHUB_REF_NAME` and `GITHUB_SHA`.
|
|
713
|
+
5. Reads the JSON result (`actions/github-script`, `src/ci/actionReport.js`) and sets the outputs. The CLI records paths relative to its working directory, so `storage/runs/<id>` becomes `$GITHUB_WORKSPACE/<working-directory>/storage/runs/<id>`; a container path under `/github/workspace` or `/visual-ci-temp` is mapped to `$GITHUB_WORKSPACE` or `$RUNNER_TEMP/visual-ci`, and anything else has no runner path (empty output). If the token can list the run's artifacts (`actions: read`), it also warns when `artifact-name` is already taken in this run.
|
|
714
|
+
6. Uploads the run folder with `actions/upload-artifact`.
|
|
715
|
+
7. Sets `status`, `exit-code` and `artifact-name` (also when an earlier step failed).
|
|
716
|
+
8. On a pull request, creates or updates the [pull request comment](#pull-request-comment) (`actions/github-script`, `src/ci/prComment.js`).
|
|
717
|
+
9. Ends with the CLI's exit code: the job passes on `0` and fails on `1` or `2` (or when no result was recorded, or the upload failed). The comment never changes this.
|
|
718
|
+
|
|
719
|
+
**Artifact upload (`upload-artifact`):**
|
|
720
|
+
|
|
721
|
+
- `on-failure` (default): uploaded when the exit code is `1` or `2`, i.e. visual differences, a missing baseline in strict mode, or an error after at least one screenshot was taken. Nothing is uploaded on a pass.
|
|
722
|
+
- `always`: uploaded whatever the result, including a pass.
|
|
723
|
+
- `never`: never uploaded.
|
|
724
|
+
|
|
725
|
+
In every mode only the folder of **this** run is uploaded (`<storage>/runs/<run-id>`), and only if the result names it, it really lies inside the workspace (also once symlinks are resolved), it contains no symlinks, and it holds at least one file. Never the whole `storage/`. When the run stopped before its first screenshot (invalid config, image build failed, the first page could not load) there is nothing to upload, and the `artifact-*` outputs stay empty.
|
|
726
|
+
|
|
727
|
+
**Which artifacts can be imported:** a run that finished comparing (exit `0` or `1`) has `run.json` at the root of the zip, so the downloaded artifact imports as is: `npx -y visual-regression-ci@0.9.1 import visual-regression-diffs.zip` (or `node src/cli/index.js import ...` from a checkout) or **Import CI run** in the dashboard (see [Review a CI Run Locally](#6-review-a-ci-run-locally-dashboard-upload-or-visual-ci-import)). An artifact from an **error run (exit `2`)** holds only the raw screenshots taken before the error, for debugging: it has no `run.json` and is **not importable** (the import refuses partial runs on purpose).
|
|
728
|
+
|
|
729
|
+
### Pull request comment
|
|
730
|
+
|
|
731
|
+
On `pull_request` events the action keeps **one comment** on the pull request with the latest result. It is created the first time a run does not pass, and every later run updates the same comment, also once everything passes again ("All N snapshots match the baselines"). A pull request that passes from the start gets no comment. For example:
|
|
732
|
+
|
|
733
|
+
> ### β Visual CI found visual changes
|
|
734
|
+
>
|
|
735
|
+
> 4 snapshots: 1 changed, 1 missing baseline, 2 passed.
|
|
736
|
+
>
|
|
737
|
+
> | Status | Route | Viewport | Mismatch |
|
|
738
|
+
> | :--- | :--- | :--- | ---: |
|
|
739
|
+
> | π΄ Changed | `/` | `mobile` | 7.04% |
|
|
740
|
+
> | π Missing baseline | `/docs` | `desktop` | β |
|
|
741
|
+
>
|
|
742
|
+
> **Details:** [Workflow run and step summary](#pull-request-comment) Β· [Artifact `visual-regression-diffs`](#pull-request-comment)
|
|
743
|
+
>
|
|
744
|
+
> Review it in your local dashboard:
|
|
745
|
+
>
|
|
746
|
+
> ```sh
|
|
747
|
+
> gh run download 4242 -R owner/repo -n 'visual-regression-diffs' -D vrt-4242 && npx -y visual-regression-ci@0.9.1 import vrt-4242
|
|
748
|
+
> ```
|
|
749
|
+
>
|
|
750
|
+
> <sub>visual-ci Β· commit `0637412` Β· updated 2026-11-26 10:41 UTC</sub>
|
|
751
|
+
|
|
752
|
+
- **What it shows:** the status with its counts (passed, changed, missing baseline, new baselines), or the error's code and message; a table of the changed snapshots only (`DIFF` and `MISSING_BASELINE`: route, viewport, mismatch rounded to 0.01%), at most 50 rows, then "β¦and N more"; links to the workflow run and the artifact; the pull request's head commit (not the merge commit `GITHUB_SHA`) and the time (UTC). The comment stays under 60,000 bytes of UTF-8 (GitHub's limit is 65,536 characters): table rows are dropped first, the headline always stays. If the artifact upload failed (which fails the job even when every snapshot matched), the comment says so instead of "passed".
|
|
753
|
+
- **Import snippet:** shown only when the artifact can be imported (exit `0` or `1`, and an artifact was uploaded). For an error run it says the artifact holds debugging screenshots only. It runs `npx -y visual-regression-ci@<version>` with the version of the action that made the run (read from the action's own `package.json`), so the import uses the same visual-ci that wrote the result, wherever it is installed or not.
|
|
754
|
+
- **Only `pull_request` events.** `pull_request_target` is not supported: the comment would name the pull request's head commit, while such a job usually tests the base branch.
|
|
755
|
+
- **Permissions:** the job needs `pull-requests: write` (and `contents: read` for the checkout):
|
|
756
|
+
```yaml
|
|
757
|
+
jobs:
|
|
758
|
+
visual:
|
|
759
|
+
permissions:
|
|
760
|
+
contents: read
|
|
761
|
+
pull-requests: write
|
|
762
|
+
```
|
|
763
|
+
Without it (or on Dependabot pull requests, whose token is read-only) the comment step warns with GitHub's answer and the probable fix (*"give the job permissions: pull-requests: write"*; a locked conversation also answers 403), and the job's result is unchanged. A comment problem of any kind is only ever a warning: it never changes `status`, `exit-code` or whether the job passes.
|
|
764
|
+
- **Pull requests from forks:** no comment. The token of a `pull_request` run from a fork is read-only, so the action skips the comment with a notice; the results are in the step summary and the artifact. Commenting on fork pull requests from a separate `workflow_run` workflow is a planned follow-up.
|
|
765
|
+
- **Safe with untrusted text:** routes, viewports and error messages are shown as code spans (`mdCode` in `src/shared/text.js`): control and bidi characters are escaped, the backtick fence is longer than any backtick run, and `|` is escaped in tables. So a route can't mention people, add links, images or HTML, or break the table. The step summary uses the same escaping.
|
|
766
|
+
- **Which comment is updated:** the oldest one whose first line is the hidden marker `<!-- visual-ci:sticky id=<comment-id> -->` **and** that was written by `github-actions[bot]` (a `Bot` account). A person who pastes the marker into their own comment never gets it overwritten. With a personal access token or a GitHub App token in `github-token` the comment has another author, so it is never recognised again and each run adds a new comment: keep the default token.
|
|
767
|
+
- **Duplicates:** two runs that overlap (two quick pushes, or matrix legs sharing a `comment-id`) can each create a comment. The next run keeps the oldest and edits the others to a short *"Superseded by the current visual-ci comment"* link, so no stale result lingers. To avoid overlaps, cancel older runs of the same pull request:
|
|
768
|
+
```yaml
|
|
769
|
+
concurrency:
|
|
770
|
+
group: visual-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
771
|
+
cancel-in-progress: true
|
|
772
|
+
```
|
|
773
|
+
- **Matrix builds:** give each leg its own `comment-id` (and its own `artifact-name` and `run-id`), so each keeps a separate comment instead of overwriting the others:
|
|
774
|
+
```yaml
|
|
775
|
+
strategy:
|
|
776
|
+
matrix:
|
|
777
|
+
app: [web, admin]
|
|
778
|
+
steps:
|
|
779
|
+
- uses: abhishek-k-33/Visual_Regression_Testing@v0
|
|
780
|
+
with:
|
|
781
|
+
base-url: http://127.0.0.1:3000
|
|
782
|
+
working-directory: apps/${{ matrix.app }}
|
|
783
|
+
comment-id: ${{ matrix.app }}
|
|
784
|
+
artifact-name: visual-diffs-${{ matrix.app }}
|
|
785
|
+
run-id: ${{ matrix.app }}-${{ github.run_id }}
|
|
786
|
+
```
|
|
787
|
+
- **Turn it off** with `comment: false` (then `contents: read` is all the job needs).
|
|
788
|
+
|
|
789
|
+
### Baselines in your repo
|
|
790
|
+
|
|
791
|
+
Baselines are PNGs in `<working-directory>/storage/baselines/` (or your `storageDir`), committed to git. They must be rendered by **the same Docker image** the action uses, or fonts and anti-aliasing will differ. Two ways to create or update them:
|
|
792
|
+
|
|
793
|
+
- **Locally, with the image:** pull the published image of the version your workflow uses (or build it from this repository: `docker build -t visual-ci https://github.com/abhishek-k-33/Visual_Regression_Testing.git#v0.9.1`) and run it against your app from your project folder:
|
|
794
|
+
```bash
|
|
795
|
+
docker pull ghcr.io/abhishek-k-33/visual-ci:0.9.1
|
|
796
|
+
docker run --rm --network host --user "$(id -u):$(id -g)" -e HOME=/tmp \
|
|
797
|
+
-v "$PWD:/work" -w /work ghcr.io/abhishek-k-33/visual-ci:0.9.1 \
|
|
798
|
+
node /app/src/cli/index.js test --update-baselines -u http://127.0.0.1:3000
|
|
799
|
+
git add storage/baselines && git commit -m "test: update visual baselines"
|
|
800
|
+
```
|
|
801
|
+
(With Docker Desktop on macOS or Windows, drop `--network host` and use `-u http://host.docker.internal:3000`.)
|
|
802
|
+
- **From CI:** run the action once with `update-baselines: true` and `upload-artifact: always` (for example from a `workflow_dispatch` workflow). Download the artifact: its `<route>-<viewport>.png` screenshots are the new baselines. Copy them into `storage/baselines/` and commit them, or `visual-ci import` the zip first to look at them in the dashboard. (A later step in the same job can also commit `storage/baselines/` itself, which needs `contents: write`.)
|
|
803
|
+
|
|
804
|
+
With the default `strict: true`, a route without a baseline fails the check instead of quietly creating one.
|
|
805
|
+
|
|
806
|
+
### Limitations
|
|
807
|
+
|
|
808
|
+
- **Linux runners only** (`ubuntu-*` or a self-hosted Linux runner with Docker): it needs `docker run --network host`, which macOS and Windows runners don't have. The Docker daemon must run containers as the `--user` it is given (rootful Docker, as on GitHub's runners).
|
|
809
|
+
- **Your app must already be running**, started in an earlier step and reachable from the runner (e.g. `http://127.0.0.1:<port>`; a `services:` container with a published port works too). Use `wait-on` so the check doesn't start before it is up.
|
|
810
|
+
- **No pull request comment for pull requests from forks** (their token is read-only); the step summary and the artifact still have the results. The action needs `contents: read`, plus `pull-requests: write` for the comment.
|
|
811
|
+
- The image is built in every job (a minute or two) unless you pass `image`.
|
|
812
|
+
- `VISUAL_STORAGE_DIR` from the job's environment is not passed into the container: set `storageDir` in the config instead.
|
|
813
|
+
- The container can read and write the whole workspace (it needs the config and `storage/`). Check out with `persist-credentials: false`, so no git token is left in `.git/config`.
|
|
814
|
+
|
|
815
|
+
The failure paths are proven on a real runner by `.github/workflows/action-selftest.yml` (on demand, and on pull requests that touch the action): a run against a changed page must fail with exit code `1`, upload an artifact that `visual-ci import` accepts, and a run against an unreachable app must fail with `2` and upload nothing; on pull requests from this repository a run against a changed page must also create or update its comment.
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
819
|
+
## π GitHub Actions CI Pipeline
|
|
820
|
+
|
|
821
|
+
The project includes pre-configured automation for GitHub Actions (`.github/workflows/visual-ci.yml`):
|
|
822
|
+
|
|
823
|
+
- **Automatic PR & Push Testing**: Runs the Vitest suite and the visual regression checks whenever a PR or commit is pushed to `main`.
|
|
824
|
+
- **Tests a real target**: Serves the bundled demo site and captures it, rather than an external website that can change underneath the tests.
|
|
825
|
+
- **Committed baselines**: Baselines come from the git checkout, so every commit is compared against the baselines approved for it.
|
|
826
|
+
- **Dogfoods the action**: the `visual-tests` job starts the demo site and runs this repository's own action (`uses: ./`, see [Use it in your repo](#-use-it-in-your-repo-github-action)), which builds the project's Docker image and runs the tests inside it, so the rendering matches the baselines. The job has `pull-requests: write` (and `contents: read`), so this repository's own pull requests get the result comment.
|
|
827
|
+
- **Strict mode**: A missing baseline fails the job instead of silently passing.
|
|
828
|
+
- **Action self-test** (`.github/workflows/action-selftest.yml`, on demand and on pull requests that touch the action, the CLI or the image): serves the demo site's `regressed` variant and requires the action to fail with exit code `1`, upload an artifact and have that artifact import with `visual-ci import` (downloaded with `gh run download`, retried with backoff because a just-uploaded artifact is not always found at once within the same run; the job has `actions: read` for that); then points the action at an unreachable port and requires exit code `2` and no artifact. Neither job can change the committed baselines or comment on the pull request (`comment: false`, and a read-only token). A third job, `comment` (pull requests from this repository only, with `pull-requests: write`), runs the `regressed` variant with `comment-id: selftest` and requires `comment-action` to be `created` or `updated` and `comment-url` to be an `https` link: live proof that the comment is written, so such pull requests carry one sticky comment headed *Visual CI found visual changes (`selftest`)*.
|
|
829
|
+
- **Rich Markdown Step Summaries**: Generates a formatted table of every tested route, viewport, mismatch percentage, and pass/fail badge directly in the GitHub Actions run summary (`GITHUB_STEP_SUMMARY`).
|
|
830
|
+
- **Diff Artifact Downloads**: On any visual regression failure (or error), the run's folder (`storage/runs/<run-id>/`) is uploaded as a workflow artifact (`visual-regression-diffs`, kept 7 days) for quick inspection. The run folder includes `run.json`, a machine-readable record of the run (status, git info, and per snapshot: route, viewport, status, mismatch, file names and the compared baseline's hash), so a CI run can be re-created without its database: `visual-ci import visual-regression-diffs.zip` loads it into your local dashboard (see [Review a CI Run Locally](#6-review-a-ci-run-locally-dashboard-upload-or-visual-ci-import)).
|
|
831
|
+
|
|
832
|
+
### Releases (`.github/workflows/release.yml`)
|
|
833
|
+
|
|
834
|
+
Pushing a version tag (`v0.9.1`, `v1.0.0-rc.1`) releases that version; [RELEASING.md](RELEASING.md) is the step-by-step checklist. The jobs:
|
|
835
|
+
|
|
836
|
+
```text
|
|
837
|
+
verify βββ¬ββ npm βββββ¬ββ release
|
|
838
|
+
βββ image βββ
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
- **verify** (`contents: read`): the tag must be exactly `v` + the `package.json` version (else it fails and says how to fix it) and its commit must be on `main`; it works out whether this is the newest release (of all, and of its major version) from the repository's `vX.Y.Z` tags; then `npm ci`, Playwright Chromium, the whole test suite and `scripts/check-package.js`.
|
|
842
|
+
- **npm** (`contents: read`, `id-token: write`): publishes `visual-regression-ci@<version>` with npm **trusted publishing**: npm accepts a short-lived OIDC token from this workflow, so no npm token exists anywhere (Node 24, npm 11.5.1 or newer, provenance added automatically). It installs no dependencies, skips a version that is already on npm (0.9.0 was published by hand), and publishes prereleases under the dist-tag `next`.
|
|
843
|
+
- **image** (`contents: read`, `packages: write`, `id-token: write`, `attestations: write`): builds the `Dockerfile` and pushes `ghcr.io/abhishek-k-33/visual-ci:<version>`, with OCI labels (`org.opencontainers.image.source` links the package to this repository) and the source-hash label the action checks. `:<major>` moves only to the newest full release of that major version and `:latest` only to the newest of all, so a re-run or a patch of an older line never moves them backwards. A version that is already published from the same files is not built again (a re-run); one published from other files is never overwritten (the job fails). It attests the pushed digest with `actions/attest-build-provenance` (build provenance signed for this run, also pushed to the registry), which the action verifies. Then it verifies that attestation itself, pulls the digest and checks its label and `--version`.
|
|
844
|
+
- **release** (`contents: write`): creates the GitHub release with generated notes (`--prerelease` for prereleases, `--latest=false` when a newer release exists; an existing release is left alone) and moves the major tag (`v0`, later `v1`) to the tag's commit through the REST API, again only for the newest full release of that major version.
|
|
845
|
+
- The npm and image jobs of a real release run in the GitHub environment `release`, which only `v*` tags may use; npm's trusted publisher names that environment (see [RELEASING.md](RELEASING.md)).
|
|
846
|
+
|
|
847
|
+
The concurrency group `release` runs one release at a time and never cancels one; dry runs queue in their own group (`release-dry-run`), so they can never push out a waiting real release. **Actions β Release β Run workflow** is a dry run by default (`dry-run: true`): every check and the image build run, but nothing is published, pushed or tagged. `tests/release.test.js` checks the workflow and runs its scripts against fake `npm` and `gh` commands.
|
|
848
|
+
|
|
849
|
+
### Live demo on GitHub Pages (`.github/workflows/pages.yml`)
|
|
850
|
+
|
|
851
|
+
- **Build**: on pushes and pull requests to `main` that touch `src/`, `scripts/`, the package files or the workflow, runs `scripts/build-static-demo.js` (see [Build the Static Demo](#7-build-the-static-demo-github-pages)) with the repository name as the base path, and uploads `_site` as the Pages artifact. On pull requests it only builds, so a change that breaks the demo fails the PR.
|
|
852
|
+
- **Deploy**: on `main` (or a manual run from `main`), deploys the artifact with `actions/deploy-pages` and smoke-tests that the dashboard and the `demo-05-regression` run page return `200`.
|
|
853
|
+
- **Setup**: the repository's Pages source must be set to *GitHub Actions* (Settings β Pages).
|
|
854
|
+
|
|
855
|
+
---
|
|
856
|
+
|
|
857
|
+
## π§ͺ Testing & Verification
|
|
858
|
+
|
|
859
|
+
The project includes unit, integration, and deliverable verification suites:
|
|
860
|
+
|
|
861
|
+
```bash
|
|
862
|
+
# Run all 1118 Vitest unit, integration & browser tests
|
|
863
|
+
npm test
|
|
864
|
+
|
|
865
|
+
# Run Phase 1 Deliverable Verification (Capture & Masking)
|
|
866
|
+
node tests/verify-phase-1.js
|
|
867
|
+
|
|
868
|
+
# Run Phase 2 Deliverable Verification (Pixel Diffing & Layout Shifts)
|
|
869
|
+
node tests/verify-phase-2.js
|
|
870
|
+
|
|
871
|
+
# Run Phase 3 Deliverable Verification (Database, Dashboard & Approvals)
|
|
872
|
+
node tests/verify-phase-3.js
|
|
873
|
+
|
|
874
|
+
# Run Phase 4 Deliverable Verification (Docker & Cross-OS Environment)
|
|
875
|
+
node tests/verify-phase-4.js
|
|
876
|
+
|
|
877
|
+
# Run Phase 5 Deliverable Verification (GitHub Actions CI & Markdown Reports)
|
|
878
|
+
node tests/verify-phase-5.js
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
### Verification Results
|
|
882
|
+
```text
|
|
883
|
+
β tests/config.test.js (21 tests)
|
|
884
|
+
β tests/capture.test.js (8 tests)
|
|
885
|
+
β tests/compare.test.js (11 tests)
|
|
886
|
+
β tests/capture-integration.test.js (6 tests)
|
|
887
|
+
β tests/cli-strict.test.js (5 tests)
|
|
888
|
+
β tests/cli-json.test.js (26 tests)
|
|
889
|
+
β tests/result.test.js (25 tests)
|
|
890
|
+
β tests/shared-text.test.js (4 tests)
|
|
891
|
+
β tests/display.test.js (8 tests)
|
|
892
|
+
β tests/json-target.test.js (7 tests)
|
|
893
|
+
β tests/capture-errors.test.js (8 tests)
|
|
894
|
+
β tests/install-browsers.test.js (8 tests)
|
|
895
|
+
β tests/invocation.test.js (12 tests)
|
|
896
|
+
β tests/lazy-imports.test.js (14 tests)
|
|
897
|
+
β tests/package.test.js (19 tests)
|
|
898
|
+
β tests/demo-app.test.js (8 tests)
|
|
899
|
+
β tests/build-static-demo.test.js (14 tests)
|
|
900
|
+
β tests/db.test.js (19 tests)
|
|
901
|
+
β tests/docker.test.js (3 tests)
|
|
902
|
+
β tests/action.test.js (241 tests)
|
|
903
|
+
β tests/action-report.test.js (65 tests)
|
|
904
|
+
β tests/pr-comment.test.js (85 tests)
|
|
905
|
+
β tests/release.test.js (113 tests)
|
|
906
|
+
β tests/sync-readme-version.test.js (7 tests)
|
|
907
|
+
β tests/manifest.test.js (19 tests)
|
|
908
|
+
β tests/import.test.js (104 tests)
|
|
909
|
+
β tests/upload-import.test.js (24 tests)
|
|
910
|
+
β tests/import-ui.test.js (11 tests)
|
|
911
|
+
β tests/per-run-baselines.test.js (11 tests)
|
|
912
|
+
β tests/approve-all.test.js (21 tests)
|
|
913
|
+
β tests/approve-all-api.test.js (12 tests)
|
|
914
|
+
β tests/server.test.js (52 tests)
|
|
915
|
+
β tests/serve.test.js (21 tests)
|
|
916
|
+
β tests/storage-dir.test.js (3 tests)
|
|
917
|
+
β tests/urls.test.js (3 tests)
|
|
918
|
+
β tests/viewModels.test.js (32 tests)
|
|
919
|
+
β tests/theme-contrast.test.js (9 tests)
|
|
920
|
+
β tests/responsive-theme.test.js (9 tests)
|
|
921
|
+
β tests/reporter.test.js (16 tests)
|
|
922
|
+
β tests/a11y-axe.test.js (14 tests)
|
|
923
|
+
β tests/keyboard-ui.test.js (20 tests)
|
|
924
|
+
|
|
925
|
+
Test Files 41 passed (41)
|
|
926
|
+
Tests 1118 passed (1118)
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
---
|
|
930
|
+
|
|
931
|
+
## π Engineering Logs & Milestones
|
|
932
|
+
|
|
933
|
+
Detailed implementation specifications, security audits, and architectural records:
|
|
934
|
+
- **[Phase 1 Implementation Record](docs/PHASE_1_EXECUTION.md)**: Playwright engine, deterministic animation freezing, dynamic DOM masking.
|
|
935
|
+
- **[Phase 2 Implementation Record](docs/PHASE_2_EXECUTION.md)**: Pixel diffing engine, canvas dimension normalization, baseline promotion.
|
|
936
|
+
- **[Phase 3 Implementation Record](docs/PHASE_3_EXECUTION.md)**: SQLite storage, REST API, interactive review dashboard, and security hardening.
|
|
937
|
+
- **[Phase 4 Implementation Record](docs/PHASE_4_EXECUTION.md)**: Cross-platform Docker containerization, volume sharing, and font normalization.
|
|
938
|
+
- **[Phase 5 Implementation Record](docs/PHASE_5_EXECUTION.md)**: GitHub Actions CI workflow, PR gating, Markdown step summaries, and diff archiving.
|
|
939
|
+
|
|
940
|
+
---
|
|
941
|
+
|
|
942
|
+
## πΊοΈ Roadmap
|
|
943
|
+
|
|
944
|
+
- [x] **Phase 1:** Multi-viewport capture engine & deterministic DOM freezing.
|
|
945
|
+
- [x] **Phase 2:** Pixel diffing engine, dimension normalizer & CLI test command.
|
|
946
|
+
- [x] **Phase 3:** Embedded SQLite storage, REST API & interactive review dashboard.
|
|
947
|
+
- [x] **Phase 4:** Cross-platform Docker containerization (`Dockerfile`, `docker-compose.yml`) for OS-independent rendering consistency.
|
|
948
|
+
- [x] **Phase 5:** GitHub Actions CI workflow with automated PR checks, Markdown step summaries, and diff artifact uploads.
|
|
949
|
+
|
|
950
|
+
---
|
|
951
|
+
|
|
952
|
+
## π License
|
|
953
|
+
|
|
954
|
+
[MIT](LICENSE)
|