@cevek/screentest 0.2.5 → 0.3.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,13 +1,12 @@
1
1
  # @cevek/screentest
2
2
 
3
- Local desktop tool for visual screenshot-test review, **plus** the runner
4
- helpers and Docker-based test harness needed to actually capture the
3
+ Local desktop tool for visual screenshot-test review **plus** the runner
4
+ helpers and Docker-based browser harness needed to capture the
5
5
  screenshots. Everything ships in one npm package — no copy-paste.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- # pick your package manager — all three are supported:
11
10
  npm i -D @cevek/screentest playwright vitest && npx playwright install firefox
12
11
  # pnpm add -D @cevek/screentest playwright vitest && pnpm exec playwright install firefox
13
12
  # yarn add -D @cevek/screentest playwright vitest && yarn playwright install firefox
@@ -15,26 +14,31 @@ npm i -D @cevek/screentest playwright vitest && npx playwright install firefox
15
14
 
16
15
  `playwright` and `vitest` are peer-deps — keep them in your devDependencies.
17
16
 
18
- `screentest init` detects your package manager (from your lockfile or
19
- `packageManager` field) and writes a matching `Dockerfile.tests`.
20
-
21
17
  ## Quick start
22
18
 
23
19
  ```bash
24
- # 1. Scaffold the test harness into your project.
20
+ # 1. Scaffold vitest.screentest.config.ts + tests/example.test.ts
25
21
  npx screentest init
26
22
 
27
- # 2. Build the Docker image once.
28
- docker build -f Dockerfile.tests -t screentest-tests .
23
+ # 2. Start the shared Firefox daemon (one-time per machine — image builds
24
+ # on first run, ~2 min; cached forever after).
25
+ npx screentest serve
29
26
 
30
27
  # 3. Run.
31
28
  APP_URL=http://localhost:5050 npx screentest test
32
29
  ```
33
30
 
31
+ The daemon lives outside your project — one container serves every
32
+ project on your machine. It listens on `ws://localhost:5180`, holds
33
+ ~300MB RAM at idle, and stays up across reboots-of-your-app until you
34
+ `screentest stop` it.
35
+
36
+ Your **tests run natively on the host** (your normal vitest + TS + path
37
+ aliases + watch mode); only the Firefox rendering happens in the
38
+ container, over a WebSocket. Editing tests never needs an image rebuild.
39
+
34
40
  `screentest init` creates:
35
41
 
36
- - `Dockerfile.tests` — playwright-noble + your project deps + vitest CMD
37
- (auto-picked for pnpm / npm / yarn based on your lockfile)
38
42
  - `vitest.screentest.config.ts` — separate vitest config wired with the
39
43
  package's globalSetup. Kept under its own name so your normal
40
44
  `vitest.config.ts` (unit tests) is untouched.
@@ -49,33 +53,38 @@ and screenshot tests via `screentest test` stay completely separate.
49
53
  ## Commands
50
54
 
51
55
  ```bash
52
- screentest <doc-json-path> [--port 5174] [--no-open]
53
- [--worker-url URL] [--token TOKEN]
56
+ screentest serve # start the shared Firefox browser-server daemon
57
+ screentest stop # stop it
58
+ screentest status # is it running?
54
59
  ```
55
60
 
56
- Open the review UI on a pre-built `doc.json`. Used internally by `screentest
57
- test` and `screentest review`.
58
-
59
61
  ```bash
60
- screentest test [--host]
62
+ screentest test
61
63
  ```
62
64
 
63
- Default workflow: run vitest **inside Docker** (network=host), and on failure
64
- auto-launch the review UI. `--host` runs vitest on the host instead (debug
65
- only bytes diverge from your CI baseline). Set `CI=1` to skip the auto-UI
66
- launch.
65
+ Run vitest on the host, connect to the daemon for browser rendering.
66
+ On failure (or new snapshots) auto-launch the review UI. Set `CI=1` to
67
+ skip the auto-UI and just propagate the exit code.
67
68
 
68
69
  ```bash
69
70
  screentest review
70
71
  ```
71
72
 
72
- Skip vitest, just regenerate `doc.json` from cached actuals and open the UI.
73
+ Skip vitest, regenerate `doc.json` from cached actuals, open the UI.
73
74
 
74
75
  ```bash
75
76
  screentest init
76
77
  ```
77
78
 
