@cappa/plugin-storybook 0.0.13 → 0.0.14
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 +7 -4
- package/dist/index.mjs +7 -4
- package/dist/preview.mjs +1 -3
- package/package.json +6 -3
- package/src/cappa/plugin.ts +9 -8
- 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 +1 -2
- 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.13 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/preview.mjs [22m[32m1.
|
|
28
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.39 KB[39m
|
|
29
29
|
[32mESM[39m ⚡️ Build success in 7ms
|
|
30
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m5.
|
|
31
|
-
[32mESM[39m ⚡️ Build success in
|
|
32
|
-
[32mCJS[39m [1mdist/index.js [22m[32m6.99 KB[39m
|
|
33
|
-
[32mCJS[39m ⚡️ Build success in 9ms
|
|
30
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m5.81 KB[39m
|
|
31
|
+
[32mESM[39m ⚡️ Build success in 10ms
|
|
34
32
|
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
35
33
|
[32mESM[39m ⚡️ Build success in 7ms
|
|
34
|
+
[32mCJS[39m [1mdist/index.js [22m[32m7.17 KB[39m
|
|
35
|
+
[32mCJS[39m ⚡️ Build success in 10ms
|
|
36
36
|
DTS Build start
|
|
37
|
-
DTS ⚡️ Build success in
|
|
37
|
+
DTS ⚡️ Build success in 795ms
|
|
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
|
@@ -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,
|
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,
|
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.14",
|
|
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.14"
|
|
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;
|
|
@@ -126,12 +128,6 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
126
128
|
type: "jpeg" as const,
|
|
127
129
|
};
|
|
128
130
|
|
|
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
131
|
const page = screenshotTool.page;
|
|
136
132
|
if (!page) {
|
|
137
133
|
throw new Error("Page not initialized");
|
|
@@ -160,6 +156,11 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (options) =>
|
|
|
160
156
|
await page.waitForTimeout(options.delay);
|
|
161
157
|
}
|
|
162
158
|
|
|
159
|
+
// Take screenshot with story-specific filename
|
|
160
|
+
const filename = buildFilename(story);
|
|
161
|
+
|
|
162
|
+
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
|
163
|
+
|
|
163
164
|
// Actually take the screenshot
|
|
164
165
|
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
165
166
|
fullPage: options.fullPage ?? screenshotOptions.fullPage,
|
|
@@ -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
|
+
};
|