afterbefore 0.1.0 → 0.1.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/README.md +95 -76
- package/dist/cli.js +1258 -266
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +74 -2
- package/dist/index.js +1209 -236
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
# afterbefore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/afterbefore)
|
|
4
|
+
[](https://www.npmjs.com/package/afterbefore)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Automatic before/after screenshot capture for Next.js pull requests. **The git diff is the config.**
|
|
7
|
+
|
|
8
|
+
Change code, run one command, and get a visual report of only impacted routes.
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
npx afterbefore
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
→ git worktree for base version → start 2 dev servers → Playwright capture
|
|
26
|
-
→ pixelmatch diff → side-by-side comparison → HTML report + PR comment
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
1. **Diff** — reads `git diff --name-status` to find changed files
|
|
30
|
-
2. **Classify** — categorizes as page, component, style, layout, utility, config, test
|
|
31
|
-
3. **Import graph** — parses all imports with `es-module-lexer`, resolves `@/` tsconfig aliases
|
|
32
|
-
4. **Impact analysis** — BFS traverses the reverse import graph (depth 3) to find affected pages
|
|
33
|
-
5. **Worktree** — creates a git worktree for the base branch, installs deps
|
|
34
|
-
6. **Dev servers** — starts two Next.js dev servers (before + after) on random ports
|
|
35
|
-
7. **Capture** — Playwright takes full-page screenshots at 1280x720 for each affected route
|
|
36
|
-
8. **Compare** — pixelmatch detects pixel-level differences, sharp generates side-by-side images
|
|
37
|
-
9. **Report** — HTML card grid, drag-to-compare sliders, markdown summary, optional PR comment
|
|
14
|
+
## What It Does
|
|
15
|
+
|
|
16
|
+
1. Reads changed files from `git diff` against a base ref
|
|
17
|
+
2. Builds an import graph and finds affected `app/**/page.*` routes
|
|
18
|
+
3. Handles layout/global style changes that are not direct imports
|
|
19
|
+
4. Creates a temporary git worktree for the base ref
|
|
20
|
+
5. Starts two Next.js dev servers (before + after)
|
|
21
|
+
6. Captures screenshots with Playwright
|
|
22
|
+
7. Computes pixel diffs with `pixelmatch`
|
|
23
|
+
8. Generates:
|
|
24
|
+
- `index.html` visual report
|
|
25
|
+
- per-route slider pages for changed routes
|
|
26
|
+
- `summary.md` for PR comments
|
|
27
|
+
9. Optionally posts/updates a GitHub PR comment (`--post`)
|
|
38
28
|
|
|
39
29
|
## Installation
|
|
40
30
|
|
|
@@ -42,80 +32,109 @@ git diff → classify changed files → build import graph → BFS to find affec
|
|
|
42
32
|
# npm
|
|
43
33
|
npm install --save-dev afterbefore
|
|
44
34
|
|
|
45
|
-
#
|
|
35
|
+
# from GitHub
|
|
46
36
|
npm install --save-dev github:kairevicius/afterbefore
|
|
47
37
|
|
|
48
|
-
#
|
|
38
|
+
# run without installing
|
|
49
39
|
npx afterbefore
|
|
50
40
|
```
|
|
51
41
|
|
|
52
|
-
Playwright's Chromium browser is required for screenshots:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
npx playwright install chromium
|
|
56
|
-
```
|
|
57
|
-
|
|
58
42
|
## Usage
|
|
59
43
|
|
|
60
44
|
```bash
|
|
61
|
-
#
|
|
45
|
+
# compare current branch vs main
|
|
62
46
|
npx afterbefore
|
|
63
47
|
|
|
64
|
-
#
|
|
48
|
+
# compare against a different base branch
|
|
65
49
|
npx afterbefore --base develop
|
|
66
50
|
|
|
67
|
-
#
|
|
51
|
+
# post/update comment on the open PR (requires gh auth)
|
|
68
52
|
npx afterbefore --post
|
|
69
53
|
```
|
|
70
54
|
|
|
71
|
-
### Options
|
|
55
|
+
### CLI Options
|
|
72
56
|
|
|
73
57
|
| Flag | Description | Default |
|
|
74
58
|
|------|-------------|---------|
|
|
75
59
|
| `--base <ref>` | Base branch or ref to compare against | `main` |
|
|
76
|
-
| `--output <dir>` | Output directory | `.afterbefore` |
|
|
77
|
-
| `--post` | Post results as a PR comment via `gh` CLI | `false` |
|
|
60
|
+
| `--output <dir>` | Output directory root | `.afterbefore` |
|
|
61
|
+
| `--post` | Post/update results as a PR comment via `gh` CLI | `false` |
|
|
62
|
+
| `--threshold <percent>` | Diff threshold percentage below which route is marked unchanged | `0.1` |
|
|
63
|
+
| `--max-routes <count>` | Maximum routes to capture (`0` = unlimited) | `6` |
|
|
64
|
+
| `--open` | Auto-open `index.html` after run | `false` |
|
|
65
|
+
| `--width <pixels>` | Viewport width | `1280` |
|
|
66
|
+
| `--height <pixels>` | Viewport height | `720` |
|
|
67
|
+
| `--device <name>` | Playwright device preset (for example `iPhone 14`) | unset |
|
|
68
|
+
| `--delay <ms>` | Extra wait after page load/actions | `0` |
|
|
69
|
+
| `--no-auto-tabs` | Disable ARIA tab state auto-capture | auto-tabs enabled |
|
|
70
|
+
| `--max-tabs <count>` | Max auto-detected inactive tabs per route | `5` |
|
|
71
|
+
| `--auto-sections` | Auto-detect and capture heading-labeled sections | `false` |
|
|
72
|
+
| `--max-sections <count>` | Max auto-detected sections per page/tab state | `10` |
|
|
73
|
+
|
|
74
|
+
## Optional Scenario Config
|
|
75
|
+
|
|
76
|
+
`afterbefore` can run scripted interactions before capture via config files:
|
|
77
|
+
|
|
78
|
+
- `afterbefore.config.json`
|
|
79
|
+
- `afterbefore.config.js`
|
|
80
|
+
- `afterbefore.config.mjs`
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"scenarios": {
|
|
87
|
+
"/pricing": [
|
|
88
|
+
{
|
|
89
|
+
"name": "annual-toggle",
|
|
90
|
+
"actions": [
|
|
91
|
+
{ "click": "[data-testid='billing-toggle']" },
|
|
92
|
+
{ "wait": 300 }
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "plan-cards-only",
|
|
97
|
+
"selector": "[data-testid='plan-grid']",
|
|
98
|
+
"actions": []
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
When a route has manual scenarios, default auto tab/section expansion is skipped for that route.
|
|
78
106
|
|
|
79
107
|
## Output
|
|
80
108
|
|
|
81
|
-
|
|
109
|
+
Each run creates a dated session directory:
|
|
110
|
+
|
|
111
|
+
```text
|
|
82
112
|
.afterbefore/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
before.png
|
|
87
|
-
after.png
|
|
88
|
-
diff.png
|
|
89
|
-
|
|
90
|
-
slider.html
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
slider.html
|
|
113
|
+
<branch>_YYYY-MM-DD/
|
|
114
|
+
index.html
|
|
115
|
+
summary.md
|
|
116
|
+
_root-before.png
|
|
117
|
+
_root-after.png
|
|
118
|
+
_root-diff.png
|
|
119
|
+
_root-compare.png # only when changed
|
|
120
|
+
_root-slider.html # only when changed
|
|
121
|
+
about-before.png
|
|
122
|
+
about-after.png
|
|
123
|
+
about-diff.png
|
|
124
|
+
about-compare.png
|
|
125
|
+
about-slider.html
|
|
97
126
|
```
|
|
98
127
|
|
|
99
|
-
Open `index.html`
|
|
100
|
-
|
|
101
|
-
## Requirements
|
|
102
|
-
|
|
103
|
-
- Node.js 18+
|
|
104
|
-
- Git
|
|
105
|
-
- Next.js project using the app router
|
|
106
|
-
- Playwright Chromium (`npx playwright install chromium`)
|
|
107
|
-
|
|
108
|
-
## How It's Different
|
|
128
|
+
Open `index.html` to review all captured states.
|
|
109
129
|
|
|
110
|
-
|
|
130
|
+
## Requirements And Limits
|
|
111
131
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
| Cost | Per-snapshot pricing | Free, open source |
|
|
132
|
+
- Node.js `>=18`
|
|
133
|
+
- Git repository
|
|
134
|
+
- Next.js App Router project (`app/` pages)
|
|
135
|
+
- Dependencies installable in temporary worktree
|
|
136
|
+
- `gh` CLI authenticated if using `--post`
|
|
137
|
+
- Dynamic routes (for example `app/blog/[slug]/page.tsx`) are currently skipped
|
|
119
138
|
|
|
120
139
|
## License
|
|
121
140
|
|