78
- Scaffold Dockerfile + vitest config + example test (see above).
79
+ Scaffold vitest config + example test (see above).
80
+
81
+ ```bash
82
+ screentest <doc-json-path> [--port 5174] [--no-open]
83
+ [--worker-url URL] [--token TOKEN]
84
+ ```
85
+
86
+ Open the review UI on a pre-built `doc.json`. Used internally by
87
+ `screentest test` and `screentest review`.
79
88
 
80
89
  ## Writing tests
81
90
 
@@ -102,26 +111,33 @@ describe('team', () => {
102
111
  await page.goto(`${APP_URL}/team`);
103
112
  await page.locator('input[name="username"]').waitFor({ state: 'visible' });
104
113
  await compareSnapshot(page, 'login'); // → team / login flow / login
114
+
115
+ // Snapshot just one element instead of the whole page:
116
+ await compareSnapshot(page.locator('header'), 'header');
105
117
  });
106
118
  });
107
119
  ```
108
120
 
109
- Snapshot paths are auto-derived from `describe(...)` + `it(...)`. The
110
- hashes are stored in `snapshot.json` at your project root; actuals + the
111
- generated `doc.json` go to `node_modules/.cache/screentest/` (gitignored
112
- by convention).
121
+ Snapshot paths are auto-derived from `describe(...)` + `it(...)` plus the
122
+ `compareSnapshot` leaf name. Hashes go into `tests/snapshot.json` by
123
+ default; override with `SCREENTEST_SNAPSHOT_FILE=path/to/snapshot.json`.
124
+ Actuals + the generated `doc.json` go to
125
+ `node_modules/.cache/screentest/` (gitignored by convention).
126
+
127
+ > **Upgrading from < 0.3:** an existing `<projectRoot>/snapshot.json` keeps
128
+ > working — the runner picks it up if `tests/snapshot.json` isn't there yet.
113
129
 
114
130
  ## Docker Desktop host networking
115
131
 
116
- `screentest test` uses `--network=host` so the container can reach your
117
- app at `localhost:*`. On macOS / Windows Docker Desktop enable it once:
118
- `Settings → Resources → Network → Enable host networking`. On Linux Docker
119
- (CI) it works out of the box.
132
+ The daemon container uses `--network=host` so its Firefox can reach
133
+ your app at `localhost:*`. On macOS / Windows Docker Desktop enable it
134
+ once: `Settings → Resources → Network → Enable host networking`. On
135
+ Linux Docker (CI) it works out of the box.
120
136
 
121
137
  ## Cloudflare Worker (blob store)
122
138
 
123
- Accepted screenshots are stored in your Cloudflare Worker (R2-backed). See
124
- the [worker template](https://github.com/x-cevek/screentest/tree/main/cloudflare-worker)
139
+ Accepted screenshots are stored in your Cloudflare Worker (R2-backed).
140
+ See the [worker template](https://github.com/x-cevek/screentest/tree/main/cloudflare-worker)
125
141
  for a 100-line implementation + `wrangler deploy` instructions.
126
142
 
127
143
  Once deployed:
@@ -136,12 +152,12 @@ Or pass `--worker-url` / `--token` to `screentest` directly.
136
152
  ## CI
137
153
 
138
154
  ```yaml
139
- - run: docker build -f Dockerfile.tests -t screentest-tests .
155
+ - run: npx screentest serve # builds image + starts daemon
140
156
  - run: CI=1 npx screentest test
141
157
  ```
142
158
 
143
- In `CI=1` the orchestrator exits with vitest's code and never tries to open
144
- the UI.
159
+ In `CI=1` the orchestrator exits with vitest's code and never tries to
160
+ open the UI.
145
161
 
146
162
  ## Input format reference
147
163
 
@@ -2,6 +2,13 @@
2
2
  import { firefox } from "playwright";
3
3
  var server;
4
4
  async function setup(project) {
5
+ const externalWs = process.env.SCREENTEST_FIREFOX_WS;
6
+ if (externalWs) {
7
+ project.provide("wsEndpoint", externalWs);
8
+ console.log(`[screentest] using external firefox daemon: ${externalWs}`);
9
+ return async () => {
10
+ };
11
+ }
5
12
  server = await firefox.launchServer();
6
13
  const wsEndpoint = server.wsEndpoint();
7
14
  project.provide("wsEndpoint", wsEndpoint);