@cappa/core 0.1.2 → 0.2.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.
- package/.turbo/turbo-build.log +13 -19
- package/.turbo/turbo-test.log +53 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/index.d.mts +190 -38
- package/dist/index.d.ts +190 -38
- package/dist/index.js +430 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +430 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -12
- package/src/compare.test.ts +9 -4
- package/src/compare.ts +76 -23
- package/src/filesystem.test.ts +83 -0
- package/src/filesystem.ts +202 -0
- package/src/index.ts +23 -2
- package/src/plugin.ts +26 -3
- package/src/screenshot.test.ts +40 -0
- package/src/screenshot.ts +425 -119
- package/src/types.ts +23 -1
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
|
|
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
|
-
|
|
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
|
+
});
|