@cappa/plugin-storybook 0.0.16 → 0.0.18

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 3a8b89e: Fix skipped stories and report
8
+ - Updated dependencies [3a8b89e]
9
+ - @cappa/core@0.0.18
10
+
11
+ ## 0.0.17
12
+
13
+ ### Patch Changes
14
+
15
+ - 6d7176e: Fix error reporting
16
+ - Updated dependencies [6d7176e]
17
+ - @cappa/core@0.0.17
18
+
3
19
  ## 0.0.16
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/plugin-storybook",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@swc/core": "^1.13.5",
32
32
  "storybook": "^9.1.5",
33
- "@cappa/core": "0.0.16"
33
+ "@cappa/core": "0.0.18"
34
34
  },
35
35
  "devDependencies": {
36
36
  "playwright-core": "^1.55.0",
@@ -39,10 +39,13 @@ function createLatch<T>() {
39
39
  * Storybook Plugin for Cappa
40
40
  * Fetches stories from a running Storybook server and takes screenshots of each story
41
41
  */
42
- export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) => {
42
+ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
43
+ options,
44
+ ) => {
43
45
  return {
44
46
  name: "StorybookPlugin",
45
- description: "Takes screenshots of Storybook stories with configurable options",
47
+ description:
48
+ "Takes screenshots of Storybook stories with configurable options",
46
49
  version: "1.0.0",
47
50
  execute: async (screenshotTool: ScreenshotTool) => {
48
51
  if (!options) {
@@ -68,7 +71,9 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
68
71
  // Fetch stories from Storybook
69
72
  const response = await fetch(storiesUrl);
70
73
  if (!response.ok) {
71
- throw new Error(`Failed to fetch stories: ${response.status} ${response.statusText}`);
74
+ throw new Error(
75
+ `Failed to fetch stories: ${response.status} ${response.statusText}`,
76
+ );
72
77
  }
73
78
 
74
79
  const data = (await response.json()) as StorybookStoriesResponse;
@@ -79,36 +84,49 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
79
84
 
80
85
  if (includeStories.length > 0) {
81
86
  filteredStories = filteredStories.filter((story) =>
82
- includeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern)),
87
+ includeStories.some(
88
+ (pattern) =>
89
+ story.title.includes(pattern) || story.name.includes(pattern),
90
+ ),
83
91
  );
84
92
  }
85
93
 
86
94
  if (excludeStories.length > 0) {
87
95
  filteredStories = filteredStories.filter(
88
- (story) => !excludeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern)),
96
+ (story) =>
97
+ !excludeStories.some(
98
+ (pattern) =>
99
+ story.title.includes(pattern) || story.name.includes(pattern),
100
+ ),
89
101
  );
90
102
  }
91
103
 
92
104
  // Filter docs etc
93
- filteredStories = filteredStories.filter((story) => story.type === "story");
105
+ filteredStories = filteredStories.filter(
106
+ (story) => story.type === "story",
107
+ );
94
108
 
95
109
  console.log(`Found ${filteredStories.length} stories to screenshot`);
96
110
 
97
111
  const results: Array<{
98
112
  storyId: string;
99
113
  storyName: string;
100
- success: boolean;
101
114
  filepath?: string;
115
+ success?: boolean;
102
116
  error?: string;
117
+ skipped?: boolean;
103
118
  }> = [];
104
119
 
105
120
  await screenshotTool.init();
106
121
 
107
122
  let currentLatch = createLatch<ScreenshotOptions>();
108
123
 
109
- await screenshotTool.page?.exposeFunction("__cappa_parameters", async (payload: ScreenshotOptions) => {
110
- currentLatch.resolve(payload);
111
- });
124
+ await screenshotTool.page?.exposeFunction(
125
+ "__cappa_parameters",
126
+ async (payload: ScreenshotOptions) => {
127
+ currentLatch.resolve(payload);
128
+ },
129
+ );
112
130
 
113
131
  // Take screenshots of each story
114
132
  for (const story of filteredStories) {
@@ -144,6 +162,12 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
144
162
 
145
163
  if (options.skip) {
146
164
  console.log(`Skipping story ${story.title} - ${story.name}`);
165
+ results.push({
166
+ storyId: story.id,
167
+ storyName: `${story.title} - ${story.name}`,
168
+ skipped: true,
169
+ });
170
+ continue;
147
171
  }
148
172
 
149
173
  await freezeUI(page);
@@ -157,35 +181,61 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
157
181
  const filename = buildFilename(story);
158
182
 
159
183
  // Actually take the screenshot
160
- const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
161
- fullPage: options.fullPage ?? screenshotOptions.fullPage,
162
- type: options.type ?? screenshotOptions.type,
163
- waitForSelector: options.waitForSelector ?? screenshotOptions.waitForSelector,
164
- waitForTimeout: options.waitForTimeout ?? screenshotOptions.waitForTimeout,
165
- });
184
+ const actualFilepath = await screenshotTool.takeScreenshot(
185
+ page,
186
+ filename,
187
+ {
188
+ fullPage: options.fullPage ?? screenshotOptions.fullPage,
189
+ type: options.type ?? screenshotOptions.type,
190
+ waitForSelector:
191
+ options.waitForSelector ?? screenshotOptions.waitForSelector,
192
+ waitForTimeout:
193
+ options.waitForTimeout ?? screenshotOptions.waitForTimeout,
194
+ },
195
+ );
166
196
 
167
197
  results.push({
168
198
  storyId: story.id,
169
199
  storyName: `${story.title} - ${story.name}`,
170
- success: true,
171
200
  filepath: actualFilepath,
201
+ success: true,
172
202
  });
173
203
  } catch (error) {
174
- console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, (error as Error).message);
204
+ console.error(
205
+ `Error taking screenshot of story ${story.title} - ${story.name}:`,
206
+ (error as Error).message,
207
+ );
175
208
  results.push({
176
209
  storyId: story.id,
177
210
  storyName: `${story.title} - ${story.name}`,
178
- success: false,
179
211
  error: (error as Error)?.message ?? "Unknown error",
180
212
  });
181
213
  }
182
214
  }
183
215
 
184
- if (results.some((r) => !r.success)) {
185
- console.log(`Error report: \n${results.map((r) => `${r.storyName}: ${r.error}`).join("\n")}`);
216
+ // Print error report if there are any errors
217
+ if (results.some((r) => r.error)) {
218
+ console.log(
219
+ `Error report: \n${results
220
+ .filter((r) => r.error)
221
+ .map((r) => `${r.storyName}: ${r.error}`)
222
+ .join("\n")}`,
223
+ );
224
+ }
225
+
226
+ // Print skipped stories if there are any
227
+ if (results.some((r) => r.skipped)) {
228
+ console.log(
229
+ `Skipped stories: \n${results
230
+ .filter((r) => r.skipped)
231
+ .map((r) => `${r.storyName}`)
232
+ .join("\n")}`,
233
+ );
186
234
  }
187
235
 
188
- console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
236
+ console.log(
237
+ `Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`,
238
+ );
189
239
  return results;
190
240
  } catch (error) {
191
241
  console.error("Error in Storybook plugin:", (error as Error).message);
package/src/cappa/util.ts CHANGED
@@ -28,7 +28,9 @@ export const waitForVisualIdle = async (page: Page) => {
28
28
  if (document.fonts?.ready) await document.fonts.ready;
29
29
 
30
30
  // Wait for a frame to be idle in the requestAnimationFrame queue
31
- await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
31
+ await new Promise((r) =>
32
+ requestAnimationFrame(() => requestAnimationFrame(r)),
33
+ );
32
34
  });
33
35
  };
34
36