@cappa/plugin-storybook 0.0.18 → 0.0.19
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +8 -0
- package/dist/index.js +62 -26
- package/dist/index.mjs +62 -26
- package/package.json +2 -2
- package/src/cappa/plugin.ts +7 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @cappa/plugin-storybook@0.0.
|
|
3
|
+
> @cappa/plugin-storybook@0.0.18 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
[34mESM[39m Build start
|
|
28
28
|
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
29
29
|
[32mESM[39m ⚡️ Build success in 6ms
|
|
30
|
-
[32mCJS[39m [1mdist/index.js [22m[32m7.14 KB[39m
|
|
31
|
-
[32mCJS[39m ⚡️ Build success in 9ms
|
|
32
30
|
[32mESM[39m [1mdist/preview.mjs [22m[32m1.34 KB[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in
|
|
34
|
-
[
|
|
35
|
-
[
|
|
31
|
+
[32mESM[39m ⚡️ Build success in 8ms
|
|
32
|
+
[32mCJS[39m [1mdist/index.js [22m[32m7.86 KB[39m
|
|
33
|
+
[32mCJS[39m ⚡️ Build success in 9ms
|
|
34
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m6.57 KB[39m
|
|
35
|
+
[32mESM[39m ⚡️ Build success in 9ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
37
|
+
DTS ⚡️ Build success in 785ms
|
|
38
38
|
DTS dist/index.d.ts 593.00 B
|
|
39
39
|
DTS dist/index.d.mts 593.00 B
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -49,7 +49,9 @@ var waitForVisualIdle = async (page) => {
|
|
|
49
49
|
await page.waitForLoadState("networkidle");
|
|
50
50
|
await page.evaluate(async () => {
|
|
51
51
|
if (document.fonts?.ready) await document.fonts.ready;
|
|
52
|
-
await new Promise(
|
|
52
|
+
await new Promise(
|
|
53
|
+
(r) => requestAnimationFrame(() => requestAnimationFrame(r))
|
|
54
|
+
);
|
|
53
55
|
});
|
|
54
56
|
};
|
|
55
57
|
var buildFilename = (story) => {
|
|
@@ -67,7 +69,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
67
69
|
name: "StorybookPlugin",
|
|
68
70
|
description: "Takes screenshots of Storybook stories with configurable options",
|
|
69
71
|
version: "1.0.0",
|
|
70
|
-
execute: async (screenshotTool) => {
|
|
72
|
+
execute: async (screenshotTool, logger) => {
|
|
71
73
|
if (!options) {
|
|
72
74
|
throw new Error("Storybook plugin options are required");
|
|
73
75
|
}
|
|
@@ -87,29 +89,40 @@ var cappaPluginStorybook = (options) => {
|
|
|
87
89
|
try {
|
|
88
90
|
const response = await fetch(storiesUrl);
|
|
89
91
|
if (!response.ok) {
|
|
90
|
-
throw new Error(
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Failed to fetch stories: ${response.status} ${response.statusText}`
|
|
94
|
+
);
|
|
91
95
|
}
|
|
92
96
|
const data = await response.json();
|
|
93
97
|
const stories = Object.values(data.entries);
|
|
94
98
|
let filteredStories = stories;
|
|
95
99
|
if (includeStories.length > 0) {
|
|
96
100
|
filteredStories = filteredStories.filter(
|
|
97
|
-
(story) => includeStories.some(
|
|
101
|
+
(story) => includeStories.some(
|
|
102
|
+
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
103
|
+
)
|
|
98
104
|
);
|
|
99
105
|
}
|
|
100
106
|
if (excludeStories.length > 0) {
|
|
101
107
|
filteredStories = filteredStories.filter(
|
|
102
|
-
(story) => !excludeStories.some(
|
|
108
|
+
(story) => !excludeStories.some(
|
|
109
|
+
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
110
|
+
)
|
|
103
111
|
);
|
|
104
112
|
}
|
|
105
|
-
filteredStories = filteredStories.filter(
|
|
113
|
+
filteredStories = filteredStories.filter(
|
|
114
|
+
(story) => story.type === "story"
|
|
115
|
+
);
|
|
106
116
|
console.log(`Found ${filteredStories.length} stories to screenshot`);
|
|
107
117
|
const results = [];
|
|
108
118
|
await screenshotTool.init();
|
|
109
119
|
let currentLatch = createLatch();
|
|
110
|
-
await screenshotTool.page?.exposeFunction(
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
await screenshotTool.page?.exposeFunction(
|
|
121
|
+
"__cappa_parameters",
|
|
122
|
+
async (payload) => {
|
|
123
|
+
currentLatch.resolve(payload);
|
|
124
|
+
}
|
|
125
|
+
);
|
|
113
126
|
for (const story of filteredStories) {
|
|
114
127
|
try {
|
|
115
128
|
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
@@ -126,16 +139,23 @@ var cappaPluginStorybook = (options) => {
|
|
|
126
139
|
throw new Error("Page not initialized");
|
|
127
140
|
}
|
|
128
141
|
page.on("console", (message) => {
|
|
129
|
-
|
|
142
|
+
logger.debug("console", message.text());
|
|
130
143
|
});
|
|
131
144
|
page.on("pageerror", (error) => {
|
|
132
|
-
|
|
145
|
+
logger.debug("pageerror", error);
|
|
133
146
|
});
|
|
134
147
|
await page.goto(storyUrl);
|
|
135
148
|
const options2 = await currentLatch.p;
|
|
136
149
|
currentLatch = createLatch();
|
|
150
|
+
logger.debug("options", options2);
|
|
137
151
|
if (options2.skip) {
|
|
138
|
-
|
|
152
|
+
logger.log(`Skipping story ${story.title} - ${story.name}`);
|
|
153
|
+
results.push({
|
|
154
|
+
storyId: story.id,
|
|
155
|
+
storyName: `${story.title} - ${story.name}`,
|
|
156
|
+
skipped: true
|
|
157
|
+
});
|
|
158
|
+
continue;
|
|
139
159
|
}
|
|
140
160
|
await freezeUI(page);
|
|
141
161
|
await waitForVisualIdle(page);
|
|
@@ -143,33 +163,49 @@ var cappaPluginStorybook = (options) => {
|
|
|
143
163
|
await page.waitForTimeout(options2.delay);
|
|
144
164
|
}
|
|
145
165
|
const filename = buildFilename(story);
|
|
146
|
-
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
166
|
+
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
167
|
+
page,
|
|
168
|
+
filename,
|
|
169
|
+
{
|
|
170
|
+
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
171
|
+
type: options2.type ?? screenshotOptions.type,
|
|
172
|
+
waitForSelector: options2.waitForSelector ?? screenshotOptions.waitForSelector,
|
|
173
|
+
waitForTimeout: options2.waitForTimeout ?? screenshotOptions.waitForTimeout
|
|
174
|
+
}
|
|
175
|
+
);
|
|
152
176
|
results.push({
|
|
153
177
|
storyId: story.id,
|
|
154
178
|
storyName: `${story.title} - ${story.name}`,
|
|
155
|
-
|
|
156
|
-
|
|
179
|
+
filepath: actualFilepath,
|
|
180
|
+
success: true
|
|
157
181
|
});
|
|
158
182
|
} catch (error) {
|
|
159
|
-
console.error(
|
|
183
|
+
console.error(
|
|
184
|
+
`Error taking screenshot of story ${story.title} - ${story.name}:`,
|
|
185
|
+
error.message
|
|
186
|
+
);
|
|
160
187
|
results.push({
|
|
161
188
|
storyId: story.id,
|
|
162
189
|
storyName: `${story.title} - ${story.name}`,
|
|
163
|
-
success: false,
|
|
164
190
|
error: error?.message ?? "Unknown error"
|
|
165
191
|
});
|
|
166
192
|
}
|
|
167
193
|
}
|
|
168
|
-
if (results.some((r) =>
|
|
169
|
-
console.log(
|
|
170
|
-
|
|
194
|
+
if (results.some((r) => r.error)) {
|
|
195
|
+
console.log(
|
|
196
|
+
`Error report:
|
|
197
|
+
${results.filter((r) => r.error).map((r) => `${r.storyName}: ${r.error}`).join("\n")}`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (results.some((r) => r.skipped)) {
|
|
201
|
+
console.log(
|
|
202
|
+
`Skipped stories:
|
|
203
|
+
${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
|
|
204
|
+
);
|
|
171
205
|
}
|
|
172
|
-
console.log(
|
|
206
|
+
console.log(
|
|
207
|
+
`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`
|
|
208
|
+
);
|
|
173
209
|
return results;
|
|
174
210
|
} catch (error) {
|
|
175
211
|
console.error("Error in Storybook plugin:", error.message);
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,9 @@ var waitForVisualIdle = async (page) => {
|
|
|
19
19
|
await page.waitForLoadState("networkidle");
|
|
20
20
|
await page.evaluate(async () => {
|
|
21
21
|
if (document.fonts?.ready) await document.fonts.ready;
|
|
22
|
-
await new Promise(
|
|
22
|
+
await new Promise(
|
|
23
|
+
(r) => requestAnimationFrame(() => requestAnimationFrame(r))
|
|
24
|
+
);
|
|
23
25
|
});
|
|
24
26
|
};
|
|
25
27
|
var buildFilename = (story) => {
|
|
@@ -37,7 +39,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
37
39
|
name: "StorybookPlugin",
|
|
38
40
|
description: "Takes screenshots of Storybook stories with configurable options",
|
|
39
41
|
version: "1.0.0",
|
|
40
|
-
execute: async (screenshotTool) => {
|
|
42
|
+
execute: async (screenshotTool, logger) => {
|
|
41
43
|
if (!options) {
|
|
42
44
|
throw new Error("Storybook plugin options are required");
|
|
43
45
|
}
|
|
@@ -57,29 +59,40 @@ var cappaPluginStorybook = (options) => {
|
|
|
57
59
|
try {
|
|
58
60
|
const response = await fetch(storiesUrl);
|
|
59
61
|
if (!response.ok) {
|
|
60
|
-
throw new Error(
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Failed to fetch stories: ${response.status} ${response.statusText}`
|
|
64
|
+
);
|
|
61
65
|
}
|
|
62
66
|
const data = await response.json();
|
|
63
67
|
const stories = Object.values(data.entries);
|
|
64
68
|
let filteredStories = stories;
|
|
65
69
|
if (includeStories.length > 0) {
|
|
66
70
|
filteredStories = filteredStories.filter(
|
|
67
|
-
(story) => includeStories.some(
|
|
71
|
+
(story) => includeStories.some(
|
|
72
|
+
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
73
|
+
)
|
|
68
74
|
);
|
|
69
75
|
}
|
|
70
76
|
if (excludeStories.length > 0) {
|
|
71
77
|
filteredStories = filteredStories.filter(
|
|
72
|
-
(story) => !excludeStories.some(
|
|
78
|
+
(story) => !excludeStories.some(
|
|
79
|
+
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
80
|
+
)
|
|
73
81
|
);
|
|
74
82
|
}
|
|
75
|
-
filteredStories = filteredStories.filter(
|
|
83
|
+
filteredStories = filteredStories.filter(
|
|
84
|
+
(story) => story.type === "story"
|
|
85
|
+
);
|
|
76
86
|
console.log(`Found ${filteredStories.length} stories to screenshot`);
|
|
77
87
|
const results = [];
|
|
78
88
|
await screenshotTool.init();
|
|
79
89
|
let currentLatch = createLatch();
|
|
80
|
-
await screenshotTool.page?.exposeFunction(
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
await screenshotTool.page?.exposeFunction(
|
|
91
|
+
"__cappa_parameters",
|
|
92
|
+
async (payload) => {
|
|
93
|
+
currentLatch.resolve(payload);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
83
96
|
for (const story of filteredStories) {
|
|
84
97
|
try {
|
|
85
98
|
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
@@ -96,16 +109,23 @@ var cappaPluginStorybook = (options) => {
|
|
|
96
109
|
throw new Error("Page not initialized");
|
|
97
110
|
}
|
|
98
111
|
page.on("console", (message) => {
|
|
99
|
-
|
|
112
|
+
logger.debug("console", message.text());
|
|
100
113
|
});
|
|
101
114
|
page.on("pageerror", (error) => {
|
|
102
|
-
|
|
115
|
+
logger.debug("pageerror", error);
|
|
103
116
|
});
|
|
104
117
|
await page.goto(storyUrl);
|
|
105
118
|
const options2 = await currentLatch.p;
|
|
106
119
|
currentLatch = createLatch();
|
|
120
|
+
logger.debug("options", options2);
|
|
107
121
|
if (options2.skip) {
|
|
108
|
-
|
|
122
|
+
logger.log(`Skipping story ${story.title} - ${story.name}`);
|
|
123
|
+
results.push({
|
|
124
|
+
storyId: story.id,
|
|
125
|
+
storyName: `${story.title} - ${story.name}`,
|
|
126
|
+
skipped: true
|
|
127
|
+
});
|
|
128
|
+
continue;
|
|
109
129
|
}
|
|
110
130
|
await freezeUI(page);
|
|
111
131
|
await waitForVisualIdle(page);
|
|
@@ -113,33 +133,49 @@ var cappaPluginStorybook = (options) => {
|
|
|
113
133
|
await page.waitForTimeout(options2.delay);
|
|
114
134
|
}
|
|
115
135
|
const filename = buildFilename(story);
|
|
116
|
-
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
137
|
+
page,
|
|
138
|
+
filename,
|
|
139
|
+
{
|
|
140
|
+
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
141
|
+
type: options2.type ?? screenshotOptions.type,
|
|
142
|
+
waitForSelector: options2.waitForSelector ?? screenshotOptions.waitForSelector,
|
|
143
|
+
waitForTimeout: options2.waitForTimeout ?? screenshotOptions.waitForTimeout
|
|
144
|
+
}
|
|
145
|
+
);
|
|
122
146
|
results.push({
|
|
123
147
|
storyId: story.id,
|
|
124
148
|
storyName: `${story.title} - ${story.name}`,
|
|
125
|
-
|
|
126
|
-
|
|
149
|
+
filepath: actualFilepath,
|
|
150
|
+
success: true
|
|
127
151
|
});
|
|
128
152
|
} catch (error) {
|
|
129
|
-
console.error(
|
|
153
|
+
console.error(
|
|
154
|
+
`Error taking screenshot of story ${story.title} - ${story.name}:`,
|
|
155
|
+
error.message
|
|
156
|
+
);
|
|
130
157
|
results.push({
|
|
131
158
|
storyId: story.id,
|
|
132
159
|
storyName: `${story.title} - ${story.name}`,
|
|
133
|
-
success: false,
|
|
134
160
|
error: error?.message ?? "Unknown error"
|
|
135
161
|
});
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
|
-
if (results.some((r) =>
|
|
139
|
-
console.log(
|
|
140
|
-
|
|
164
|
+
if (results.some((r) => r.error)) {
|
|
165
|
+
console.log(
|
|
166
|
+
`Error report:
|
|
167
|
+
${results.filter((r) => r.error).map((r) => `${r.storyName}: ${r.error}`).join("\n")}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (results.some((r) => r.skipped)) {
|
|
171
|
+
console.log(
|
|
172
|
+
`Skipped stories:
|
|
173
|
+
${results.filter((r) => r.skipped).map((r) => `${r.storyName}`).join("\n")}`
|
|
174
|
+
);
|
|
141
175
|
}
|
|
142
|
-
console.log(
|
|
176
|
+
console.log(
|
|
177
|
+
`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`
|
|
178
|
+
);
|
|
143
179
|
return results;
|
|
144
180
|
} catch (error) {
|
|
145
181
|
console.error("Error in Storybook plugin:", error.message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
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.
|
|
33
|
+
"@cappa/core": "0.0.19"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"playwright-core": "^1.55.0",
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Plugin, ScreenshotOptions
|
|
1
|
+
import type { Plugin, ScreenshotOptions } from "@cappa/core";
|
|
2
2
|
import { buildFilename, freezeUI, waitForVisualIdle } from "./util";
|
|
3
3
|
|
|
4
4
|
export interface StorybookStory {
|
|
@@ -47,7 +47,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
47
47
|
description:
|
|
48
48
|
"Takes screenshots of Storybook stories with configurable options",
|
|
49
49
|
version: "1.0.0",
|
|
50
|
-
execute: async (screenshotTool
|
|
50
|
+
execute: async (screenshotTool, logger) => {
|
|
51
51
|
if (!options) {
|
|
52
52
|
throw new Error("Storybook plugin options are required");
|
|
53
53
|
}
|
|
@@ -149,10 +149,10 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
page.on("console", (message) => {
|
|
152
|
-
|
|
152
|
+
logger.debug("console", message.text());
|
|
153
153
|
});
|
|
154
154
|
page.on("pageerror", (error) => {
|
|
155
|
-
|
|
155
|
+
logger.debug("pageerror", error);
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
await page.goto(storyUrl);
|
|
@@ -160,8 +160,10 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
160
160
|
const options = await currentLatch.p;
|
|
161
161
|
currentLatch = createLatch<ScreenshotOptions>();
|
|
162
162
|
|
|
163
|
+
logger.debug("options", options);
|
|
164
|
+
|
|
163
165
|
if (options.skip) {
|
|
164
|
-
|
|
166
|
+
logger.log(`Skipping story ${story.title} - ${story.name}`);
|
|
165
167
|
results.push({
|
|
166
168
|
storyId: story.id,
|
|
167
169
|
storyName: `${story.title} - ${story.name}`,
|