@cappa/plugin-storybook 0.9.0 → 0.10.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/dist/index.cjs.cjs +34 -4
- package/dist/index.cjs.d.cts +16 -0
- package/dist/index.esm.d.mts +16 -0
- package/dist/index.esm.mjs +34 -4
- package/package.json +2 -2
package/dist/index.cjs.cjs
CHANGED
|
@@ -176,6 +176,10 @@ function toFilterContext(story) {
|
|
|
176
176
|
filePath: `${story.title}/${story.name}`
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
+
/** Whether an options object was given and actually carries something. */
|
|
180
|
+
function hasEntries(value) {
|
|
181
|
+
return !!value && Object.keys(value).length > 0;
|
|
182
|
+
}
|
|
179
183
|
/**
|
|
180
184
|
* Create a latch for a Promise. A latch is a Promise that can be resolved from outside.
|
|
181
185
|
* @param T - The type of the Promise
|
|
@@ -286,6 +290,28 @@ const cappaPluginStorybook = (options) => {
|
|
|
286
290
|
if (storyParameters && Object.keys(storyParameters).length > 0) logger.debug("Taking screenshot with options", storyParameters);
|
|
287
291
|
const resolvedViewport = storyParameters?.viewport ?? screenshotTool.viewport;
|
|
288
292
|
await page.setViewportSize(resolvedViewport);
|
|
293
|
+
const storyArgs = {
|
|
294
|
+
...defaultStorybookOptions?.args,
|
|
295
|
+
...storyParameters?.args
|
|
296
|
+
};
|
|
297
|
+
const storyGlobals = {
|
|
298
|
+
...defaultStorybookOptions?.globals,
|
|
299
|
+
...storyParameters?.globals
|
|
300
|
+
};
|
|
301
|
+
const baseUrl = hasEntries(storyParameters?.args) || hasEntries(storyParameters?.globals) ? buildStorybookIframeUrl({
|
|
302
|
+
baseUrl: options?.storybookUrl || "",
|
|
303
|
+
storyId: story.id,
|
|
304
|
+
viewMode: defaultStorybookOptions?.viewMode,
|
|
305
|
+
args: storyArgs,
|
|
306
|
+
globals: storyGlobals,
|
|
307
|
+
query: defaultStorybookOptions?.query,
|
|
308
|
+
fullscreen: defaultStorybookOptions?.fullscreen,
|
|
309
|
+
singleStory: defaultStorybookOptions?.singleStory
|
|
310
|
+
}) : url;
|
|
311
|
+
if (baseUrl !== url) {
|
|
312
|
+
logger.debug(`Reloading story with story-level render options`);
|
|
313
|
+
await page.goto(baseUrl, { timeout: screenshotTool.connectionTimeout });
|
|
314
|
+
}
|
|
289
315
|
await freezeUI(page);
|
|
290
316
|
await waitForVisualIdle(page);
|
|
291
317
|
await waitForPlayFunctionCompletion(page, `${story.title} - ${story.name}`);
|
|
@@ -294,15 +320,19 @@ const cappaPluginStorybook = (options) => {
|
|
|
294
320
|
const variantsWithUrls = [];
|
|
295
321
|
const variantExtrasEntries = [];
|
|
296
322
|
for (const variant of variantParameters) {
|
|
297
|
-
const variantFilename =
|
|
323
|
+
const variantFilename = screenshotTool.getVariantFilename(filename, {
|
|
298
324
|
id: variant.id,
|
|
299
325
|
label: variant.label,
|
|
300
326
|
filename: variant.filename
|
|
301
327
|
});
|
|
302
328
|
const mergedArgs = {
|
|
303
|
-
...
|
|
329
|
+
...storyArgs,
|
|
304
330
|
...variant.options?.args
|
|
305
331
|
};
|
|
332
|
+
const mergedGlobals = {
|
|
333
|
+
...storyGlobals,
|
|
334
|
+
...variant.options?.globals
|
|
335
|
+
};
|
|
306
336
|
variantsWithUrls.push({
|
|
307
337
|
id: variant.id,
|
|
308
338
|
label: variant.label,
|
|
@@ -312,7 +342,7 @@ const cappaPluginStorybook = (options) => {
|
|
|
312
342
|
storyId: story.id,
|
|
313
343
|
viewMode: defaultStorybookOptions?.viewMode,
|
|
314
344
|
args: mergedArgs,
|
|
315
|
-
globals:
|
|
345
|
+
globals: mergedGlobals,
|
|
316
346
|
query: defaultStorybookOptions?.query,
|
|
317
347
|
fullscreen: defaultStorybookOptions?.fullscreen,
|
|
318
348
|
singleStory: defaultStorybookOptions?.singleStory
|
|
@@ -351,7 +381,7 @@ const cappaPluginStorybook = (options) => {
|
|
|
351
381
|
waitForStability: waitForVisualIdle,
|
|
352
382
|
captureStart
|
|
353
383
|
};
|
|
354
|
-
const captureResult = await screenshotTool.captureWithVariants(page, filename,
|
|
384
|
+
const captureResult = await screenshotTool.captureWithVariants(page, filename, baseUrl, baseOptions, variantsWithUrls, captureExtras);
|
|
355
385
|
return {
|
|
356
386
|
storyId: story.id,
|
|
357
387
|
storyName: `${story.title} - ${story.name}`,
|
package/dist/index.cjs.d.cts
CHANGED
|
@@ -19,7 +19,23 @@ interface ScreenshotVariantOverrideStorybook {
|
|
|
19
19
|
width: number;
|
|
20
20
|
height: number;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Storybook args to render this screenshot with, merged over the
|
|
24
|
+
* plugin-level `storybook.args` — and, on a variant, over the story's own
|
|
25
|
+
* `args`.
|
|
26
|
+
*/
|
|
22
27
|
args?: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Storybook globals to render this screenshot with, merged over the
|
|
30
|
+
* plugin-level `storybook.globals` — and, on a variant, over the story's own
|
|
31
|
+
* `globals`.
|
|
32
|
+
*
|
|
33
|
+
* Args and globals are the only render inputs Storybook decodes from the
|
|
34
|
+
* iframe URL, which is what makes them settable per screenshot: cappa
|
|
35
|
+
* rebuilds the URL and loads it again. Parameters cannot work this way —
|
|
36
|
+
* they are fixed when the story is prepared.
|
|
37
|
+
*/
|
|
38
|
+
globals?: Record<string, string | number | boolean>;
|
|
23
39
|
/**
|
|
24
40
|
* Optional diff settings override applied when comparing this screenshot.
|
|
25
41
|
* Supports both pixel (default) and gmsd algorithms.
|
package/dist/index.esm.d.mts
CHANGED
|
@@ -19,7 +19,23 @@ interface ScreenshotVariantOverrideStorybook {
|
|
|
19
19
|
width: number;
|
|
20
20
|
height: number;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Storybook args to render this screenshot with, merged over the
|
|
24
|
+
* plugin-level `storybook.args` — and, on a variant, over the story's own
|
|
25
|
+
* `args`.
|
|
26
|
+
*/
|
|
22
27
|
args?: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Storybook globals to render this screenshot with, merged over the
|
|
30
|
+
* plugin-level `storybook.globals` — and, on a variant, over the story's own
|
|
31
|
+
* `globals`.
|
|
32
|
+
*
|
|
33
|
+
* Args and globals are the only render inputs Storybook decodes from the
|
|
34
|
+
* iframe URL, which is what makes them settable per screenshot: cappa
|
|
35
|
+
* rebuilds the URL and loads it again. Parameters cannot work this way —
|
|
36
|
+
* they are fixed when the story is prepared.
|
|
37
|
+
*/
|
|
38
|
+
globals?: Record<string, string | number | boolean>;
|
|
23
39
|
/**
|
|
24
40
|
* Optional diff settings override applied when comparing this screenshot.
|
|
25
41
|
* Supports both pixel (default) and gmsd algorithms.
|
package/dist/index.esm.mjs
CHANGED
|
@@ -176,6 +176,10 @@ function toFilterContext(story) {
|
|
|
176
176
|
filePath: `${story.title}/${story.name}`
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
+
/** Whether an options object was given and actually carries something. */
|
|
180
|
+
function hasEntries(value) {
|
|
181
|
+
return !!value && Object.keys(value).length > 0;
|
|
182
|
+
}
|
|
179
183
|
/**
|
|
180
184
|
* Create a latch for a Promise. A latch is a Promise that can be resolved from outside.
|
|
181
185
|
* @param T - The type of the Promise
|
|
@@ -286,6 +290,28 @@ const cappaPluginStorybook = (options) => {
|
|
|
286
290
|
if (storyParameters && Object.keys(storyParameters).length > 0) logger.debug("Taking screenshot with options", storyParameters);
|
|
287
291
|
const resolvedViewport = storyParameters?.viewport ?? screenshotTool.viewport;
|
|
288
292
|
await page.setViewportSize(resolvedViewport);
|
|
293
|
+
const storyArgs = {
|
|
294
|
+
...defaultStorybookOptions?.args,
|
|
295
|
+
...storyParameters?.args
|
|
296
|
+
};
|
|
297
|
+
const storyGlobals = {
|
|
298
|
+
...defaultStorybookOptions?.globals,
|
|
299
|
+
...storyParameters?.globals
|
|
300
|
+
};
|
|
301
|
+
const baseUrl = hasEntries(storyParameters?.args) || hasEntries(storyParameters?.globals) ? buildStorybookIframeUrl({
|
|
302
|
+
baseUrl: options?.storybookUrl || "",
|
|
303
|
+
storyId: story.id,
|
|
304
|
+
viewMode: defaultStorybookOptions?.viewMode,
|
|
305
|
+
args: storyArgs,
|
|
306
|
+
globals: storyGlobals,
|
|
307
|
+
query: defaultStorybookOptions?.query,
|
|
308
|
+
fullscreen: defaultStorybookOptions?.fullscreen,
|
|
309
|
+
singleStory: defaultStorybookOptions?.singleStory
|
|
310
|
+
}) : url;
|
|
311
|
+
if (baseUrl !== url) {
|
|
312
|
+
logger.debug(`Reloading story with story-level render options`);
|
|
313
|
+
await page.goto(baseUrl, { timeout: screenshotTool.connectionTimeout });
|
|
314
|
+
}
|
|
289
315
|
await freezeUI(page);
|
|
290
316
|
await waitForVisualIdle(page);
|
|
291
317
|
await waitForPlayFunctionCompletion(page, `${story.title} - ${story.name}`);
|
|
@@ -294,15 +320,19 @@ const cappaPluginStorybook = (options) => {
|
|
|
294
320
|
const variantsWithUrls = [];
|
|
295
321
|
const variantExtrasEntries = [];
|
|
296
322
|
for (const variant of variantParameters) {
|
|
297
|
-
const variantFilename =
|
|
323
|
+
const variantFilename = screenshotTool.getVariantFilename(filename, {
|
|
298
324
|
id: variant.id,
|
|
299
325
|
label: variant.label,
|
|
300
326
|
filename: variant.filename
|
|
301
327
|
});
|
|
302
328
|
const mergedArgs = {
|
|
303
|
-
...
|
|
329
|
+
...storyArgs,
|
|
304
330
|
...variant.options?.args
|
|
305
331
|
};
|
|
332
|
+
const mergedGlobals = {
|
|
333
|
+
...storyGlobals,
|
|
334
|
+
...variant.options?.globals
|
|
335
|
+
};
|
|
306
336
|
variantsWithUrls.push({
|
|
307
337
|
id: variant.id,
|
|
308
338
|
label: variant.label,
|
|
@@ -312,7 +342,7 @@ const cappaPluginStorybook = (options) => {
|
|
|
312
342
|
storyId: story.id,
|
|
313
343
|
viewMode: defaultStorybookOptions?.viewMode,
|
|
314
344
|
args: mergedArgs,
|
|
315
|
-
globals:
|
|
345
|
+
globals: mergedGlobals,
|
|
316
346
|
query: defaultStorybookOptions?.query,
|
|
317
347
|
fullscreen: defaultStorybookOptions?.fullscreen,
|
|
318
348
|
singleStory: defaultStorybookOptions?.singleStory
|
|
@@ -351,7 +381,7 @@ const cappaPluginStorybook = (options) => {
|
|
|
351
381
|
waitForStability: waitForVisualIdle,
|
|
352
382
|
captureStart
|
|
353
383
|
};
|
|
354
|
-
const captureResult = await screenshotTool.captureWithVariants(page, filename,
|
|
384
|
+
const captureResult = await screenshotTool.captureWithVariants(page, filename, baseUrl, baseOptions, variantsWithUrls, captureExtras);
|
|
355
385
|
return {
|
|
356
386
|
storyId: story.id,
|
|
357
387
|
storyName: `${story.title} - ${story.name}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@cappa/core": "0.13.
|
|
79
|
+
"@cappa/core": "0.13.1",
|
|
80
80
|
"@cappa/logger": "0.0.12",
|
|
81
81
|
"@swc/core": "^1.16.2",
|
|
82
82
|
"chalk": "^6.0.0"
|