found-pixel 0.7.0 → 0.8.0-alpha.143
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 +37 -23
- package/dist/baselines.d.ts +15 -0
- package/dist/baselines.d.ts.map +1 -0
- package/dist/baselines.js +148 -0
- package/dist/baselines.js.map +1 -0
- package/dist/bin.d.ts +1 -7
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +3 -15
- package/dist/bin.js.map +1 -1
- package/dist/capture/browser.d.ts +5 -0
- package/dist/capture/browser.d.ts.map +1 -0
- package/dist/capture/browser.js +21 -0
- package/dist/capture/browser.js.map +1 -0
- package/dist/capture/compare.d.ts +8 -0
- package/dist/capture/compare.d.ts.map +1 -0
- package/dist/capture/compare.js +40 -0
- package/dist/capture/compare.js.map +1 -0
- package/dist/capture/engine.d.ts +33 -0
- package/dist/capture/engine.d.ts.map +1 -0
- package/dist/capture/engine.js +211 -0
- package/dist/capture/engine.js.map +1 -0
- package/dist/capture/inPage.d.ts +39 -0
- package/dist/capture/inPage.d.ts.map +1 -0
- package/dist/capture/inPage.js +106 -0
- package/dist/capture/inPage.js.map +1 -0
- package/dist/capture/server.d.ts +6 -0
- package/dist/capture/server.d.ts.map +1 -0
- package/dist/capture/server.js +67 -0
- package/dist/capture/server.js.map +1 -0
- package/dist/capture/shotPlan.d.ts +25 -0
- package/dist/capture/shotPlan.d.ts.map +1 -0
- package/dist/capture/shotPlan.js +89 -0
- package/dist/capture/shotPlan.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +10 -2
- package/dist/cli.js.map +1 -1
- package/dist/comment.d.ts +2 -1
- package/dist/comment.d.ts.map +1 -1
- package/dist/comment.js +4 -1
- package/dist/comment.js.map +1 -1
- package/dist/config.d.ts +23 -93
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -38
- package/dist/config.js.map +1 -1
- package/dist/diffViewerResults.d.ts +2 -0
- package/dist/diffViewerResults.d.ts.map +1 -1
- package/dist/diffViewerResults.js +2 -1
- package/dist/diffViewerResults.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +21 -59
- package/dist/review.js.map +1 -1
- package/dist/shotIds.js +1 -1
- package/dist/shotIds.js.map +1 -1
- package/dist/storage.d.ts +5 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +32 -0
- package/dist/storage.js.map +1 -1
- package/dist/storyIndex.d.ts +2 -0
- package/dist/storyIndex.d.ts.map +1 -1
- package/dist/storyIndex.js +15 -10
- package/dist/storyIndex.js.map +1 -1
- package/dist/storybook.d.ts +4 -0
- package/dist/storybook.d.ts.map +1 -0
- package/dist/storybook.js +41 -0
- package/dist/storybook.js.map +1 -0
- package/dist/visualRegression.d.ts +9 -32
- package/dist/visualRegression.d.ts.map +1 -1
- package/dist/visualRegression.js +165 -237
- package/dist/visualRegression.js.map +1 -1
- package/package.json +7 -8
- package/patches/lostPixelWindowApi.cjs +0 -215
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
// Preloaded via `node --require` before lost-pixel's CLI starts.
|
|
2
|
-
//
|
|
3
|
-
// Replaces lost-pixel's `collectStoriesViaWindowApi` with a version whose
|
|
4
|
-
// browser-side evaluate prunes each story's `parameters` to an allow-list of
|
|
5
|
-
// keys that lost-pixel actually consumes downstream. The upstream implementation
|
|
6
|
-
// runs a depth-10 recursive `Object.keys(...).reduce()` over every story's full
|
|
7
|
-
// parameters tree; for storybooks with large docgen argTypes metadata (e.g.
|
|
8
|
-
// @storybook/nextjs + complex TS types) this OOM-kills the Chromium renderer
|
|
9
|
-
// on stores with many stories. Playwright has no crash rejection plumbed
|
|
10
|
-
// through `page.evaluate`, so the caller hangs forever.
|
|
11
|
-
//
|
|
12
|
-
// The pruned shape preserves every field `generateStorybookShotItems` reads:
|
|
13
|
-
// parameters.fileName
|
|
14
|
-
// parameters.viewport (width, height) — resolved here from numeric
|
|
15
|
-
// parameters, story/meta-level `globals.viewport`, or the legacy
|
|
16
|
-
// `parameters.viewport.defaultViewport` name, via the viewport addon's
|
|
17
|
-
// `options`/`viewports` map. Project-level defaults are not applied.
|
|
18
|
-
// parameters.lostpixel.{disable,args,threshold,waitBeforeScreenshot,mask,
|
|
19
|
-
// elementLocator,breakpoints,extraShots}
|
|
20
|
-
// parameters.storyshots.disable
|
|
21
|
-
"use strict";
|
|
22
|
-
|
|
23
|
-
const storybook = require("lost-pixel/dist/crawler/storybook");
|
|
24
|
-
const configModule = require("lost-pixel/dist/config");
|
|
25
|
-
|
|
26
|
-
const fetchStoriesTimeout = () =>
|
|
27
|
-
(configModule.config &&
|
|
28
|
-
configModule.config.timeouts &&
|
|
29
|
-
configModule.config.timeouts.fetchStories) ||
|
|
30
|
-
60_000;
|
|
31
|
-
|
|
32
|
-
storybook.collectStoriesViaWindowApi = async function collectStoriesViaWindowApi(
|
|
33
|
-
context,
|
|
34
|
-
url,
|
|
35
|
-
isIframeUrl,
|
|
36
|
-
) {
|
|
37
|
-
const page = await context.newPage();
|
|
38
|
-
const iframeUrl = isIframeUrl
|
|
39
|
-
? storybook.getStoryBookUrl(url)
|
|
40
|
-
: storybook.getIframeUrl(storybook.getStoryBookUrl(url));
|
|
41
|
-
|
|
42
|
-
await page.goto(iframeUrl);
|
|
43
|
-
await page.waitForFunction(() => window.__STORYBOOK_PREVIEW__, null, {
|
|
44
|
-
timeout: fetchStoriesTimeout(),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const isV8OrAbove = await page.evaluate(
|
|
48
|
-
async () => window.__STORYBOOK_PREVIEW__.ready !== undefined,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (isV8OrAbove) {
|
|
52
|
-
await page.evaluate(async () => {
|
|
53
|
-
const api = window.__STORYBOOK_PREVIEW__;
|
|
54
|
-
if (api.ready) await api.ready();
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
await page.waitForFunction(() => window.__STORYBOOK_CLIENT_API__, null, {
|
|
58
|
-
timeout: fetchStoriesTimeout(),
|
|
59
|
-
});
|
|
60
|
-
await page.evaluate(async () => {
|
|
61
|
-
const api = window.__STORYBOOK_CLIENT_API__;
|
|
62
|
-
if (api.storyStore && api.storyStore.cacheAllCSFFiles) {
|
|
63
|
-
await api.storyStore.cacheAllCSFFiles();
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const result = await page.evaluate(extractStories);
|
|
69
|
-
|
|
70
|
-
return result;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
async function extractStories() {
|
|
74
|
-
const isPrimitive = (v) =>
|
|
75
|
-
v === null ||
|
|
76
|
-
v === undefined ||
|
|
77
|
-
typeof v === "string" ||
|
|
78
|
-
typeof v === "number" ||
|
|
79
|
-
typeof v === "boolean";
|
|
80
|
-
|
|
81
|
-
const px = (value) => {
|
|
82
|
-
const n = typeof value === "number" ? value : parseFloat(value);
|
|
83
|
-
return Number.isFinite(n) && n > 0 ? Math.round(n) : undefined;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const namedSize = (viewport, name, rotated) => {
|
|
87
|
-
if (typeof name !== "string" || !viewport) return undefined;
|
|
88
|
-
const named = (viewport.options || viewport.viewports || {})[name];
|
|
89
|
-
const styles = named && named.styles;
|
|
90
|
-
const width = styles && px(styles.width);
|
|
91
|
-
const height = styles && px(styles.height);
|
|
92
|
-
if (!width || !height) return undefined;
|
|
93
|
-
return rotated ? { width: height, height: width } : { width, height };
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const resolveViewport = (story) => {
|
|
97
|
-
const p = story.parameters || {};
|
|
98
|
-
const viewport = p.viewport && typeof p.viewport === "object" ? p.viewport : undefined;
|
|
99
|
-
const width = viewport && px(viewport.width);
|
|
100
|
-
const height = viewport && px(viewport.height);
|
|
101
|
-
if (width && height) return { width, height };
|
|
102
|
-
const g = story.storyGlobals && story.storyGlobals.viewport;
|
|
103
|
-
const fromGlobals =
|
|
104
|
-
g && typeof g === "object"
|
|
105
|
-
? namedSize(viewport, g.value, g.isRotated === true)
|
|
106
|
-
: namedSize(viewport, story.storyGlobals && story.storyGlobals.viewport, false);
|
|
107
|
-
if (fromGlobals) return fromGlobals;
|
|
108
|
-
const fromDefault = namedSize(viewport, viewport && viewport.defaultViewport, false);
|
|
109
|
-
if (fromDefault) return fromDefault;
|
|
110
|
-
if (width || height) {
|
|
111
|
-
const partial = {};
|
|
112
|
-
if (width) partial.width = width;
|
|
113
|
-
if (height) partial.height = height;
|
|
114
|
-
return partial;
|
|
115
|
-
}
|
|
116
|
-
return undefined;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const pluckArgs = (args) => {
|
|
120
|
-
if (!args || typeof args !== "object") return undefined;
|
|
121
|
-
const out = {};
|
|
122
|
-
for (const k of Object.keys(args)) {
|
|
123
|
-
if (isPrimitive(args[k])) out[k] = args[k];
|
|
124
|
-
}
|
|
125
|
-
return out;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const pluckMask = (mask) => {
|
|
129
|
-
if (!Array.isArray(mask)) return undefined;
|
|
130
|
-
return mask
|
|
131
|
-
.map((m) => {
|
|
132
|
-
if (!m || typeof m !== "object") return undefined;
|
|
133
|
-
const out = {};
|
|
134
|
-
if (typeof m.selector === "string") out.selector = m.selector;
|
|
135
|
-
return out.selector ? out : undefined;
|
|
136
|
-
})
|
|
137
|
-
.filter(Boolean);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const pluckExtraShots = (shots) => {
|
|
141
|
-
if (!Array.isArray(shots)) return undefined;
|
|
142
|
-
return shots.map((s) => {
|
|
143
|
-
if (!s || typeof s !== "object") return {};
|
|
144
|
-
const out = {};
|
|
145
|
-
if (typeof s.prefix === "string") out.prefix = s.prefix;
|
|
146
|
-
if (typeof s.suffix === "string") out.suffix = s.suffix;
|
|
147
|
-
if (typeof s.name === "string") out.name = s.name;
|
|
148
|
-
const args = pluckArgs(s.args);
|
|
149
|
-
if (args) out.args = args;
|
|
150
|
-
return out;
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const pluckParameters = (story) => {
|
|
155
|
-
const p = story.parameters;
|
|
156
|
-
if (!p || typeof p !== "object") return {};
|
|
157
|
-
const out = {};
|
|
158
|
-
if (typeof p.fileName === "string") out.fileName = p.fileName;
|
|
159
|
-
const viewport = resolveViewport(story);
|
|
160
|
-
if (viewport) out.viewport = viewport;
|
|
161
|
-
if (p.lostpixel && typeof p.lostpixel === "object") {
|
|
162
|
-
const lp = p.lostpixel;
|
|
163
|
-
const lpOut = {};
|
|
164
|
-
if (typeof lp.disable === "boolean") lpOut.disable = lp.disable;
|
|
165
|
-
const args = pluckArgs(lp.args);
|
|
166
|
-
if (args) lpOut.args = args;
|
|
167
|
-
if (typeof lp.threshold === "number") lpOut.threshold = lp.threshold;
|
|
168
|
-
if (typeof lp.waitBeforeScreenshot === "number")
|
|
169
|
-
lpOut.waitBeforeScreenshot = lp.waitBeforeScreenshot;
|
|
170
|
-
const mask = pluckMask(lp.mask);
|
|
171
|
-
if (mask) lpOut.mask = mask;
|
|
172
|
-
if (typeof lp.elementLocator === "string")
|
|
173
|
-
lpOut.elementLocator = lp.elementLocator;
|
|
174
|
-
if (Array.isArray(lp.breakpoints))
|
|
175
|
-
lpOut.breakpoints = lp.breakpoints.filter(
|
|
176
|
-
(b) => typeof b === "number",
|
|
177
|
-
);
|
|
178
|
-
const extraShots = pluckExtraShots(lp.extraShots);
|
|
179
|
-
if (extraShots) lpOut.extraShots = extraShots;
|
|
180
|
-
out.lostpixel = lpOut;
|
|
181
|
-
}
|
|
182
|
-
if (p.storyshots && typeof p.storyshots === "object") {
|
|
183
|
-
const ss = {};
|
|
184
|
-
if (typeof p.storyshots.disable === "boolean")
|
|
185
|
-
ss.disable = p.storyshots.disable;
|
|
186
|
-
out.storyshots = ss;
|
|
187
|
-
}
|
|
188
|
-
return out;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const mapStories = (stories) =>
|
|
192
|
-
stories.map((story) => {
|
|
193
|
-
const parameters = pluckParameters(story);
|
|
194
|
-
return {
|
|
195
|
-
id: story.id,
|
|
196
|
-
kind: story.kind,
|
|
197
|
-
story: story.story,
|
|
198
|
-
importPath: parameters && parameters.fileName,
|
|
199
|
-
parameters,
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const previewApi = window.__STORYBOOK_PREVIEW__;
|
|
204
|
-
const clientApi = window.__STORYBOOK_CLIENT_API__;
|
|
205
|
-
let stories = [];
|
|
206
|
-
if (previewApi && previewApi.extract) {
|
|
207
|
-
const items = await previewApi.extract();
|
|
208
|
-
stories = mapStories(Object.values(items));
|
|
209
|
-
} else if (clientApi && clientApi.raw) {
|
|
210
|
-
stories = mapStories(clientApi.raw());
|
|
211
|
-
}
|
|
212
|
-
return { stories };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
module.exports = { extractStories };
|