@cappa/core 0.1.3 → 0.2.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.
package/src/index.ts CHANGED
@@ -1,15 +1,38 @@
1
1
  import { defineConfig } from "./config";
2
+ import { ScreenshotFileSystem } from "./filesystem";
2
3
  import type { Plugin, PluginDef, PluginFunction } from "./plugin";
3
- import ScreenshotTool from "./screenshot";
4
- import type { Screenshot, ScreenshotOptions, UserConfig } from "./types";
4
+ import ScreenshotTool, {
5
+ type ScreenshotCaptureDetails,
6
+ type ScreenshotCaptureExtras,
7
+ type ScreenshotCaptureResult,
8
+ type ScreenshotVariantCaptureDetails,
9
+ } from "./screenshot";
10
+ import type {
11
+ Screenshot,
12
+ ScreenshotOptions,
13
+ ScreenshotSettings,
14
+ ScreenshotVariant,
15
+ ScreenshotVariantWithUrl,
16
+ UserConfig,
17
+ Viewport,
18
+ } from "./types";
5
19
 
6
20
  export {
7
21
  ScreenshotTool,
22
+ ScreenshotFileSystem,
8
23
  defineConfig,
9
24
  type PluginFunction,
10
25
  type Plugin,
11
26
  type PluginDef,
12
27
  type UserConfig,
13
28
  type ScreenshotOptions,
29
+ type ScreenshotSettings,
30
+ type ScreenshotVariant,
31
+ type ScreenshotVariantWithUrl,
14
32
  type Screenshot,
33
+ type ScreenshotCaptureResult,
34
+ type ScreenshotCaptureDetails,
35
+ type ScreenshotVariantCaptureDetails,
36
+ type ScreenshotCaptureExtras,
37
+ type Viewport,
15
38
  };
package/src/plugin.ts CHANGED
@@ -1,17 +1,40 @@
1
+ import type { Page } from "playwright-core";
1
2
  import type ScreenshotTool from "./screenshot";
2
3
 
3
4
  /**
4
- * Plugin function type definition
5
+ * Plugin task interface
6
+ */
7
+ export type PluginTask<TData = any> = {
8
+ id: string; // unique identifier for logging
9
+ url: string; // url of the task
10
+ data?: TData; // plugin-specific task data
11
+ };
12
+
13
+ /**
14
+ * Plugin function type definition (legacy)
5
15
  */
6
16
  export type PluginFunction = (screenshotTool: ScreenshotTool) => Promise<any[]>;
7
17
 
8
18
  /**
9
19
  * Plugin definition interface
10
20
  */
11
- export type PluginDef = {
21
+ export type PluginDef<TResult = any, TContext = any, TData = any> = {
12
22
  name: string;
13
23
  description: string;
14
- execute: PluginFunction;
24
+
25
+ // Phase 1: Discover all tasks
26
+ discover: (screenshotTool: ScreenshotTool) => Promise<PluginTask<TData>[]>;
27
+
28
+ // Phase 2: Execute a single task
29
+ execute: (
30
+ task: PluginTask<TData>,
31
+ page: Page,
32
+ screenshotTool: ScreenshotTool,
33
+ context: TContext,
34
+ ) => Promise<TResult>;
35
+
36
+ // Optional: called once per page before executing tasks on that page
37
+ initPage?: (page: Page, screenshotTool: ScreenshotTool) => Promise<TContext>;
15
38
  };
16
39
 
17
40
  /**
@@ -0,0 +1,40 @@
1
+ import { initLogger } from "@cappa/logger";
2
+ import { beforeAll, describe, expect, it } from "vitest";
3
+ import ScreenshotTool from "./screenshot";
4
+
5
+ beforeAll(() => {
6
+ initLogger(0);
7
+ });
8
+
9
+ describe("ScreenshotTool getVariantFilename", () => {
10
+ it("appends the variant id as a suffix", () => {
11
+ const tool = new ScreenshotTool({ outputDir: "/tmp" });
12
+
13
+ const filename = tool.getVariantFilename("components/Button.png", {
14
+ id: "mobile",
15
+ });
16
+
17
+ expect(filename).toBe("components/Button--mobile.png");
18
+ });
19
+
20
+ it("sanitizes invalid characters in the variant id", () => {
21
+ const tool = new ScreenshotTool({ outputDir: "/tmp" });
22
+
23
+ const filename = tool.getVariantFilename("Badge.png", {
24
+ id: "📱 mobile view",
25
+ });
26
+
27
+ expect(filename).toBe("Badge--mobile-view.png");
28
+ });
29
+
30
+ it("uses a provided filename when present", () => {
31
+ const tool = new ScreenshotTool({ outputDir: "/tmp" });
32
+
33
+ const filename = tool.getVariantFilename("Badge.png", {
34
+ id: "mobile",
35
+ filename: "Badge/mobile-custom.png",
36
+ });
37
+
38
+ expect(filename).toBe("Badge/mobile-custom.png");
39
+ });
40
+ });