@cappa/plugin-storybook 0.0.13 → 0.0.15
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/.turbo/turbo-tsc.log +5 -0
- package/CHANGELOG.md +16 -0
- package/README.md +6 -4
- package/dist/index.js +14 -9
- package/dist/index.mjs +14 -9
- package/dist/preview.mjs +1 -3
- package/package.json +6 -3
- package/src/cappa/plugin.ts +16 -14
- package/src/cappa/util.test.ts +47 -0
- package/src/cappa/util.ts +10 -0
- package/src/storybook/addon/decorator.ts +0 -1
- package/src/storybook/addon/preview.ts +2 -8
- package/src/tsconfig.json +7 -0
- package/vitest.config.ts +8 -0
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.14 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
[34mESM[39m Build start
|
|
26
26
|
[34mCLI[39m Cleaning output folder
|
|
27
27
|
[34mESM[39m Build start
|
|
28
|
-
[32mESM[39m [1mdist/
|
|
29
|
-
[32mESM[39m ⚡️ Build success in
|
|
30
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m5.
|
|
28
|
+
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
29
|
+
[32mESM[39m ⚡️ Build success in 6ms
|
|
30
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m5.96 KB[39m
|
|
31
31
|
[32mESM[39m ⚡️ Build success in 9ms
|
|
32
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
32
|
+
[32mCJS[39m [1mdist/index.js [22m[32m7.32 KB[39m
|
|
33
33
|
[32mCJS[39m ⚡️ Build success in 9ms
|
|
34
|
-
[32mESM[39m [1mdist/
|
|
34
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.39 KB[39m
|
|
35
35
|
[32mESM[39m ⚡️ Build success in 7ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
37
|
+
DTS ⚡️ Build success in 839ms
|
|
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.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a41a91e: Add fullPage option
|
|
8
|
+
- Updated dependencies [a41a91e]
|
|
9
|
+
- @cappa/core@0.0.15
|
|
10
|
+
|
|
11
|
+
## 0.0.14
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b8af138: Screenshot Creation folders
|
|
16
|
+
- Updated dependencies [b8af138]
|
|
17
|
+
- @cappa/core@0.0.14
|
|
18
|
+
|
|
3
19
|
## 0.0.13
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -45,10 +45,11 @@ Cappa uses a storybook addon that allows you to pass options from storybook into
|
|
|
45
45
|
|
|
46
46
|
### Parameters
|
|
47
47
|
|
|
48
|
-
| Option
|
|
49
|
-
|
|
|
50
|
-
| skip
|
|
51
|
-
| delay
|
|
48
|
+
| Option | Description | Default |
|
|
49
|
+
| -------- | ----------------------------------------------- | --------------- |
|
|
50
|
+
| skip | Whether to skip the screenshot | false |
|
|
51
|
+
| delay | The delay to wait before taking the screenshot | null (no delay) |
|
|
52
|
+
| fullPage | Whether to take a full page screenshot | true |
|
|
52
53
|
|
|
53
54
|
#### Example
|
|
54
55
|
|
|
@@ -58,6 +59,7 @@ export const Primary: Story = {
|
|
|
58
59
|
cappa: {
|
|
59
60
|
skip: true,
|
|
60
61
|
delay: 1000,
|
|
62
|
+
fullPage: false,
|
|
61
63
|
},
|
|
62
64
|
},
|
|
63
65
|
};
|
package/dist/index.js
CHANGED
|
@@ -52,8 +52,13 @@ var waitForVisualIdle = async (page) => {
|
|
|
52
52
|
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
53
53
|
});
|
|
54
54
|
};
|
|
55
|
+
var buildFilename = (story) => {
|
|
56
|
+
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.jpeg`;
|
|
57
|
+
};
|
|
55
58
|
|
|
56
59
|
// src/cappa/plugin.ts
|
|
60
|
+
var import_path = __toESM(require("path"));
|
|
61
|
+
var import_fs = __toESM(require("fs"));
|
|
57
62
|
function createLatch() {
|
|
58
63
|
let resolve;
|
|
59
64
|
const p = new Promise((r) => resolve = r);
|
|
@@ -118,10 +123,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
118
123
|
quality: 90,
|
|
119
124
|
type: "jpeg"
|
|
120
125
|
};
|
|
121
|
-
const filename = `${story.title.replace(
|
|
122
|
-
/[^a-zA-Z0-9]/g,
|
|
123
|
-
"_"
|
|
124
|
-
)}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
|
|
125
126
|
const page = screenshotTool.page;
|
|
126
127
|
if (!page) {
|
|
127
128
|
throw new Error("Page not initialized");
|
|
@@ -143,6 +144,8 @@ var cappaPluginStorybook = (options) => {
|
|
|
143
144
|
if (options2.delay) {
|
|
144
145
|
await page.waitForTimeout(options2.delay);
|
|
145
146
|
}
|
|
147
|
+
const filename = buildFilename(story);
|
|
148
|
+
import_fs.default.mkdirSync(import_path.default.dirname(filename), { recursive: true });
|
|
146
149
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
147
150
|
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
148
151
|
type: options2.type ?? screenshotOptions.type,
|
|
@@ -151,8 +154,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
151
154
|
});
|
|
152
155
|
results.push({
|
|
153
156
|
storyId: story.id,
|
|
154
|
-
storyName: story.name
|
|
155
|
-
storyTitle: story.title,
|
|
157
|
+
storyName: `${story.title} - ${story.name}`,
|
|
156
158
|
success: true,
|
|
157
159
|
filepath: actualFilepath
|
|
158
160
|
});
|
|
@@ -160,13 +162,16 @@ var cappaPluginStorybook = (options) => {
|
|
|
160
162
|
console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, error.message);
|
|
161
163
|
results.push({
|
|
162
164
|
storyId: story.id,
|
|
163
|
-
storyName: story.name
|
|
164
|
-
storyTitle: story.title,
|
|
165
|
+
storyName: `${story.title} - ${story.name}`,
|
|
165
166
|
success: false,
|
|
166
|
-
error: error
|
|
167
|
+
error: error?.message ?? "Unknown error"
|
|
167
168
|
});
|
|
168
169
|
}
|
|
169
170
|
}
|
|
171
|
+
if (results.some((r) => !r.success)) {
|
|
172
|
+
console.log(`Error report:
|
|
173
|
+
${results.map((r) => `${r.storyName}: ${r.error}`).join("\n")}`);
|
|
174
|
+
}
|
|
170
175
|
console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
|
|
171
176
|
return results;
|
|
172
177
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -22,8 +22,13 @@ var waitForVisualIdle = async (page) => {
|
|
|
22
22
|
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
+
var buildFilename = (story) => {
|
|
26
|
+
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.jpeg`;
|
|
27
|
+
};
|
|
25
28
|
|
|
26
29
|
// src/cappa/plugin.ts
|
|
30
|
+
import path from "path";
|
|
31
|
+
import fs from "fs";
|
|
27
32
|
function createLatch() {
|
|
28
33
|
let resolve;
|
|
29
34
|
const p = new Promise((r) => resolve = r);
|
|
@@ -88,10 +93,6 @@ var cappaPluginStorybook = (options) => {
|
|
|
88
93
|
quality: 90,
|
|
89
94
|
type: "jpeg"
|
|
90
95
|
};
|
|
91
|
-
const filename = `${story.title.replace(
|
|
92
|
-
/[^a-zA-Z0-9]/g,
|
|
93
|
-
"_"
|
|
94
|
-
)}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
|
|
95
96
|
const page = screenshotTool.page;
|
|
96
97
|
if (!page) {
|
|
97
98
|
throw new Error("Page not initialized");
|
|
@@ -113,6 +114,8 @@ var cappaPluginStorybook = (options) => {
|
|
|
113
114
|
if (options2.delay) {
|
|
114
115
|
await page.waitForTimeout(options2.delay);
|
|
115
116
|
}
|
|
117
|
+
const filename = buildFilename(story);
|
|
118
|
+
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
116
119
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
117
120
|
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
118
121
|
type: options2.type ?? screenshotOptions.type,
|
|
@@ -121,8 +124,7 @@ var cappaPluginStorybook = (options) => {
|
|
|
121
124
|
});
|
|
122
125
|
results.push({
|
|
123
126
|
storyId: story.id,
|
|
124
|
-
storyName: story.name
|
|
125
|
-
storyTitle: story.title,
|
|
127
|
+
storyName: `${story.title} - ${story.name}`,
|
|
126
128
|
success: true,
|
|
127
129
|
filepath: actualFilepath
|
|
128
130
|
});
|
|
@@ -130,13 +132,16 @@ var cappaPluginStorybook = (options) => {
|
|
|
130
132
|
console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, error.message);
|
|
131
133
|
results.push({
|
|
132
134
|
storyId: story.id,
|
|
133
|
-
storyName: story.name
|
|
134
|
-
storyTitle: story.title,
|
|
135
|
+
storyName: `${story.title} - ${story.name}`,
|
|
135
136
|
success: false,
|
|
136
|
-
error: error
|
|
137
|
+
error: error?.message ?? "Unknown error"
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
if (results.some((r) => !r.success)) {
|
|
142
|
+
console.log(`Error report:
|
|
143
|
+
${results.map((r) => `${r.storyName}: ${r.error}`).join("\n")}`);
|
|
144
|
+
}
|
|
140
145
|
console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
|
|
141
146
|
return results;
|
|
142
147
|
} catch (error) {
|
package/dist/preview.mjs
CHANGED
|
@@ -28,7 +28,6 @@ var withCappaDecorator = makeDecorator({
|
|
|
28
28
|
const hasPlayFunction = context.playFunction != null;
|
|
29
29
|
queueMicrotask(async () => {
|
|
30
30
|
try {
|
|
31
|
-
console.log("hasPlayFunction", hasPlayFunction);
|
|
32
31
|
const cappaParameters = await waitForExposed("__cappa_parameters");
|
|
33
32
|
cappaParameters(parameters2 ?? {});
|
|
34
33
|
} catch (error) {
|
|
@@ -47,8 +46,7 @@ var parameters = {
|
|
|
47
46
|
enabled: true
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
|
-
var afterEach = (
|
|
51
|
-
console.log("afterEach", context);
|
|
49
|
+
var afterEach = () => {
|
|
52
50
|
window.playAfterEach = true;
|
|
53
51
|
};
|
|
54
52
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,12 +30,15 @@
|
|
|
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.15"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"playwright-core": "^1.55.0",
|
|
37
37
|
"tsup": "8.5.0",
|
|
38
|
-
"typescript": "5.7.3"
|
|
38
|
+
"typescript": "5.7.3",
|
|
39
|
+
"vitest": "3.2.4",
|
|
40
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
41
|
+
"@vitest/ui": "3.2.4"
|
|
39
42
|
},
|
|
40
43
|
"scripts": {
|
|
41
44
|
"test": "vitest",
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Plugin, ScreenshotOptions, ScreenshotTool } from "@cappa/core";
|
|
2
|
-
import { freezeUI, waitForVisualIdle } from "./util";
|
|
2
|
+
import { buildFilename, freezeUI, waitForVisualIdle } from "./util";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import fs from "fs";
|
|
3
5
|
|
|
4
|
-
interface StorybookStory {
|
|
6
|
+
export interface StorybookStory {
|
|
5
7
|
id: string;
|
|
6
8
|
name: string;
|
|
7
9
|
title: string;
|
|
@@ -97,7 +99,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
97
99
|
const results: Array<{
|
|
98
100
|
storyId: string;
|
|
99
101
|
storyName: string;
|
|
100
|
-
storyTitle: string;
|
|
101
102
|
success: boolean;
|
|
102
103
|
filepath?: string;
|
|
103
104
|
error?: string;
|
|
@@ -126,12 +127,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
126
127
|
type: "jpeg" as const,
|
|
127
128
|
};
|
|
128
129
|
|
|
129
|
-
// Take screenshot with story-specific filename
|
|
130
|
-
const filename = `${story.title.replace(
|
|
131
|
-
/[^a-zA-Z0-9]/g,
|
|
132
|
-
"_",
|
|
133
|
-
)}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
|
|
134
|
-
|
|
135
130
|
const page = screenshotTool.page;
|
|
136
131
|
if (!page) {
|
|
137
132
|
throw new Error("Page not initialized");
|
|
@@ -160,6 +155,11 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
160
155
|
await page.waitForTimeout(options.delay);
|
|
161
156
|
}
|
|
162
157
|
|
|
158
|
+
// Take screenshot with story-specific filename
|
|
159
|
+
const filename = buildFilename(story);
|
|
160
|
+
|
|
161
|
+
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
162
|
+
|
|
163
163
|
// Actually take the screenshot
|
|
164
164
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
165
165
|
fullPage: options.fullPage ?? screenshotOptions.fullPage,
|
|
@@ -170,8 +170,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
170
170
|
|
|
171
171
|
results.push({
|
|
172
172
|
storyId: story.id,
|
|
173
|
-
storyName: story.name
|
|
174
|
-
storyTitle: story.title,
|
|
173
|
+
storyName: `${story.title} - ${story.name}`,
|
|
175
174
|
success: true,
|
|
176
175
|
filepath: actualFilepath,
|
|
177
176
|
});
|
|
@@ -179,14 +178,17 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
179
178
|
console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, (error as Error).message);
|
|
180
179
|
results.push({
|
|
181
180
|
storyId: story.id,
|
|
182
|
-
storyName: story.name
|
|
183
|
-
storyTitle: story.title,
|
|
181
|
+
storyName: `${story.title} - ${story.name}`,
|
|
184
182
|
success: false,
|
|
185
|
-
error: (error as Error)
|
|
183
|
+
error: (error as Error)?.message ?? "Unknown error",
|
|
186
184
|
});
|
|
187
185
|
}
|
|
188
186
|
}
|
|
189
187
|
|
|
188
|
+
if (results.some((r) => !r.success)) {
|
|
189
|
+
console.log(`Error report: \n${results.map((r) => `${r.storyName}: ${r.error}`).join("\n")}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
190
192
|
console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
|
|
191
193
|
return results;
|
|
192
194
|
} catch (error) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { buildFilename } from "./util";
|
|
3
|
+
import type { StorybookStory } from "./plugin";
|
|
4
|
+
|
|
5
|
+
describe("buildFilename", () => {
|
|
6
|
+
it("should build a filename for a story", () => {
|
|
7
|
+
const story: StorybookStory = {
|
|
8
|
+
id: "1",
|
|
9
|
+
name: "Primary",
|
|
10
|
+
title: "Story",
|
|
11
|
+
kind: "Kind",
|
|
12
|
+
story: "Story",
|
|
13
|
+
type: "story",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const filename = buildFilename(story);
|
|
17
|
+
expect(filename).toBe("Story/Primary.jpeg");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should build a filename for a story with a folder", () => {
|
|
21
|
+
const story: StorybookStory = {
|
|
22
|
+
id: "1",
|
|
23
|
+
name: "Primary",
|
|
24
|
+
title: "Folder/Story",
|
|
25
|
+
kind: "Kind",
|
|
26
|
+
story: "Story",
|
|
27
|
+
type: "story",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const filename = buildFilename(story);
|
|
31
|
+
expect(filename).toBe("Folder/Story/Primary.jpeg");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should build a filename for a story with special characters", () => {
|
|
35
|
+
const story: StorybookStory = {
|
|
36
|
+
id: "1",
|
|
37
|
+
name: "Primary123!@#$%^&*()",
|
|
38
|
+
title: "Story123!@#$%^&*()",
|
|
39
|
+
kind: "Kind",
|
|
40
|
+
story: "Story",
|
|
41
|
+
type: "story",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const filename = buildFilename(story);
|
|
45
|
+
expect(filename).toBe("Story123/Primary123.jpeg");
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/cappa/util.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Page } from "playwright-core";
|
|
2
|
+
import type { StorybookStory } from "./plugin";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Disable CSS transitions, animations, and scrollbars
|
|
@@ -30,3 +31,12 @@ export const waitForVisualIdle = async (page: Page) => {
|
|
|
30
31
|
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
31
32
|
});
|
|
32
33
|
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Build a filename for a story.
|
|
37
|
+
* @param story - The story to build a filename for
|
|
38
|
+
* @returns The filename for the story. Slashes represent folders that should be handled by seperate file system calls.
|
|
39
|
+
*/
|
|
40
|
+
export const buildFilename = (story: StorybookStory) => {
|
|
41
|
+
return `${story.title.replace(/[^a-zA-Z0-9/]/g, "")}/${story.name.replace(/[^a-zA-Z0-9]/g, "")}.jpeg`;
|
|
42
|
+
};
|
|
@@ -2,14 +2,8 @@ import { withCappaDecorator } from "./decorator";
|
|
|
2
2
|
|
|
3
3
|
export const decorators = [withCappaDecorator];
|
|
4
4
|
|
|
5
|
-
export const parameters = {
|
|
6
|
-
layout: "full",
|
|
7
|
-
cappa: {
|
|
8
|
-
enabled: true,
|
|
9
|
-
},
|
|
10
|
-
};
|
|
5
|
+
export const parameters = {};
|
|
11
6
|
|
|
12
|
-
export const afterEach = (
|
|
13
|
-
console.log("afterEach", context);
|
|
7
|
+
export const afterEach = () => {
|
|
14
8
|
(window as any).playAfterEach = true;
|
|
15
9
|
};
|