afterbefore 0.1.2 → 0.1.3
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/README.md +114 -1
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -3,12 +3,125 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/afterbefore)
|
|
4
4
|
[](https://www.npmjs.com/package/afterbefore)
|
|
5
5
|
|
|
6
|
-
Automatic before/after screenshot capture for Next.js pull requests.
|
|
6
|
+
Automatic before/after screenshot capture for Next.js pull requests.
|
|
7
|
+
|
|
8
|
+
## The idea
|
|
9
|
+
|
|
10
|
+
Other visual regression tools make you list which URLs to capture. afterbefore reads your git diff instead, builds an import graph, and figures out which routes were affected by your changes. You change a button component, it finds every page that uses that button, and captures those. No URL lists, no config.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
Run it from a feature branch in any Next.js app router project:
|
|
7
15
|
|
|
8
16
|
```bash
|
|
9
17
|
npx afterbefore
|
|
10
18
|
```
|
|
11
19
|
|
|
20
|
+
It spins up two dev servers (your branch and the base branch), captures screenshots of affected routes, diffs them pixel by pixel, and generates an HTML report with interactive before/after sliders.
|
|
21
|
+
|
|
22
|
+
Output lands in `.afterbefore/`:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
.afterbefore/
|
|
26
|
+
└── feature-branch_2026-02-26/
|
|
27
|
+
├── index.html # visual report
|
|
28
|
+
├── summary.md # markdown table
|
|
29
|
+
├── about-before.png
|
|
30
|
+
├── about-after.png
|
|
31
|
+
├── about-diff.png
|
|
32
|
+
├── about-compare.png
|
|
33
|
+
└── about-slider.html # interactive slider
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Open the report automatically:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx afterbefore --open
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## How it works
|
|
43
|
+
|
|
44
|
+
1. Reads `git diff` to find changed files
|
|
45
|
+
2. Classifies each file (page, component, layout, style, utility, config)
|
|
46
|
+
3. Builds an import graph by parsing ES module imports across your codebase
|
|
47
|
+
4. Walks the graph backward from each changed file to find which `page.tsx` files are affected
|
|
48
|
+
5. Creates a git worktree for the base branch and runs `npm install`
|
|
49
|
+
6. Starts two Next.js dev servers in parallel (base branch + current branch)
|
|
50
|
+
7. Captures full-page screenshots of each affected route on both servers using Playwright
|
|
51
|
+
8. Compares screenshots with pixelmatch and generates diff images
|
|
52
|
+
9. Builds an HTML report with side-by-side comparisons and interactive sliders
|
|
53
|
+
|
|
54
|
+
Layouts work the same way. Edit `app/dashboard/layout.tsx` and it captures every page under `app/dashboard/`.
|
|
55
|
+
|
|
56
|
+
If only global files changed (like `globals.css` or `tailwind.config.ts`) and no specific routes were found, it captures all pages.
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
| Flag | Default | Description |
|
|
61
|
+
|------|---------|-------------|
|
|
62
|
+
| `--base <ref>` | `main` | Base branch to compare against |
|
|
63
|
+
| `--output <dir>` | `.afterbefore` | Output directory |
|
|
64
|
+
| `--post` | `false` | Post results as a GitHub PR comment |
|
|
65
|
+
| `--threshold <percent>` | `0.1` | Ignore diffs below this percentage |
|
|
66
|
+
| `--max-routes <count>` | `6` | Cap the number of routes captured (0 = unlimited) |
|
|
67
|
+
| `--open` | `false` | Open the HTML report in your browser |
|
|
68
|
+
| `--width <pixels>` | `1280` | Viewport width |
|
|
69
|
+
| `--height <pixels>` | `720` | Viewport height |
|
|
70
|
+
| `--device <name>` | — | Playwright device, e.g. `"iPhone 14"` |
|
|
71
|
+
| `--delay <ms>` | `0` | Extra wait time after page load |
|
|
72
|
+
| `--no-auto-tabs` | — | Disable auto-detection of ARIA tab states |
|
|
73
|
+
| `--max-tabs <count>` | `5` | Max tabs to capture per route |
|
|
74
|
+
| `--auto-sections` | `false` | Capture heading-labeled sections individually |
|
|
75
|
+
| `--max-sections <count>` | `10` | Max sections per page state |
|
|
76
|
+
|
|
77
|
+
## Post to PR
|
|
78
|
+
|
|
79
|
+
The `--post` flag uses the GitHub CLI (`gh`) to add a comment to your open pull request with a markdown summary of the results. On subsequent runs, it updates the same comment instead of creating a new one.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx afterbefore --post
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
You need `gh` installed and authenticated.
|
|
86
|
+
|
|
87
|
+
## Auto-detection
|
|
88
|
+
|
|
89
|
+
**Tabs.** If a page has ARIA tab controls (`role="tablist"` and `role="tab"`), afterbefore clicks through each tab and captures the state. This is on by default. Disable it with `--no-auto-tabs`.
|
|
90
|
+
|
|
91
|
+
**Sections.** With `--auto-sections`, pages with 3+ headings get captured section by section. Each heading-labeled section is matched by text between before and after, so you can see exactly which section changed.
|
|
92
|
+
|
|
93
|
+
## Configuration file
|
|
94
|
+
|
|
95
|
+
For pages that need interaction before capture (opening a modal, clicking a dropdown), create an `afterbefore.config.json`:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"scenarios": {
|
|
100
|
+
"/design-system": [
|
|
101
|
+
{
|
|
102
|
+
"name": "components-tab",
|
|
103
|
+
"actions": [
|
|
104
|
+
{ "click": ".tab-components" },
|
|
105
|
+
{ "wait": 300 }
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Actions run in order before the screenshot is taken. Supported actions: `click` (CSS selector), `scroll` (CSS selector), `wait` (milliseconds).
|
|
114
|
+
|
|
115
|
+
When scenarios are defined for a route, auto-tabs are disabled for that route.
|
|
116
|
+
|
|
117
|
+
## Requirements
|
|
118
|
+
|
|
119
|
+
- Next.js with the app router (`app/` directory)
|
|
120
|
+
- Git
|
|
121
|
+
- Node.js >= 18
|
|
122
|
+
|
|
123
|
+
Playwright's Chromium browser is installed automatically on first run if it's missing.
|
|
124
|
+
|
|
12
125
|
## License
|
|
13
126
|
|
|
14
127
|
Licensed under [PolyForm Shield 1.0.0](https://polyformproject.org/licenses/shield/1.0.0)
|
package/dist/cli.js
CHANGED
|
@@ -1958,7 +1958,7 @@ async function runPipeline(options) {
|
|
|
1958
1958
|
const outputDir = resolve4(cwd, output, sessionName);
|
|
1959
1959
|
const startTime = Date.now();
|
|
1960
1960
|
try {
|
|
1961
|
-
const version = true ? "0.1.
|
|
1961
|
+
const version = true ? "0.1.3" : "dev";
|
|
1962
1962
|
console.log(`
|
|
1963
1963
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1964
1964
|
`);
|
|
@@ -2092,7 +2092,7 @@ afterbefore v${version} \xB7 Comparing against ${base}
|
|
|
2092
2092
|
var program = new Command();
|
|
2093
2093
|
program.name("afterbefore").description(
|
|
2094
2094
|
"Automatic before/after screenshot capture for PRs. Git diff is the config."
|
|
2095
|
-
).version("0.1.
|
|
2095
|
+
).version("0.1.3").option("--base <ref>", "Base branch or ref to compare against", "main").option("--output <dir>", "Output directory for screenshots", ".afterbefore").option("--post", "Post results as a PR comment via gh CLI", false).option(
|
|
2096
2096
|
"--threshold <percent>",
|
|
2097
2097
|
"Diff threshold percentage (changes below this are ignored)",
|
|
2098
2098
|
"0.1"
|
package/dist/index.js
CHANGED
|
@@ -1945,7 +1945,7 @@ async function runPipeline(options) {
|
|
|
1945
1945
|
const outputDir = resolve4(cwd, output, sessionName);
|
|
1946
1946
|
const startTime = Date.now();
|
|
1947
1947
|
try {
|
|
1948
|
-
const version = true ? "0.1.
|
|
1948
|
+
const version = true ? "0.1.3" : "dev";
|
|
1949
1949
|
console.log(`
|
|
1950
1950
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1951
1951
|
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "afterbefore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Automatic before/after screenshot capture for PRs. Git diff is the config.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dev": "tsup --watch",
|
|
23
23
|
"test": "vitest run",
|
|
24
24
|
"test:watch": "vitest",
|
|
25
|
-
|
|
26
25
|
"typecheck": "tsc --noEmit",
|
|
27
26
|
"lint": "tsc --noEmit",
|
|
28
27
|
"prepare": "tsup"
|