@cappa/plugin-storybook 0.0.15 → 0.0.17
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 +6 -6
- package/CHANGELOG.md +16 -0
- package/dist/index.js +0 -3
- package/dist/index.mjs +0 -3
- package/dist/preview.mjs +1 -6
- package/package.json +2 -2
- package/src/cappa/plugin.ts +52 -22
- package/src/cappa/util.test.ts +5 -5
- package/src/cappa/util.ts +4 -2
- package/src/tsconfig.json +2 -2
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.15 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
|
-
[
|
|
31
|
-
[32mESM[39m ⚡️ Build success in 9ms
|
|
32
|
-
[32mCJS[39m [1mdist/index.js [22m[32m7.32 KB[39m
|
|
30
|
+
[32mCJS[39m [1mdist/index.js [22m[32m7.14 KB[39m
|
|
33
31
|
[32mCJS[39m ⚡️ Build success in 9ms
|
|
34
|
-
[32mESM[39m [1mdist/preview.mjs [22m[32m1.
|
|
32
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.34 KB[39m
|
|
35
33
|
[32mESM[39m ⚡️ Build success in 7ms
|
|
34
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m5.84 KB[39m
|
|
35
|
+
[32mESM[39m ⚡️ Build success in 10ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
37
|
+
DTS ⚡️ Build success in 777ms
|
|
38
38
|
DTS dist/index.d.ts 593.00 B
|
|
39
39
|
DTS dist/index.d.mts 593.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @cappa/plugin-storybook
|
|
2
2
|
|
|
3
|
+
## 0.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6d7176e: Fix error reporting
|
|
8
|
+
- Updated dependencies [6d7176e]
|
|
9
|
+
- @cappa/core@0.0.17
|
|
10
|
+
|
|
11
|
+
## 0.0.16
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 92d164e: Fix directory creation
|
|
16
|
+
- Updated dependencies [92d164e]
|
|
17
|
+
- @cappa/core@0.0.16
|
|
18
|
+
|
|
3
19
|
## 0.0.15
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -57,8 +57,6 @@ var buildFilename = (story) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// src/cappa/plugin.ts
|
|
60
|
-
var import_path = __toESM(require("path"));
|
|
61
|
-
var import_fs = __toESM(require("fs"));
|
|
62
60
|
function createLatch() {
|
|
63
61
|
let resolve;
|
|
64
62
|
const p = new Promise((r) => resolve = r);
|
|
@@ -145,7 +143,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
145
143
|
await page.waitForTimeout(options2.delay);
|
|
146
144
|
}
|
|
147
145
|
const filename = buildFilename(story);
|
|
148
|
-
import_fs.default.mkdirSync(import_path.default.dirname(filename), { recursive: true });
|
|
149
146
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
150
147
|
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
151
148
|
type: options2.type ?? screenshotOptions.type,
|
package/dist/index.mjs
CHANGED
|
@@ -27,8 +27,6 @@ var buildFilename = (story) => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// src/cappa/plugin.ts
|
|
30
|
-
import path from "path";
|
|
31
|
-
import fs from "fs";
|
|
32
30
|
function createLatch() {
|
|
33
31
|
let resolve;
|
|
34
32
|
const p = new Promise((r) => resolve = r);
|
|
@@ -115,7 +113,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
115
113
|
await page.waitForTimeout(options2.delay);
|
|
116
114
|
}
|
|
117
115
|
const filename = buildFilename(story);
|
|
118
|
-
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
119
116
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
120
117
|
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
121
118
|
type: options2.type ?? screenshotOptions.type,
|
package/dist/preview.mjs
CHANGED
|
@@ -40,12 +40,7 @@ var withCappaDecorator = makeDecorator({
|
|
|
40
40
|
|
|
41
41
|
// src/storybook/addon/preview.ts
|
|
42
42
|
var decorators = [withCappaDecorator];
|
|
43
|
-
var parameters = {
|
|
44
|
-
layout: "full",
|
|
45
|
-
cappa: {
|
|
46
|
-
enabled: true
|
|
47
|
-
}
|
|
48
|
-
};
|
|
43
|
+
var parameters = {};
|
|
49
44
|
var afterEach = () => {
|
|
50
45
|
window.playAfterEach = true;
|
|
51
46
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
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.17"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"playwright-core": "^1.55.0",
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Plugin, ScreenshotOptions, ScreenshotTool } from "@cappa/core";
|
|
2
2
|
import { buildFilename, freezeUI, waitForVisualIdle } from "./util";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
3
|
|
|
6
4
|
export interface StorybookStory {
|
|
7
5
|
id: string;
|
|
@@ -41,10 +39,13 @@ function createLatch<T>() {
|
|
|
41
39
|
* Storybook Plugin for Cappa
|
|
42
40
|
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
43
41
|
*/
|
|
44
|
-
export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
42
|
+
export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
43
|
+
options,
|
|
44
|
+
) => {
|
|
45
45
|
return {
|
|
46
46
|
name: "StorybookPlugin",
|
|
47
|
-
description:
|
|
47
|
+
description:
|
|
48
|
+
"Takes screenshots of Storybook stories with configurable options",
|
|
48
49
|
version: "1.0.0",
|
|
49
50
|
execute: async (screenshotTool: ScreenshotTool) => {
|
|
50
51
|
if (!options) {
|
|
@@ -70,7 +71,9 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
70
71
|
// Fetch stories from Storybook
|
|
71
72
|
const response = await fetch(storiesUrl);
|
|
72
73
|
if (!response.ok) {
|
|
73
|
-
throw new Error(
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Failed to fetch stories: ${response.status} ${response.statusText}`,
|
|
76
|
+
);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
const data = (await response.json()) as StorybookStoriesResponse;
|
|
@@ -81,18 +84,27 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
81
84
|
|
|
82
85
|
if (includeStories.length > 0) {
|
|
83
86
|
filteredStories = filteredStories.filter((story) =>
|
|
84
|
-
includeStories.some(
|
|
87
|
+
includeStories.some(
|
|
88
|
+
(pattern) =>
|
|
89
|
+
story.title.includes(pattern) || story.name.includes(pattern),
|
|
90
|
+
),
|
|
85
91
|
);
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
if (excludeStories.length > 0) {
|
|
89
95
|
filteredStories = filteredStories.filter(
|
|
90
|
-
(story) =>
|
|
96
|
+
(story) =>
|
|
97
|
+
!excludeStories.some(
|
|
98
|
+
(pattern) =>
|
|
99
|
+
story.title.includes(pattern) || story.name.includes(pattern),
|
|
100
|
+
),
|
|
91
101
|
);
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
// Filter docs etc
|
|
95
|
-
filteredStories = filteredStories.filter(
|
|
105
|
+
filteredStories = filteredStories.filter(
|
|
106
|
+
(story) => story.type === "story",
|
|
107
|
+
);
|
|
96
108
|
|
|
97
109
|
console.log(`Found ${filteredStories.length} stories to screenshot`);
|
|
98
110
|
|
|
@@ -108,9 +120,12 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
108
120
|
|
|
109
121
|
let currentLatch = createLatch<ScreenshotOptions>();
|
|
110
122
|
|
|
111
|
-
await screenshotTool.page?.exposeFunction(
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
await screenshotTool.page?.exposeFunction(
|
|
124
|
+
"__cappa_parameters",
|
|
125
|
+
async (payload: ScreenshotOptions) => {
|
|
126
|
+
currentLatch.resolve(payload);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
114
129
|
|
|
115
130
|
// Take screenshots of each story
|
|
116
131
|
for (const story of filteredStories) {
|
|
@@ -158,15 +173,19 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
158
173
|
// Take screenshot with story-specific filename
|
|
159
174
|
const filename = buildFilename(story);
|
|
160
175
|
|
|
161
|
-
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
162
|
-
|
|
163
176
|
// Actually take the screenshot
|
|
164
|
-
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
const actualFilepath = await screenshotTool.takeScreenshot(
|
|
178
|
+
page,
|
|
179
|
+
filename,
|
|
180
|
+
{
|
|
181
|
+
fullPage: options.fullPage ?? screenshotOptions.fullPage,
|
|
182
|
+
type: options.type ?? screenshotOptions.type,
|
|
183
|
+
waitForSelector:
|
|
184
|
+
options.waitForSelector ?? screenshotOptions.waitForSelector,
|
|
185
|
+
waitForTimeout:
|
|
186
|
+
options.waitForTimeout ?? screenshotOptions.waitForTimeout,
|
|
187
|
+
},
|
|
188
|
+
);
|
|
170
189
|
|
|
171
190
|
results.push({
|
|
172
191
|
storyId: story.id,
|
|
@@ -175,7 +194,10 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
175
194
|
filepath: actualFilepath,
|
|
176
195
|
});
|
|
177
196
|
} catch (error) {
|
|
178
|
-
console.error(
|
|
197
|
+
console.error(
|
|
198
|
+
`Error taking screenshot of story ${story.title} - ${story.name}:`,
|
|
199
|
+
(error as Error).message,
|
|
200
|
+
);
|
|
179
201
|
results.push({
|
|
180
202
|
storyId: story.id,
|
|
181
203
|
storyName: `${story.title} - ${story.name}`,
|
|
@@ -185,11 +207,19 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
209
|
|
|
210
|
+
// Print error report if there are any errors
|
|
188
211
|
if (results.some((r) => !r.success)) {
|
|
189
|
-
console.log(
|
|
212
|
+
console.log(
|
|
213
|
+
`Error report: \n${results
|
|
214
|
+
.filter((r) => !r.success)
|
|
215
|
+
.map((r) => `${r.storyName}: ${r.error}`)
|
|
216
|
+
.join("\n")}`,
|
|
217
|
+
);
|
|
190
218
|
}
|
|
191
219
|
|
|
192
|
-
console.log(
|
|
220
|
+
console.log(
|
|
221
|
+
`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`,
|
|
222
|
+
);
|
|
193
223
|
return results;
|
|
194
224
|
} catch (error) {
|
|
195
225
|
console.error("Error in Storybook plugin:", (error as Error).message);
|
package/src/cappa/util.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import { buildFilename } from "./util";
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
3
2
|
import type { StorybookStory } from "./plugin";
|
|
4
|
-
|
|
3
|
+
import { buildFilename } from "./util";
|
|
4
|
+
|
|
5
5
|
describe("buildFilename", () => {
|
|
6
6
|
it("should build a filename for a story", () => {
|
|
7
7
|
const story: StorybookStory = {
|
|
@@ -26,7 +26,7 @@ describe("buildFilename", () => {
|
|
|
26
26
|
story: "Story",
|
|
27
27
|
type: "story",
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
const filename = buildFilename(story);
|
|
31
31
|
expect(filename).toBe("Folder/Story/Primary.jpeg");
|
|
32
32
|
});
|
|
@@ -44,4 +44,4 @@ describe("buildFilename", () => {
|
|
|
44
44
|
const filename = buildFilename(story);
|
|
45
45
|
expect(filename).toBe("Story123/Primary123.jpeg");
|
|
46
46
|
});
|
|
47
|
-
});
|
|
47
|
+
});
|
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) =>
|
|
31
|
+
await new Promise((r) =>
|
|
32
|
+
requestAnimationFrame(() => requestAnimationFrame(r)),
|
|
33
|
+
);
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -39,4 +41,4 @@ export const waitForVisualIdle = async (page: Page) => {
|
|
|
39
41
|
*/
|
|
40
42
|
export const buildFilename = (story: StorybookStory) => {
|
|
41
43
|
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.jpeg`;
|
|
42
|
-
};
|
|
44
|
+
};
|