@cappa/core 0.1.3 → 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 +13 -0
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/index.d.mts +173 -36
- package/dist/index.d.ts +173 -36
- package/dist/index.js +391 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +391 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -11
- 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 +344 -104
- package/src/types.ts +19 -1
package/src/index.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
import { defineConfig } from "./config";
|
|
2
|
+
import { ScreenshotFileSystem } from "./filesystem";
|
|
2
3
|
import type { Plugin, PluginDef, PluginFunction } from "./plugin";
|
|
3
|
-
import ScreenshotTool
|
|
4
|
-
|
|
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
|
+
UserConfig,
|
|
16
|
+
Viewport,
|
|
17
|
+
} from "./types";
|
|
5
18
|
|
|
6
19
|
export {
|
|
7
20
|
ScreenshotTool,
|
|
21
|
+
ScreenshotFileSystem,
|
|
8
22
|
defineConfig,
|
|
9
23
|
type PluginFunction,
|
|
10
24
|
type Plugin,
|
|
11
25
|
type PluginDef,
|
|
12
26
|
type UserConfig,
|
|
13
27
|
type ScreenshotOptions,
|
|
28
|
+
type ScreenshotSettings,
|
|
29
|
+
type ScreenshotVariant,
|
|
14
30
|
type Screenshot,
|
|
31
|
+
type ScreenshotCaptureResult,
|
|
32
|
+
type ScreenshotCaptureDetails,
|
|
33
|
+
type ScreenshotVariantCaptureDetails,
|
|
34
|
+
type ScreenshotCaptureExtras,
|
|
35
|
+
type Viewport,
|
|
15
36
|
};
|
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
|
+
});
|