@cappa/plugin-storybook 0.3.3 → 0.4.1

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,5 +1,5 @@
1
1
 
2
- > @cappa/plugin-storybook@0.3.3 build /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook
2
+ > @cappa/plugin-storybook@0.4.1 build /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: {"index":"src/index.esm.ts"}
@@ -20,24 +20,34 @@
20
20
  CLI Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
21
21
  CLI Target: esnext
22
22
  CLI Target: esnext
23
+ CLI Target: node16
24
+ CLI Target: es2015
23
25
  CLI Cleaning output folder
24
26
  ESM Build start
25
27
  CLI Cleaning output folder
26
28
  CJS Build start
27
- CLI Target: node16
28
- CLI Target: es2015
29
29
  CLI Cleaning output folder
30
30
  ESM Build start
31
31
  CLI Cleaning output folder
32
32
  ESM Build start
33
+ CJS Build start
33
34
  ESM dist/browser.js 138.00 B
34
- ESM ⚡️ Build success in 26ms
35
+ ESM ⚡️ Build success in 62ms
36
+ CJS dist/browser.cjs 1.12 KB
37
+ CJS ⚡️ Build success in 65ms
35
38
  ESM dist/preview.js 1.58 KB
36
- ESM ⚡️ Build success in 41ms
37
- CJS dist/index.cjs 13.98 KB
38
- CJS ⚡️ Build success in 45ms
39
- ESM dist/index.js 12.25 KB
40
- ESM ⚡️ Build success in 54ms
39
+ ESM ⚡️ Build success in 74ms
40
+ CJS dist/index.cjs 14.08 KB
41
+ CJS ⚡️ Build success in 86ms
42
+ ESM dist/index.js 12.35 KB
43
+ ESM ⚡️ Build success in 94ms
44
+ DTS Build start
45
+ DTS Build start
41
46
  DTS Build start
42
- DTS ⚡️ Build success in 3394ms
43
- DTS dist/index.d.ts 2.63 KB
47
+ DTS ⚡️ Build success in 5054ms
48
+ DTS dist/browser.d.ts 117.00 B
49
+ DTS dist/browser.d.cts 117.00 B
50
+ DTS ⚡️ Build success in 6179ms
51
+ DTS dist/index.esm.d.ts 2.66 KB
52
+ DTS ⚡️ Build success in 6343ms
53
+ DTS dist/index.cjs.d.cts 2.66 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 298486b: fix: package export types
8
+ - Updated dependencies [298486b]
9
+ - @cappa/logger@0.0.6
10
+ - @cappa/core@0.4.1
11
+
12
+ ## 0.4.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 915be10: Add a `logConsoleEvents` base configuration option that controls whether Playwright console
17
+ messages are logged during captures, and have the Storybook plugin respect the global setting.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [915be10]
22
+ - Updated dependencies [1e8f301]
23
+ - @cappa/core@0.4.0
24
+ - @cappa/logger@0.0.5
25
+
3
26
  ## 0.3.3
4
27
 
5
28
  ### Patch Changes
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/storybook/addon/browser.ts
21
+ var browser_exports = {};
22
+ __export(browser_exports, {
23
+ isCappa: () => isCappa
24
+ });
25
+ module.exports = __toCommonJS(browser_exports);
26
+ var isCappa = () => {
27
+ return navigator.userAgent.includes("CappaStorybook");
28
+ };
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ isCappa
32
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if the current window is a cappa window
3
+ */
4
+ declare const isCappa: () => boolean;
5
+
6
+ export { isCappa };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if the current window is a cappa window
3
+ */
4
+ declare const isCappa: () => boolean;
5
+
6
+ export { isCappa };
package/dist/index.cjs CHANGED
@@ -271,6 +271,7 @@ var cappaPluginStorybook = (options) => {
271
271
  const { story } = data;
272
272
  const logger = (0, import_logger.getLogger)();
273
273
  const { storybook: defaultStorybookOptions } = options || {};
274
+ const { logConsoleEvents = true } = screenshotTool;
274
275
  try {
275
276
  const currentLatch = createLatch();
276
277
  context.latchMap.set(story.id, currentLatch);
@@ -284,9 +285,11 @@ var cappaPluginStorybook = (options) => {
284
285
  }
285
286
  );
286
287
  }
