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 CHANGED
@@ -1,40 +1,30 @@
1
1
  # afterbefore
2
2
 
3
- Automatic before/after screenshot capture for pull requests. **The git diff is the config.**
3
+ [![npm version](https://img.shields.io/npm/v/afterbefore)](https://www.npmjs.com/package/afterbefore)
4
+ [![npm downloads](https://img.shields.io/npm/dm/afterbefore)](https://www.npmjs.com/package/afterbefore)
4
5
 
5
- Change code, run one command, get a visual comparison. No config files, no manual URL lists, no SaaS — `afterbefore` reads your diff, walks the import graph, and captures both versions automatically.
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
- ## The Problem
12
-
13
- Visual PR reviews are painful:
14
-
15
- 1. Switch to main, start the app, take screenshots
16
- 2. Switch back to your branch, start the app, take more screenshots
17
- 3. Crop, label, and paste into the PR description
18
-
19
- This takes 5-10 minutes. Most developers skip it. Reviewers approve visual changes blind.
20
-
21
- ## How It Works
22
-
23
- ```
24
- git diff classify changed files build import graph → BFS to find affected pages
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
- # From GitHub (builds automatically on install)
35
+ # from GitHub
46
36
  npm install --save-dev github:kairevicius/afterbefore
47
37
 
48
- # Or run directly without installing
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
- # Compare current branch against main
45
+ # compare current branch vs main
62
46
  npx afterbefore
63
47
 
64
- # Compare against a different base
48
+ # compare against a different base branch
65
49
  npx afterbefore --base develop
66
50
 
67
- # Capture and post results to the open PR
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
- summary.md Markdown table (for PR comments)
84
- index.html HTML report with card grid
85
- _root/
86
- before.png Screenshot of / on base branch
87
- after.png Screenshot of / on current branch
88
- diff.png Pixel diff overlay
89
- side-by-side.png Labeled comparison image
90
- slider.html Interactive drag-to-compare
91
- about/
92
- before.png
93
- after.png
94
- diff.png
95
- side-by-side.png
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` in a browser to see all comparisons at a glance. Each changed route gets a card with before/after/diff images and a link to the interactive slider.
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
- Every visual regression tool either captures everything on every run (Chromatic, Lost Pixel) or requires manual URL configuration (Percy, BackstopJS). `afterbefore` is the only tool that figures out what to capture from the code diff.
130
+ ## Requirements And Limits
111
131
 
112
- | | Visual regression tools | afterbefore |
113
- |---|---|---|
114
- | Config | URL lists, story lists | Zero — reads git diff |
115
- | Scope | Everything, every run | Only affected pages |
116
- | Philosophy | "Did anything break?" | "Here's what changed" |
117
- | Hosting | Cloud SaaS | Local, nothing leaves your machine |
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