@cappa/plugin-storybook 0.3.2 → 0.4.0

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.2 build /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook
2
+ > @cappa/plugin-storybook@0.4.0 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"}
@@ -31,13 +31,13 @@
31
31
  CLI Cleaning output folder
32
32
  ESM Build start
33
33
  ESM dist/browser.js 138.00 B
34
- ESM ⚡️ Build success in 30ms
34
+ ESM ⚡️ Build success in 26ms
35
35
  ESM dist/preview.js 1.58 KB
36
- ESM ⚡️ Build success in 33ms
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 48ms
36
+ ESM ⚡️ Build success in 41ms
37
+ ESM dist/index.js 12.35 KB
38
+ ESM ⚡️ Build success in 58ms
39
+ CJS dist/index.cjs 14.08 KB
40
+ CJS ⚡️ Build success in 50ms
41
41
  DTS Build start
42
- DTS ⚡️ Build success in 3603ms
43
- DTS dist/index.d.ts 2.63 KB
42
+ DTS ⚡️ Build success in 3847ms
43
+ DTS dist/index.d.ts 2.66 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @cappa/plugin-storybook
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 915be10: Add a `logConsoleEvents` base configuration option that controls whether Playwright console
8
+ messages are logged during captures, and have the Storybook plugin respect the global setting.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [915be10]
13
+ - Updated dependencies [1e8f301]
14
+ - @cappa/core@0.4.0
15
+ - @cappa/logger@0.0.5
16
+
17
+ ## 0.3.3
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [772d0f6]
22
+ - @cappa/core@0.3.1
23
+
3
24
  ## 0.3.2
4
25
 
5
26
  ### Patch Changes
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
  });
package/dist/index.d.ts CHANGED
@@ -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 };
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.2",
3
+ "version": "0.4.0",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -44,8 +44,8 @@
44
44
  "@swc/core": "^1.14.0",
45
45
  "chalk": "^5.6.2",
46
46
  "minimatch": "^10.1.1",
47
- "@cappa/core": "0.3.0",
48
- "@cappa/logger": "0.0.4"
47
+ "@cappa/core": "0.4.0",
48
+ "@cappa/logger": "0.0.5"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "24.9.2",
@@ -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";