287
- page.on("console", (message) => {
288
- logger.debug("console", message.text());
289
- });
288
+ if (logConsoleEvents) {
289
+ page.on("console", (message) => {
290
+ logger.debug("console", message.text());
291
+ });
292
+ }
290
293
  page.on("pageerror", (error) => {
291
294
  logger.debug("pageerror", error);
292
295
  });
@@ -78,4 +78,4 @@ declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
78
78
 
79
79
  declare const previewAnnotations: string[];
80
80
 
81
- export { type ScreenshotOptionsStorybook as CappaStorybookOptions, cappaPluginStorybook, previewAnnotations };
81
+ export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
@@ -0,0 +1,81 @@
1
+ import { Plugin } from '@cappa/core';
2
+
3
+ interface StorybookRenderOptions {
4
+ viewMode?: "story" | "docs";
5
+ args?: Record<string, unknown>;
6
+ globals?: Record<string, string | number | boolean>;
7
+ query?: Record<string, string | number | boolean>;
8
+ fullscreen?: boolean;
9
+ singleStory?: boolean;
10
+ }
11
+ interface ScreenshotVariantOverrideStorybook {
12
+ fullPage?: boolean;
13
+ delay?: number;
14
+ skip?: boolean;
15
+ mask?: string[];
16
+ omitBackground?: boolean;
17
+ viewport?: {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ args?: Record<string, unknown>;
22
+ }
23
+ interface ScreenshotVariantOptionsStorybook {
24
+ id: string;
25
+ label?: string;
26
+ filename?: string;
27
+ options?: ScreenshotVariantOverrideStorybook;
28
+ }
29
+ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook {
30
+ variants?: ScreenshotVariantOptionsStorybook[];
31
+ }
32
+
33
+ interface StorybookPluginOptions {
34
+ storybookUrl: string;
35
+ /**
36
+ * Array of glob patterns to include stories. Stories matching any of these patterns will be included.
37
+ * Patterns can match against:
38
+ * - Story ID (e.g., "button--primary")
39
+ * - Story title (e.g., "Button")
40
+ * - Story name (e.g., "Primary")
41
+ * - Full story path (e.g., "Button/Primary")
42
+ *
43
+ * Examples:
44
+ * - ["button--*"] - Include all button stories
45
+ * - ["*--primary"] - Include all primary stories
46
+ * - ["Button/*"] - Include all stories under Button title
47
+ * - ["*--*"] - Include all stories
48
+ */
49
+ includeStories?: string[];
50
+ /**
51
+ * Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
52
+ * Patterns can match against:
53
+ * - Story ID (e.g., "button--primary")
54
+ * - Story title (e.g., "Button")
55
+ * - Story name (e.g., "Primary")
56
+ * - Full story path (e.g., "Button/Primary")
57
+ *
58
+ * Examples:
59
+ * - ["button--*"] - Exclude all button stories
60
+ * - ["*--secondary"] - Exclude all secondary stories
61
+ * - ["Input/*"] - Exclude all stories under Input title
62
+ */
63
+ excludeStories?: string[];
64
+ defaultViewport?: {
65
+ width: number;
66
+ height: number;
67
+ };
68
+ waitForSelector?: string;
69
+ waitForTimeout?: number;
70
+ storybook?: StorybookRenderOptions;
71
+ }
72
+ /**
73
+ * Storybook Plugin for Cappa
74
+ * Fetches stories from a running Storybook server and takes screenshots of each story.
75
+ * Supports glob pattern matching for includeStories and excludeStories options.
76
+ */
77
+ declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
78
+
79
+ declare const previewAnnotations: string[];
80
+
81
+ export { type ScreenshotOptionsStorybook as CappaStorybookOptions, type StorybookPluginOptions, cappaPluginStorybook, previewAnnotations };
package/dist/index.js CHANGED
@@ -237,6 +237,7 @@ var cappaPluginStorybook = (options) => {
237
237
  const { story } = data;
238
238
  const logger = getLogger();
239
239
  const { storybook: defaultStorybookOptions } = options || {};
240
+ const { logConsoleEvents = true } = screenshotTool;
240
241
  try {
241
242
  const currentLatch = createLatch();
242
243
  context.latchMap.set(story.id, currentLatch);
@@ -250,9 +251,11 @@ var cappaPluginStorybook = (options) => {
250
251
  }
251
252
  );
252
253
  }
253
- page.on("console", (message) => {
254
- logger.debug("console", message.text());
255
- });
254
+ if (logConsoleEvents) {
255
+ page.on("console", (message) => {
256
+ logger.debug("console", message.text());
257
+ });
258
+ }
256
259
  page.on("pageerror", (error) => {
257
260
  logger.debug("pageerror", error);
258
261
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/plugin-storybook",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,15 +14,27 @@
14
14
  "type": "module",
15
15
  "main": "./dist/index.cjs",
16
16
  "module": "./dist/index.js",
17
- "types": "./dist/index.d.ts",
17
+ "types": "./dist/index.esm.d.ts",
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "require": "./dist/index.cjs",
22
- "import": "./dist/index.js"
20
+ "import": {
21
+ "types": "./dist/index.esm.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.cjs.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
23
28
  },
24
29
  "./browser": {
25
- "default": "./dist/browser.js"
30
+ "import": {
31
+ "types": "./dist/browser.d.ts",
32
+ "default": "./dist/browser.js"
33
+ },
34
+ "require": {
35
+ "types": "./dist/browser.d.cts",
36
+ "default": "./dist/browser.cjs"
37
+ }
26
38
  },
27
39
  "./package.json": "./package.json"
28
40
  },
@@ -44,8 +56,8 @@
44
56
  "@swc/core": "^1.14.0",
45
57
  "chalk": "^5.6.2",
46
58
  "minimatch": "^10.1.1",
47
- "@cappa/core": "0.3.1",
48
- "@cappa/logger": "0.0.4"
59
+ "@cappa/core": "0.4.1",
60
+ "@cappa/logger": "0.0.6"
49
61
  },
50
62
  "devDependencies": {
51
63
  "@types/node": "24.9.2",
@@ -55,11 +67,13 @@
55
67
  "tsup": "8.5.0",
56
68
  "typescript": "5.9.3",
57
69
  "vitest": "4.0.6",
58
- "storybook": "^10.0.2"
70
+ "storybook": "^10.0.2",
71
+ "@arethetypeswrong/cli": "0.18.2"
59
72
  },
60
73
  "scripts": {
61
74
  "test": "vitest",
62
75
  "build": "tsup",
63
- "tsc": "tsc"
76
+ "tsc": "tsc",
77
+ "attw": "attw --pack --profile node16 ."
64
78
  }
65
79
  }
