@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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- > @cappa/plugin-storybook@0.0.12 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
3
+ > @cappa/plugin-storybook@0.0.13 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: src/index.ts
@@ -25,15 +25,15 @@
25
25
  ESM Build start
26
26
  CLI Cleaning output folder
27
27
  ESM Build start
28
- ESM dist/preview.mjs 1.49 KB
28
+ ESM dist/preview.mjs 1.39 KB
29
29
  ESM ⚡️ Build success in 7ms
30
- ESM dist/index.mjs 5.70 KB
31
- ESM ⚡️ Build success in 9ms
32
- CJS dist/index.js 6.99 KB
33
- CJS ⚡️ Build success in 9ms
30
+ ESM dist/index.mjs 5.81 KB
31
+ ESM ⚡️ Build success in 10ms
34
32
  ESM dist/browser.mjs 138.00 B
35
33
  ESM ⚡️ Build success in 7ms
34
+ CJS dist/index.js 7.17 KB
35
+ CJS ⚡️ Build success in 10ms
36
36
  DTS Build start
37
- DTS ⚡️ Build success in 843ms
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
@@ -1,5 +1,13 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - b8af138: Screenshot Creation folders
8
+ - Updated dependencies [b8af138]
9
+ - @cappa/core@0.0.14
10
+
3
11
  ## 0.0.13
4
12
 
5
13
  ### Patch Changes
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 = (context) => {
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.13",
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.13"
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",
@@ -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
+ };
@@ -12,7 +12,6 @@ export const withCappaDecorator = makeDecorator({
12
12
 
13
13
  queueMicrotask(async () => {
14
14
  try {
15
- console.log("hasPlayFunction", hasPlayFunction);
16
15
  const cappaParameters = await waitForExposed("__cappa_parameters");
17
16
 
18
17
  cappaParameters(parameters ?? {});
@@ -9,7 +9,6 @@ export const parameters = {
9
9
  },
10
10
  };
11
11
 
12
- export const afterEach = (context) => {
13
- console.log("afterEach", context);
12
+ export const afterEach = () => {
14
13
  (window as any).playAfterEach = true;
15
14
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@cappa/config-ts/base.json",
3
+ "compilerOptions": {
4
+ "types": ["vitest/globals"],
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ dir: "./src",
6
+ include: ["**/*.test.ts"],
7
+ },
8
+ });