@recursica/adapter-tester 4.0.0 → 5.0.0

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/dist/cli.js CHANGED
@@ -1,209 +1,255 @@
1
1
  #!/usr/bin/env node
2
- import { spawn as F, spawnSync as B } from "node:child_process";
3
- import { readFileSync as S, existsSync as M, mkdirSync as W, writeFileSync as A } from "node:fs";
4
- import { dirname as I, join as a, resolve as E } from "node:path";
5
- import { fileURLToPath as V, pathToFileURL as q } from "node:url";
6
- import H from "node:net";
7
- import K from "express";
8
- import { createProxyMiddleware as Y } from "http-proxy-middleware";
9
- import { m as X } from "./mantineSourceOfTruth-BUkqMNEo.js";
10
- import { a as z, i as Q } from "./index-DqQzFSAH.js";
11
- const j = I(V(import.meta.url));
12
- function O(t) {
13
- return new Promise((r) => {
14
- const e = new H.Socket();
15
- e.setTimeout(200), e.once("connect", () => {
16
- e.destroy(), r(!0);
17
- }), e.once("timeout", () => {
18
- e.destroy(), r(!1);
19
- }), e.once("error", () => {
20
- e.destroy(), r(!1);
21
- }), e.connect(t, "127.0.0.1");
2
+ import { spawn as _, spawnSync as q } from "node:child_process";
3
+ import { readFileSync as S, mkdirSync as F, writeFileSync as O, existsSync as I } from "node:fs";
4
+ import { dirname as D, join as a, resolve as j } from "node:path";
5
+ import { fileURLToPath as M, pathToFileURL as H } from "node:url";
6
+ import W from "express";
7
+ import { createProxyMiddleware as B } from "http-proxy-middleware";
8
+ import K from "node:net";
9
+ import { m as X } from "./mantineSourceOfTruth-DE7XOgea.js";
10
+ import { a as Y, i as z } from "./index-DqQzFSAH.js";
11
+ const Q = /\x1b\[[0-9;]*m/g, Z = /Local:\s*(https?:\/\/localhost:\d+)/;
12
+ function ee(e) {
13
+ return new Promise((t) => {
14
+ const r = new K.Socket();
15
+ r.setTimeout(200), r.once("connect", () => {
16
+ r.destroy(), t(!0);
17
+ }), r.once("timeout", () => {
18
+ r.destroy(), t(!1);
19
+ }), r.once("error", () => {
20
+ r.destroy(), t(!1);
21
+ }), r.connect(e, "127.0.0.1");
22
22
  });
23
23
  }
24
- async function $(t, r = 6e4) {
25
- const e = Date.now();
26
- for (; Date.now() - e < r; ) {
27
- if (await O(t)) return !0;
28
- await new Promise((o) => setTimeout(o, 500));
24
+ function te(e) {
25
+ try {
26
+ const t = JSON.parse(S(e, "utf8")).port;
27
+ return typeof t == "number" ? t : void 0;
28
+ } catch {
29
+ return;
29
30
  }
30
- return !1;
31
31
  }
32
- function N(t) {
33
- return Number(new URL(t).port);
32
+ function re(e, t) {
33
+ F(D(e), { recursive: !0 }), O(e, JSON.stringify({ port: t }));
34
34
  }
35
- function L(t, r) {
36
- var o, s;
37
- console.log(
38
- `[Dev Launcher] Port ${r.port} is inactive. Launching Storybook for ${t}...`
39
- );
40
- const e = F(r.command, {
41
- cwd: r.cwd,
42
- stdio: "pipe",
43
- shell: !0
44
- });
45
- return (o = e.stdout) == null || o.on("data", (n) => {
46
- for (const p of n.toString().split(`
47
- `))
48
- p.trim() && console.log(`[${t} SB] ${p.trim()}`);
49
- }), (s = e.stderr) == null || s.on("data", (n) => {
50
- for (const p of n.toString().split(`
35
+ function oe(e, t) {
36
+ return new Promise((r, o) => {
37
+ var y, w;
38
+ const s = _(e.command, {
39
+ cwd: e.cwd,
40
+ stdio: "pipe",
41
+ shell: !0
42
+ });
43
+ let n = !1;
44
+ const d = setTimeout(() => {
45
+ n || (n = !0, s.kill(), o(
46
+ new Error(
47
+ `Timed out after ${t}ms waiting for ${e.name}'s Storybook to report its URL (no "Local: http://localhost:<port>" line seen in its output).`
48
+ )
49
+ ));
50
+ }, t), h = (i, u) => {
51
+ const l = i.toString();
52
+ for (const c of l.split(`
51
53
  `))
52
- p.trim() && console.error(`[${t} SB ERROR] ${p.trim()}`);
53
- }), e.on("error", (n) => {
54
- console.error(`[${t} SB ERROR] Failed to start process:`, n);
55
- }), e;
54
+ if (c.trim()) {
55
+ const p = u ? `${e.name} SB ERROR` : `${e.name} SB`;
56
+ (u ? console.error : console.log)(`[${p}] ${c.trim()}`);
57
+ }
58
+ if (n) return;
59
+ const v = l.replace(Q, "").match(Z);
60
+ if (v) {
61
+ n = !0, clearTimeout(d);
62
+ const c = v[1], p = Number(new URL(c).port);
63
+ re(e.cacheFile, p), r({ url: c, port: p, process: s });
64
+ }
65
+ };
66
+ (y = s.stdout) == null || y.on("data", (i) => h(i, !1)), (w = s.stderr) == null || w.on("data", (i) => h(i, !0)), s.on("error", (i) => {
67
+ n || (n = !0, clearTimeout(d), o(i));
68
+ }), s.on("exit", (i) => {
69
+ n || (n = !0, clearTimeout(d), o(
70
+ new Error(
71
+ `${e.name}'s Storybook exited (code ${i}) before reporting its URL.`
72
+ )
73
+ ));
74
+ });
75
+ });
56
76
  }
57
- function Z(t) {
58
- const r = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
59
- console.log(`[Dev Launcher] Auto-launching browser: ${t}`), F(r, [t], { shell: process.platform === "win32" }).on(
77
+ function x(e, t) {
78
+ return {
79
+ name: e,
80
+ command: t.command,
81
+ cwd: t.cwd,
82
+ reuseExistingServer: t.reuseExistingServer,
83
+ cacheFile: t.cacheFile,
84
+ timeoutMs: t.timeout
85
+ };
86
+ }
87
+ async function A(e) {
88
+ if (e.reuseExistingServer) {
89
+ const t = te(e.cacheFile);
90
+ if (t !== void 0 && await ee(t))
91
+ return console.log(
92
+ `[Dev Launcher] ${e.name} is already running on port ${t} (reused).`
93
+ ), {
94
+ url: `http://localhost:${t}`,
95
+ port: t,
96
+ process: null
97
+ };
98
+ }
99
+ return console.log(`[Dev Launcher] Launching Storybook for ${e.name}...`), oe(e, e.timeoutMs ?? 120 * 1e3);
100
+ }
101
+ const N = D(M(import.meta.url));
102
+ function se(e) {
103
+ const t = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
104
+ console.log(`[Dev Launcher] Auto-launching browser: ${e}`), _(t, [e], { shell: process.platform === "win32" }).on(
60
105
  "error",
61
- (e) => {
62
- console.error("[Dev Launcher] Failed to auto-launch browser:", e);
106
+ (r) => {
107
+ console.error("[Dev Launcher] Failed to auto-launch browser:", r);
63
108
  }
64
109
  );
65
110
  }
66
- function ee(t, r, e = {}) {
67
- const [o, s] = t.targets, [n, p] = r;
68
- if (!(o != null && o.sourceOfTruth) || !s || s.sourceOfTruth || !n || !p)
111
+ async function ne(e, t, r = {}) {
112
+ const [o, s] = e.targets, [n, d] = t;
113
+ if (!(o != null && o.sourceOfTruth) || !s || s.sourceOfTruth || !n || !d)
69
114
  throw new Error(
70
115
  "adapter-tester dev mode requires exactly two targets: [sourceOfTruth, target] — check adapter-tester.config.json."
71
116
  );
72
- const y = e.port ?? 6010, f = N(o.url), m = N(s.url), i = K(), b = a(j, "../public"), w = a(j, "../report-header.txt");
73
- i.get("/", (d, l, c) => {
74
- if (d.query.path) {
75
- c();
117
+ const h = r.port ?? 6010;
118
+ console.log(
119
+ `[Dev Launcher] Resolving ${o.name} and ${s.name} Storybooks...`
120
+ );
121
+ const [y, w] = await Promise.all([
122
+ A(
123
+ x(o.name, n)
124
+ ),
125
+ A(x(s.name, d))
126
+ ]);
127
+ console.log("[Dev Launcher] Both Storybooks are active and responsive!");
128
+ const i = [y.process, w.process].filter(
129
+ (f) => f !== null
130
+ ), u = W(), l = a(N, "../public"), v = a(N, "../report-header.txt");
131
+ u.get("/", (f, T, b) => {
132
+ if (f.query.path) {
133
+ b();
76
134
  return;
77
135
  }
78
- const x = S(a(b, "index.html"), "utf8").replace(
136
+ const J = S(a(l, "index.html"), "utf8").replace(
79
137
  "<head>",
80
138
  `<head>
81
139
  <script>window.__ADAPTER_TESTER__ = ${JSON.stringify({
82
140
  ownName: s.name,
83
141
  sourceOfTruthName: o.name,
84
- sourceOfTruthPort: f
142
+ sourceOfTruthPort: y.port
85
143
  })};<\/script>`
86
144
  );
87
- l.send(x);
88
- }), i.get("/report-header.txt", (d, l) => {
145
+ T.send(J);
146
+ }), u.get("/report-header.txt", (f, T) => {
89
147
  try {
90
- l.type("text/plain").send(S(w, "utf8"));
148
+ T.type("text/plain").send(S(v, "utf8"));
91
149
  } catch {
92
- l.status(500).send("Error loading report-header.txt");
150
+ T.status(500).send("Error loading report-header.txt");
93
151
  }
94
- }), i.use(
152
+ }), u.use(
95
153
  "/",
96
- Y({
97
- target: `http://localhost:${m}`,
154
+ B({
155
+ target: w.url,
98
156
  changeOrigin: !0,
99
157
  ws: !0
100
158
  })
101
159
  );
102
- const g = [];
103
- let v = !1;
104
- const k = () => {
105
- if (!v) {
106
- v = !0, console.log(
160
+ let c = !1;
161
+ const p = () => {
162
+ if (!c) {
163
+ c = !0, console.log(
107
164
  `
108
165
  [Dev Launcher] Shutting down Dev Mode server and spawned Storybooks...`
109
166
  );
110
- for (const d of g) d.kill("SIGINT");
167
+ for (const f of i) f.kill("SIGINT");
111
168
  process.exit(0);
112
169
  }
113
170
  };
114
- process.on("SIGINT", k), process.on("SIGTERM", k), i.listen(y, async () => {
171
+ process.on("SIGINT", p), process.on("SIGTERM", p), u.listen(h, () => {
115
172
  console.log(`
116
173
  ====================================================
117
174
  🚀 Adapter Dev Mode proxy running at:
118
- http://localhost:${y}
175
+ http://localhost:${h}
119
176
  ====================================================
120
- `);
121
- const [d, l] = await Promise.all([
122
- O(f),
123
- O(m)
124
- ]);
125
- d ? console.log(
126
- `[Dev Launcher] ${o.name} is already running on port ${f}.`
127
- ) : g.push(L(o.name, n)), l ? console.log(
128
- `[Dev Launcher] ${s.name} is already running on port ${m}.`
129
- ) : g.push(L(s.name, p));
130
- const c = [];
131
- d || c.push($(f)), l || c.push($(m)), c.length > 0 ? (console.log("[Dev Launcher] Waiting for Storybooks to be responsive..."), (await Promise.all(c)).every(Boolean) ? console.log("[Dev Launcher] All Storybooks are active and responsive!") : console.warn(
132
- "[Dev Launcher] Warning: some Storybooks timed out during startup, but proceeding..."
133
- )) : console.log("[Dev Launcher] Both Storybooks already active."), Z(`http://localhost:${y}`);
177
+ `), se(`http://localhost:${h}`);
134
178
  });
135
179
  }
136
- const te = "http://json-schema.org/draft-07/schema#", re = "https://github.com/borderux/recursica/tree/main/packages/adapter-tester/src/adapter-tester.schema.json", oe = "adapter-tester.config.json", se = "Configuration for @recursica/adapter-tester. All fields are optional — an adapter repo with a normal `storybook` npm script needs no config file at all.", ne = "object", ie = !1, ae = { $schema: { type: "string", description: 'Optional pointer to this schema for editor autocomplete, e.g. "https://raw.githubusercontent.com/borderux/recursica/main/packages/adapter-tester/src/adapter-tester.schema.json".' }, name: { type: "string", description: `Label for this project's own target. Defaults to the unscoped name in this project's package.json (e.g. "@recursica/some-adapter" -> "some-adapter").` }, storybook: { type: "object", additionalProperties: !1, description: "This project's own Storybook target.", properties: { port: { type: "integer", minimum: 1, maximum: 65535, description: "Port the target's Storybook is served on. Auto-detected from this project's own `scripts.storybook` (a `-p <port>`/`--port <port>` flag) when omitted, falling back to Storybook's own default of 6006." }, command: { type: "string", description: "Command that boots the target's Storybook. Defaults to `npm run storybook`." }, cwd: { type: "string", description: 'Directory the command runs in, relative to the config file. Defaults to ".".' } } }, sourceOfTruth: { description: 'The comparison target. Defaults to `{ "type": "mantine-harness" }`.', oneOf: [{ type: "object", additionalProperties: !1, description: "Default mode: boots a throwaway harness that installs the published @recursica/mantine-adapter from npm — no monorepo checkout required.", properties: { type: { const: "mantine-harness" }, port: { type: "integer", minimum: 1, maximum: 65535, description: "Port the throwaway harness's Storybook is served on. Defaults to 6011." }, mantineAdapterVersion: { type: "string", description: "npm version/tag of @recursica/mantine-adapter to install in the harness. Defaults to `latest`." }, storybookTemplateVersion: { type: "string", description: "npm version/tag of @recursica/storybook-template to install in the harness. Defaults to `latest`." } } }, { type: "object", additionalProperties: !1, description: "Non-standard mode: points at an already-addressable Storybook — e.g. a sibling workspace package's own Storybook inside this monorepo.", required: ["type", "port"], properties: { type: { const: "url" }, name: { type: "string", description: 'Label for the source-of-truth target. Defaults to "Mantine".' }, port: { type: "integer", minimum: 1, maximum: 65535, description: "Port the source-of-truth Storybook is served on." }, command: { type: "string", description: "Command that boots the source-of-truth Storybook. Defaults to `npm run storybook`." }, cwd: { type: "string", description: 'Directory the command runs in, relative to the config file. Defaults to ".".' } } }] }, isSourceOfTruthAdapter: { type: "boolean", description: "True only for the source-of-truth adapter's own config (mantine-adapter). Skips `sourceOfTruth` entirely — there's nothing above it to diverge from — and runs the own-drift golden check standalone, against just this project's own Storybook. Defaults to false." }, diffThresholdPixels: { type: "number", minimum: 0, description: "Global visual diff threshold, in mismatched pixels, before a story is considered a failure. Defaults to 3500. AI agents must not modify this field — see AGENT.md." }, stories: { type: "object", additionalProperties: { type: "object", additionalProperties: !1, properties: { threshold: { type: "number", minimum: 0, description: "Diff threshold override for matching stories, in mismatched pixels. Overrides `diffThresholdPixels`." }, exclude: { type: "boolean", description: "Skip matching stories entirely — no own-drift check, no divergence check, no golden captured. For stories that don't have a cross-adapter counterpart; use `excludeTitlePrefixes` to drop a whole title instead." } } }, description: "Per-story overrides, keyed by story id prefix (a story matches if its id equals the key or starts with it). When more than one key matches a story, the longest (most specific) key wins." }, excludeTitlePrefixes: { type: "array", items: { type: "string" }, description: "Storybook title prefixes to exclude from comparison, in addition to the built-in denylist (`Theme/*`, `Tokens/*`, `Introduction`)." } }, ce = {
137
- $schema: te,
138
- $id: re,
139
- title: oe,
140
- description: se,
141
- type: ne,
142
- additionalProperties: ie,
143
- properties: ae
144
- }, pe = Q, U = new z.Ajv({ allErrors: !0, strict: !0 });
145
- pe(U);
146
- const R = U.compile(ce);
147
- function de(t, r) {
148
- if (R(t)) return;
149
- const e = (R.errors ?? []).map((o) => {
180
+ const ie = "http://json-schema.org/draft-07/schema#", ae = "https://github.com/borderux/recursica/tree/main/packages/adapter-tester/src/adapter-tester.schema.json", ce = "adapter-tester.config.json", ue = "Configuration for @recursica/adapter-tester. All fields are optional — an adapter repo with a normal `storybook` npm script needs no config file at all.", de = "object", le = !1, pe = { $schema: { type: "string", description: 'Optional pointer to this schema for editor autocomplete, e.g. "https://raw.githubusercontent.com/borderux/recursica/main/packages/adapter-tester/src/adapter-tester.schema.json".' }, name: { type: "string", description: `Label for this project's own target. Defaults to the unscoped name in this project's package.json (e.g. "@recursica/some-adapter" -> "some-adapter").` }, storybook: { type: "object", additionalProperties: !1, description: "This project's own Storybook target.", properties: { port: { type: "integer", minimum: 1, maximum: 65535, description: "First-guess port only, not authoritative — the real port is auto-detected from this Storybook's own startup output, since Storybook silently falls back to an OS-assigned port whenever this one is taken. Auto-detected from this project's own `scripts.storybook` (a `-p <port>`/`--port <port>` flag) when omitted, falling back to 6006." }, command: { type: "string", description: "Command that boots the target's Storybook. Defaults to `npm run storybook`." }, cwd: { type: "string", description: 'Directory the command runs in, relative to the config file. Defaults to ".".' } } }, sourceOfTruth: { description: 'The comparison target. Defaults to `{ "type": "mantine-harness" }`.', oneOf: [{ type: "object", additionalProperties: !1, description: "Default mode: boots a throwaway harness that installs the published @recursica/mantine-adapter from npm — no monorepo checkout required.", properties: { type: { const: "mantine-harness" }, port: { type: "integer", minimum: 1, maximum: 65535, description: "First-guess port only, not authoritative — the real port is auto-detected from the throwaway harness's Storybook's own startup output." }, mantineAdapterVersion: { type: "string", description: "npm version/tag of @recursica/mantine-adapter to install in the harness. Defaults to `latest`." }, storybookTemplateVersion: { type: "string", description: "npm version/tag of @recursica/storybook-template to install in the harness. Defaults to `latest`." } } }, { type: "object", additionalProperties: !1, description: "Non-standard mode: points at an already-addressable Storybook — e.g. a sibling workspace package's own Storybook inside this monorepo.", required: ["type"], properties: { type: { const: "url" }, name: { type: "string", description: 'Label for the source-of-truth target. Defaults to "Mantine".' }, port: { type: "integer", minimum: 1, maximum: 65535, description: "First-guess port only, not authoritative — the real port is auto-detected from the source-of-truth Storybook's own startup output. Defaults to 6011." }, command: { type: "string", description: "Command that boots the source-of-truth Storybook. Defaults to `npm run storybook`." }, cwd: { type: "string", description: 'Directory the command runs in, relative to the config file. Defaults to ".".' } } }] }, isSourceOfTruthAdapter: { type: "boolean", description: "True only for the source-of-truth adapter's own config (mantine-adapter). Skips `sourceOfTruth` entirely — there's nothing above it to diverge from — and runs the own-drift golden check standalone, against just this project's own Storybook. Defaults to false." }, goldenThresholdPixels: { type: "number", minimum: 0, description: "Global visual diff threshold for the own-drift check (this project's live render vs. its own committed `test/golden/` image), in mismatched pixels, before a story is considered a failure. Same library/component on both sides, so this should stay tight. Defaults to 10. AI agents must not modify this field — see AGENT.md.", default: 10 }, sourceOfTruthThresholdPixels: { type: "number", minimum: 0, description: "Global visual diff threshold for the source-of-truth divergence check (this project's golden vs. the source-of-truth adapter's golden), in mismatched pixels, before a difference is flagged. Comparing across two different component libraries has legitimate structural variation (native control widgets, font rendering, etc.), so this is expected to be set much higher than `goldenThresholdPixels`. Ignored on the source-of-truth adapter's own config (`isSourceOfTruthAdapter: true`), which has no divergence check. Defaults to 3500. AI agents must not modify this field — see AGENT.md.", default: 3500 }, stories: { type: "object", additionalProperties: { type: "object", additionalProperties: !1, properties: { goldenThreshold: { type: "number", minimum: 0, description: "Diff threshold override for matching stories' own-drift check, in mismatched pixels. Overrides `goldenThresholdPixels`." }, sourceOfTruthThreshold: { type: "number", minimum: 0, description: "Diff threshold override for matching stories' source-of-truth divergence check, in mismatched pixels. Overrides `sourceOfTruthThresholdPixels`." }, exclude: { type: "boolean", description: "Skip matching stories entirely — no own-drift check, no divergence check, no golden captured. For stories that don't have a cross-adapter counterpart; use `excludeTitlePrefixes` to drop a whole title instead." } } }, description: "Per-story overrides, keyed by story id prefix (a story matches if its id equals the key or starts with it). When more than one key matches a story, the longest (most specific) key wins." }, excludeTitlePrefixes: { type: "array", items: { type: "string" }, description: "Storybook title prefixes to exclude from comparison, in addition to the built-in denylist (`Theme/*`, `Tokens/*`, `Introduction`)." } }, he = {
181
+ $schema: ie,
182
+ $id: ae,
183
+ title: ce,
184
+ description: ue,
185
+ type: de,
186
+ additionalProperties: le,
187
+ properties: pe
188
+ }, fe = z, U = new Y.Ajv({ allErrors: !0, strict: !0 });
189
+ fe(U);
190
+ const $ = U.compile(he);
191
+ function me(e, t) {
192
+ if ($(e)) return;
193
+ const r = ($.errors ?? []).map((o) => {
150
194
  var n;
151
195
  const s = (n = o.params) != null && n.additionalProperty ? ` '${o.params.additionalProperty}'` : "";
152
196
  return ` - ${o.instancePath || "root"} ${o.message}${s}`;
153
197
  }).join(`
154
198
  `);
155
- throw new Error(`Invalid ${r}:
156
- ${e}`);
199
+ throw new Error(`Invalid ${t}:
200
+ ${r}`);
157
201
  }
158
- const le = "@recursica/mantine-adapter", ue = "adapter-tester.config.json", C = "npm run storybook", he = 6006, fe = 6011, _ = "Mantine", me = 3500;
159
- function G(t) {
160
- const r = a(t, "package.json");
161
- if (!M(r))
202
+ const ge = "@recursica/mantine-adapter", ye = "adapter-tester.config.json", L = "npm run storybook", we = 6006, C = 6011, R = "Mantine", ve = 10, Te = 3500;
203
+ function G(e) {
204
+ const t = a(e, "package.json");
205
+ if (!I(t))
162
206
  throw new Error(
163
- `No package.json found in ${t} — run adapter-tester from the root of the project being tested.`
207
+ `No package.json found in ${e} — run adapter-tester from the root of the project being tested.`
164
208
  );
165
- return JSON.parse(S(r, "utf8"));
209
+ return JSON.parse(S(t, "utf8"));
166
210
  }
167
- function ge(t) {
211
+ function be(e) {
168
212
  var s;
169
- const e = (s = G(t).scripts) == null ? void 0 : s.storybook, o = e == null ? void 0 : e.match(/(?:-p|--port)[ =](\d+)/);
170
- return o ? Number(o[1]) : he;
213
+ const r = (s = G(e).scripts) == null ? void 0 : s.storybook, o = r == null ? void 0 : r.match(/(?:-p|--port)[ =](\d+)/);
214
+ return o ? Number(o[1]) : we;
171
215
  }
172
- function ye(t) {
173
- const e = G(t).name;
174
- return e ? e.split("/").pop() : "Adapter";
216
+ function Se(e) {
217
+ const r = G(e).name;
218
+ return r ? r.split("/").pop() : "Adapter";
175
219
  }
176
- function we(t) {
177
- const r = a(t, ue);
178
- if (!M(r))
220
+ function ke(e) {
221
+ const t = a(e, ye);
222
+ if (!I(t))
179
223
  return {};
180
- const e = JSON.parse(S(r, "utf8"));
181
- return de(e, r), e;
224
+ const r = JSON.parse(S(t, "utf8"));
225
+ return me(r, t), r;
182
226
  }
183
- function ve(t, r = {}) {
184
- var k, d, l;
185
- const e = we(t), o = e.isSourceOfTruthAdapter ?? !1;
186
- if (r.mantineAdapterVersion && o)
227
+ function Oe(e, t = {}) {
228
+ var p, f, T;
229
+ const r = ke(e), o = r.isSourceOfTruthAdapter ?? !1;
230
+ if (t.mantineAdapterVersion && o)
187
231
  throw new Error(
188
232
  "--source-of-truth-version has no effect on the source-of-truth adapter's own config (isSourceOfTruthAdapter: true) — there's nothing to pin a version for."
189
233
  );
190
- const s = e.name ?? ye(t), n = ((k = e.storybook) == null ? void 0 : k.port) ?? ge(t), p = ((d = e.storybook) == null ? void 0 : d.command) ?? C, y = E(t, ((l = e.storybook) == null ? void 0 : l.cwd) ?? "."), f = {
191
- command: p,
234
+ const s = r.name ?? Se(e), n = ((p = r.storybook) == null ? void 0 : p.port) ?? be(e), d = ((f = r.storybook) == null ? void 0 : f.command) ?? L, h = j(e, ((T = r.storybook) == null ? void 0 : T.cwd) ?? "."), y = {
235
+ command: d,
192
236
  port: n,
193
- cwd: y,
237
+ cwd: h,
194
238
  reuseExistingServer: !process.env.CI,
239
+ cacheFile: a(e, ".adapter-tester", "last-port-own.json"),
195
240
  timeout: 120 * 1e3
196
- }, m = {
197
- diffThresholdPixels: e.diffThresholdPixels ?? me,
198
- stories: e.stories,
199
- excludeTitlePrefixes: e.excludeTitlePrefixes,
241
+ }, w = {
242
+ goldenThresholdPixels: r.goldenThresholdPixels ?? ve,
243
+ sourceOfTruthThresholdPixels: r.sourceOfTruthThresholdPixels ?? Te,
244
+ stories: r.stories,
245
+ excludeTitlePrefixes: r.excludeTitlePrefixes,
200
246
  // Keyed off `ownCwd`, not `cwd` — the project actually being tested, not
201
247
  // wherever the config file happens to live. Matters whenever
202
248
  // `storybook.cwd` points at a sibling package: its goldens must resolve
203
249
  // to that package's own `test/golden/` (the same directory used when
204
250
  // that package runs adapter-tester directly), not a directory under
205
251
  // wherever this config file lives.
206
- goldenDir: a(y, "test", "golden"),
252
+ goldenDir: a(h, "test", "golden"),
207
253
  isSourceOfTruthAdapter: o,
208
254
  // Overwritten by the CLI from --update-golden/--approve-divergence.
209
255
  goldenMode: "check",
@@ -213,116 +259,133 @@ function ve(t, r = {}) {
213
259
  if (o)
214
260
  return {
215
261
  engineConfig: {
216
- ...m,
262
+ ...w,
217
263
  targets: [{ name: s, url: `http://localhost:${n}` }]
218
264
  },
219
- webServers: [f]
265
+ webServers: [y]
220
266
  };
221
- const i = e.sourceOfTruth ?? {
267
+ const i = r.sourceOfTruth ?? {
222
268
  type: "mantine-harness"
223
269
  };
224
- let b, w, g, v;
270
+ let u, l, v, c;
225
271
  if (i.type === "url") {
226
- if (r.mantineAdapterVersion)
272
+ if (t.mantineAdapterVersion)
227
273
  throw new Error(
228
274
  `--source-of-truth-version has no effect with sourceOfTruth.type: "url" — that mode reads a sibling package's local checkout directly, not a published version.`
229
275
  );
230
- b = i.name ?? _, w = i.port;
231
- const c = E(t, i.cwd ?? ".");
232
- g = {
233
- command: i.command ?? C,
234
- port: i.port,
235
- cwd: c,
276
+ u = i.name ?? R, l = i.port ?? C;
277
+ const b = j(e, i.cwd ?? ".");
278
+ v = {
279
+ command: i.command ?? L,
280
+ port: l,
281
+ cwd: b,
236
282
  reuseExistingServer: !process.env.CI,
283
+ cacheFile: a(e, ".adapter-tester", "last-port-source-of-truth.json"),
237
284
  timeout: 120 * 1e3
238
- }, v = {
285
+ }, c = {
239
286
  type: "local",
240
- dir: a(c, "test", "golden")
287
+ dir: a(b, "test", "golden")
241
288
  };
242
289
  } else {
243
- b = _, w = i.port ?? fe;
244
- const c = r.mantineAdapterVersion ?? i.mantineAdapterVersion;
245
- g = X({
246
- dir: a(t, ".adapter-tester/mantine-harness"),
247
- port: w,
248
- mantineAdapterVersion: c,
290
+ u = R, l = i.port ?? C;
291
+ const b = t.mantineAdapterVersion ?? i.mantineAdapterVersion;
292
+ v = X({
293
+ dir: a(e, ".adapter-tester/mantine-harness"),
294
+ port: l,
295
+ mantineAdapterVersion: b,
249
296
  storybookTemplateVersion: i.storybookTemplateVersion
250
- }), v = {
297
+ }), c = {
251
298
  type: "npm",
252
- packageName: le,
253
- versionSpec: c ?? "latest",
254
- cacheDir: a(t, ".adapter-tester/mantine-golden-cache")
299
+ packageName: ge,
300
+ versionSpec: b ?? "latest",
301
+ cacheDir: a(e, ".adapter-tester/mantine-golden-cache")
255
302
  };
256
303
  }
257
304
  return {
258
305
  engineConfig: {
259
- ...m,
306
+ ...w,
260
307
  targets: [
261
308
  {
262
- name: b,
263
- url: `http://localhost:${w}`,
309
+ name: u,
310
+ url: `http://localhost:${l}`,
264
311
  sourceOfTruth: !0
265
312
  },
266
313
  { name: s, url: `http://localhost:${n}` }
267
314
  ],
268
- sourceOfTruthGolden: v
315
+ sourceOfTruthGolden: c
269
316
  },
270
317
  // [sourceOfTruth, own] — Dev Mode needs both; the automated golden run
271
318
  // (cli.ts) only ever boots the last entry, since its divergence check
272
319
  // reads stored golden files, not a live source-of-truth page.
273
- webServers: [g, f]
320
+ webServers: [v, y]
274
321
  };
275
322
  }
276
- const be = I(V(import.meta.url)), ke = q(a(be, "testing.js")).href, h = process.argv.slice(2);
277
- let J;
278
- const T = h.indexOf("--source-of-truth-version");
279
- if (T !== -1) {
280
- const t = h[T + 1];
281
- if (t === void 0 || t.startsWith("--"))
323
+ const xe = D(M(import.meta.url)), Ae = H(a(xe, "testing.js")).href, g = process.argv.slice(2);
324
+ let V;
325
+ const k = g.indexOf("--source-of-truth-version");
326
+ if (k !== -1) {
327
+ const e = g[k + 1];
328
+ if (e === void 0 || e.startsWith("--"))
282
329
  throw new Error(
283
330
  "--source-of-truth-version requires a value, e.g. --source-of-truth-version 0.53.0"
284
331
  );
285
- J = t, h.splice(T, 2);
332
+ V = e, g.splice(k, 2);
286
333
  }
287
- const P = process.cwd(), { engineConfig: u, webServers: D } = ve(P, {
288
- mantineAdapterVersion: J
334
+ const E = process.cwd(), { engineConfig: m, webServers: P } = Oe(E, {
335
+ mantineAdapterVersion: V
289
336
  });
290
- h.includes("--update-golden") ? u.goldenMode = "update-golden" : h.includes("--approve-divergence") && (u.goldenMode = "approve-divergence");
291
- if (h.includes("--divergence-only")) {
292
- if (u.isSourceOfTruthAdapter)
337
+ g.includes("--update-golden") ? m.goldenMode = "update-golden" : g.includes("--approve-divergence") && (m.goldenMode = "approve-divergence");
338
+ if (g.includes("--divergence-only")) {
339
+ if (m.isSourceOfTruthAdapter)
293
340
  throw new Error(
294
341
  "--divergence-only has nothing to diverge from — isSourceOfTruthAdapter is true in this project's adapter-tester.config.json."
295
342
  );
296
- u.checkMode = "divergence";
297
- } else if (u.goldenMode === "approve-divergence")
343
+ m.checkMode = "divergence";
344
+ } else if (m.goldenMode === "approve-divergence")
298
345
  throw new Error(
299
346
  "--approve-divergence only makes sense with --divergence-only — there's nothing to approve without the divergence check running."
300
347
  );
301
- h.includes("--dry-run") && (console.log(JSON.stringify({ engineConfig: u, webServers: D }, null, 2)), process.exit(0));
302
- const Se = /* @__PURE__ */ new Set([
348
+ g.includes("--dry-run") && (console.log(JSON.stringify({ engineConfig: m, webServers: P }, null, 2)), process.exit(0));
349
+ const Ee = /* @__PURE__ */ new Set([
303
350
  "--dry-run",
304
351
  "--serve",
305
352
  "--update-golden",
306
353
  "--approve-divergence",
307
354
  "--divergence-only"
308
- ]), Te = h.filter((t) => !Se.has(t));
309
- if (h.includes("--serve")) {
310
- if (u.isSourceOfTruthAdapter)
311
- throw new Error(
312
- "Dev Mode (--serve) has nothing to sync this project's Storybook against — isSourceOfTruthAdapter is true in this project's adapter-tester.config.json."
313
- );
314
- ee(u, D);
315
- } else
316
- Oe(D.slice(-1), u);
317
- function Oe(t, r) {
318
- const e = a(P, ".adapter-tester/run");
319
- W(e, { recursive: !0 }), A(
320
- a(e, "playwright.config.js"),
355
+ ]), Pe = g.filter((e) => !Ee.has(e));
356
+ De().catch((e) => {
357
+ console.error(e), process.exitCode = 1;
358
+ });
359
+ async function De() {
360
+ if (g.includes("--serve")) {
361
+ if (m.isSourceOfTruthAdapter)
362
+ throw new Error(
363
+ "Dev Mode (--serve) has nothing to sync this project's Storybook against — isSourceOfTruthAdapter is true in this project's adapter-tester.config.json."
364
+ );
365
+ await ne(m, P);
366
+ } else {
367
+ const e = P.at(-1);
368
+ if (!e)
369
+ throw new Error("resolveConfig() returned no webServers to boot.");
370
+ await je(e, m);
371
+ }
372
+ }
373
+ async function je(e, t) {
374
+ const r = a(E, ".adapter-tester/run");
375
+ F(r, { recursive: !0 });
376
+ const o = t.targets.at(-1);
377
+ if (!o)
378
+ throw new Error("resolveConfig() returned no targets to check.");
379
+ const { url: s, process: n } = await A(
380
+ x(o.name, e)
381
+ );
382
+ o.url = s, O(
383
+ a(r, "playwright.config.js"),
321
384
  `// Generated by \`adapter-tester\` — do not edit, regenerated on every run.
322
385
  import { defineConfig, devices } from "@playwright/test";
323
386
 
324
387
  export default defineConfig({
325
- testDir: ${JSON.stringify(e)},
388
+ testDir: ${JSON.stringify(r)},
326
389
  // Stories run across Playwright's default worker pool — each golden check
327
390
  // only reads/writes its own story's manifest.json entry, under a lock, so
328
391
  // concurrent workers never race each other (see \`updateManifestEntry\`).
@@ -333,22 +396,31 @@ export default defineConfig({
333
396
  reporter: [["html", { open: "never" }], ["list"]],
334
397
  use: { trace: "on-first-retry" },
335
398
  projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
336
- webServer: ${JSON.stringify(t, null, 2)},
399
+ // No webServer entry this project's own Storybook is already running by
400
+ // the time this config is used (see runAutomated() in cli.ts).
337
401
  });
338
402
  `
339
- ), A(
340
- a(e, "visual-regression.spec.js"),
403
+ ), O(
404
+ a(r, "visual-regression.spec.js"),
341
405
  `// Generated by \`adapter-tester\` — do not edit, regenerated on every run.
342
- import { test } from "@playwright/test";
343
- import { resolveVisualRegressionPlan } from ${JSON.stringify(ke)};
406
+ import { test, expect } from "@playwright/test";
407
+ import { resolveVisualRegressionPlan } from ${JSON.stringify(Ae)};
344
408
 
345
409
  // \`test.describe\`/\`test\` are called here, not inside resolveVisualRegressionPlan,
346
410
  // so Playwright's HTML report groups the suite under this file instead of a
347
411
  // sourcemapped path into adapter-tester's own library code.
348
- const { ownTargetName, suiteLabel, stories, checkStory } =
349
- await resolveVisualRegressionPlan(${JSON.stringify(r, null, 2)});
412
+ const { ownTargetName, suiteLabel, stories, missingFromSourceOfTruth, checkStory } =
413
+ await resolveVisualRegressionPlan(${JSON.stringify(t, null, 2)});
350
414
 
351
415
  test.describe(\`\${ownTargetName} — \${suiteLabel}\`, () => {
416
+ if (missingFromSourceOfTruth.length > 0) {
417
+ test("story parity with source of truth", () => {
418
+ expect(
419
+ missingFromSourceOfTruth,
420
+ \`\${missingFromSourceOfTruth.length} stor(y/ies) exist in the source of truth but are missing here. Add the missing story, or mark it \\\`exclude: true\\\` under \\\`stories\\\` in adapter-tester.config.json if intentional.\`,
421
+ ).toEqual([]);
422
+ });
423
+ }
352
424
  for (const story of stories) {
353
425
  test(story.id, async ({ browser }, testInfo) => {
354
426
  await checkStory(story, browser, testInfo);
@@ -357,17 +429,21 @@ test.describe(\`\${ownTargetName} — \${suiteLabel}\`, () => {
357
429
  });
358
430
  `
359
431
  );
360
- const o = B(
361
- "npx",
362
- [
363
- "playwright",
364
- "test",
365
- "--config",
366
- a(e, "playwright.config.js"),
367
- ...Te
368
- ],
369
- { stdio: "inherit", cwd: P, shell: process.platform === "win32" }
370
- );
371
- process.exit(o.status ?? 1);
432
+ try {
433
+ const d = q(
434
+ "npx",
435
+ [
436
+ "playwright",
437
+ "test",
438
+ "--config",
439
+ a(r, "playwright.config.js"),
440
+ ...Pe
441
+ ],
442
+ { stdio: "inherit", cwd: E, shell: process.platform === "win32" }
443
+ );
444
+ process.exitCode = d.status ?? 1;
445
+ } finally {
446
+ n == null || n.kill("SIGTERM");
447
+ }
372
448
  }
373
449
  //# sourceMappingURL=cli.js.map