@@ -11,6 +11,18 @@ vi.mock("@cappa/logger", () => ({
11
11
  }),
12
12
  }));
13
13
 
14
+ vi.mock("./util", () => ({
15
+ buildFilename: vi.fn(() => "button--primary.png"),
16
+ freezeUI: vi.fn(async () => {}),
17
+ waitForVisualIdle: vi.fn(async () => {}),
18
+ }));
19
+
20
+ vi.mock("./storybook-url", () => ({
21
+ buildStorybookIframeUrl: vi.fn(
22
+ () => "http://localhost:6006/iframe.html?id=story",
23
+ ),
24
+ }));
25
+
14
26
  // Mock fetch
15
27
  global.fetch = vi.fn();
16
28
 
@@ -78,6 +90,7 @@ describe("cappaPluginStorybook - Glob Pattern Matching", () => {
78
90
 
79
91
  beforeEach(() => {
80
92
  vi.clearAllMocks();
93
+ (global.fetch as any).mockReset();
81
94
  (global.fetch as any).mockResolvedValue({
82
95
  ok: true,
83
96
  json: () => Promise.resolve(mockStorybookResponse),
@@ -378,3 +391,134 @@ describe("cappaPluginStorybook - Glob Pattern Matching", () => {
378
391
  });
379
392
  });
380
393
  });
394
+
395
+ describe("console logging configuration", () => {
396
+ const story: StorybookStory = {
397
+ id: "button--primary",
398
+ name: "Primary",
399
+ title: "Button",
400
+ kind: "Button",
401
+ story: "Primary",
402
+ type: "story",
403
+ };
404
+
405
+ beforeEach(() => {
406
+ vi.clearAllMocks();
407
+ });
408
+
409
+ const createPage = () => {
410
+ const exposedFunctions: Record<
411
+ string,
412
+ (id: string, payload: unknown) => unknown
413
+ > = {};
414
+
415
+ return {
416
+ on: vi.fn(),
417
+ evaluate: vi.fn(async (fn: any) => {
418
+ if (typeof fn === "function") {
419
+ const source = fn.toString();
420
+ if (source.includes("__cappa_parameters")) {
421
+ return true;
422
+ }
423
+ if (source.includes("__cappa_has_play_function")) {
424
+ return false;
425
+ }
426
+ }
427
+
428
+ return undefined;
429
+ }),
430
+ exposeFunction: vi.fn(
431
+ async (name: string, fn: (id: string, payload: unknown) => unknown) => {
432
+ exposedFunctions[name] = fn;
433
+ },
434
+ ),
435
+ goto: vi.fn(async () => {
436
+ await exposedFunctions.__cappa_parameters?.(story.id, {
437
+ viewport: { width: 800, height: 600 },
438
+ });
439
+ }),
440
+ setViewportSize: vi.fn(async () => {}),
441
+ viewportSize: vi.fn(() => ({ width: 1024, height: 768 })),
442
+ waitForTimeout: vi.fn(async () => {}),
443
+ locator: vi.fn(() => ({ locator: true })),
444
+ waitForFunction: vi.fn(async () => {}),
445
+ };
446
+ };
447
+
448
+ const createScreenshotTool = () => ({
449
+ viewport: { width: 1024, height: 768 },
450
+ logConsoleEvents: true,
451
+ getVariantFilename: vi.fn(
452
+ (filename: string, variant: { id: string }) =>
453
+ `${filename}-${variant.id}.png`,
454
+ ),
455
+ captureWithVariants: vi.fn(async () => ({
456
+ base: {
457
+ filename: "button--primary.png",
458
+ filepath: "button--primary.png",
459
+ skipped: false,
460
+ comparisonResult: { passed: true },
461
+ },
462
+ variants: [],
463
+ })),
464
+ });
465
+
466
+ const createTask = () => ({
467
+ id: story.id,
468
+ url: "http://localhost:6006/iframe.html?id=button--primary",
469
+ data: { story },
470
+ });
471
+
472
+ it("logs console events by default", async () => {
473
+ const plugin = cappaPluginStorybook({
474
+ storybookUrl: "http://localhost:6006",
475
+ });
476
+
477
+ const page = createPage();
478
+ const screenshotTool = createScreenshotTool();
479
+ const context = (await plugin.initPage?.()) ?? { latchMap: new Map() };
480
+
481
+ await plugin.execute(
482
+ createTask(),
483
+ page as any,
484
+ screenshotTool as any,
485
+ context,
486
+ );
487
+
488
+ expect(
489
+ (page.on as any).mock.calls.some(
490
+ ([event]: [string]) => event === "console",
491
+ ),
492
+ ).toBe(true);
493
+ });
494
+
495
+ it("skips console logging when disabled", async () => {
496
+ const page = createPage();
497
+ const screenshotTool = {
498
+ ...createScreenshotTool(),
499
+ logConsoleEvents: false,
500
+ };
501
+ const plugin = cappaPluginStorybook({
502
+ storybookUrl: "http://localhost:6006",
503
+ });
504
+ const context = (await plugin.initPage?.()) ?? { latchMap: new Map() };
505
+
506
+ await plugin.execute(
507
+ createTask(),
508
+ page as any,
509
+ screenshotTool as any,
510
+ context,
511
+ );
512
+
513
+ expect(
514
+ (page.on as any).mock.calls.some(
515
+ ([event]: [string]) => event === "console",
516
+ ),
517
+ ).toBe(false);
518
+ expect(
519
+ (page.on as any).mock.calls.some(
520
+ ([event]: [string]) => event === "pageerror",
521
+ ),
522
+ ).toBe(true);
523
+ });
524
+ });
@@ -104,7 +104,7 @@ interface StorybookStoriesResponse {
104
104
  entries: Record<string, StorybookStory>;
105
105
  }
106
106
 
107
- interface StorybookPluginOptions {
107
+ export interface StorybookPluginOptions {
108
108
  storybookUrl: string;
109
109
  /**
110
110
  * Array of glob patterns to include stories. Stories matching any of these patterns will be included.
@@ -254,6 +254,7 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
254
254
  const { story } = data;
255
255
  const logger = getLogger();
256
256
  const { storybook: defaultStorybookOptions } = options || {};
257
+ const { logConsoleEvents = true } = screenshotTool;
257
258
 
258
259
  try {
259
260
  // Setup exposed function for this page
@@ -273,9 +274,11 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
273
274
  );
274
275
  }
275
276
 
276
- page.on("console", (message) => {
277
- logger.debug("console", message.text());
278
- });
277
+ if (logConsoleEvents) {
278
+ page.on("console", (message) => {
279
+ logger.debug("console", message.text());
280
+ });
281
+ }
279
282
  page.on("pageerror", (error) => {
280
283
  logger.debug("pageerror", error);
281
284
  });
package/src/index.cjs.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export const previewAnnotations = [require.resolve("./preview.js")];
2
2
 
3
+ export type { StorybookPluginOptions } from "./cappa/plugin";
3
4
  export { cappaPluginStorybook } from "./cappa/plugin";
4
5
  export type { ScreenshotOptionsStorybook as CappaStorybookOptions } from "./types";
package/src/index.esm.ts CHANGED
@@ -4,5 +4,6 @@ export const previewAnnotations = [
4
4
  fileURLToPath(new URL("./preview.js", import.meta.url)),
5
5
  ];
6
6
 
7
+ export type { StorybookPluginOptions } from "./cappa/plugin";
7
8
  export { cappaPluginStorybook } from "./cappa/plugin";
8
9
  export type { ScreenshotOptionsStorybook as CappaStorybookOptions } from "./types";
package/tsup.config.ts CHANGED
@@ -4,7 +4,7 @@ export default defineConfig([
4
4
  {
5
5
  entry: { index: "src/index.esm.ts" },
6
6
  format: ["esm"],
7
- dts: true,
7
+ dts: { entry: "src/index.esm.ts" },
8
8
  splitting: false,
9
9
  external: ["./preview.js"],
10
10
  sourcemap: false,
@@ -13,6 +13,7 @@ export default defineConfig([
13
13
  {
14
14
  entry: { index: "src/index.cjs.ts" },
15
15
  format: ["cjs"],
16
+ dts: { entry: "src/index.cjs.ts" },
16
17
  splitting: false,
17
18
  external: ["./preview.js"],
18
19
  sourcemap: false,
@@ -29,7 +30,8 @@ export default defineConfig([
29
30
  {
30
31
  entry: ["src/storybook/addon/browser.ts"],
31
32
  target: "es2015",
32
- format: ["esm"],
33
+ format: ["esm", "cjs"],
34
+ dts: true,
33
35
  splitting: false,
34
36
  sourcemap: false,
35
37
  clean: true,