@cappa/core 0.0.16 → 0.0.18
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/config.ts +3 -1
- package/src/plugin.ts +4 -1
- package/src/screenshot.ts +27 -8
- package/tsconfig.json +6 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -4,7 +4,9 @@ import type { PossiblePromise, UserConfig } from "./types";
|
|
|
4
4
|
* Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
|
|
5
5
|
*/
|
|
6
6
|
export function defineConfig(
|
|
7
|
-
options:
|
|
7
|
+
options:
|
|
8
|
+
| PossiblePromise<UserConfig | Array<UserConfig>>
|
|
9
|
+
| (() => PossiblePromise<UserConfig | Array<UserConfig>>),
|
|
8
10
|
): typeof options {
|
|
9
11
|
return options;
|
|
10
12
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -3,7 +3,10 @@ import type ScreenshotTool from "./screenshot";
|
|
|
3
3
|
/**
|
|
4
4
|
* Plugin function type definition
|
|
5
5
|
*/
|
|
6
|
-
export type PluginFunction = (
|
|
6
|
+
export type PluginFunction = (
|
|
7
|
+
screenshotTool: ScreenshotTool,
|
|
8
|
+
options?: any,
|
|
9
|
+
) => Promise<any[]>;
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Plugin definition interface
|
package/src/screenshot.ts
CHANGED
|
@@ -49,7 +49,8 @@ class ScreenshotTool {
|
|
|
49
49
|
webkit,
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
const browserClass =
|
|
52
|
+
const browserClass =
|
|
53
|
+
browserMap[this.browserType as keyof typeof browserMap];
|
|
53
54
|
if (!browserClass) {
|
|
54
55
|
throw new Error(`Unsupported browser type: ${this.browserType}`);
|
|
55
56
|
}
|
|
@@ -113,7 +114,8 @@ class ScreenshotTool {
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
// Wait for custom timeout or default
|
|
116
|
-
const waitTime =
|
|
117
|
+
const waitTime =
|
|
118
|
+
options.waitForTimeout !== undefined ? options.waitForTimeout : 0;
|
|
117
119
|
if (waitTime > 0) {
|
|
118
120
|
console.log(`Waiting for ${waitTime}ms for dynamic content`);
|
|
119
121
|
await page.waitForTimeout(waitTime);
|
|
@@ -125,7 +127,10 @@ class ScreenshotTool {
|
|
|
125
127
|
// Take screenshot
|
|
126
128
|
const screenshotOptions = {
|
|
127
129
|
path: filepath,
|
|
128
|
-
fullPage:
|
|
130
|
+
fullPage:
|
|
131
|
+
(options.fullPage as boolean) !== undefined
|
|
132
|
+
? options.fullPage
|
|
133
|
+
: this.fullPage,
|
|
129
134
|
type: (options.type as "jpeg" | "png") || "jpeg",
|
|
130
135
|
quality: (options.quality as number) || this.quality,
|
|
131
136
|
} satisfies PageScreenshotOptions;
|
|
@@ -135,7 +140,10 @@ class ScreenshotTool {
|
|
|
135
140
|
console.log(`Screenshot saved: ${filepath}`);
|
|
136
141
|
return filepath;
|
|
137
142
|
} catch (error) {
|
|
138
|
-
console.error(
|
|
143
|
+
console.error(
|
|
144
|
+
`Error taking screenshot of ${page.url()}:`,
|
|
145
|
+
(error as Error).message,
|
|
146
|
+
);
|
|
139
147
|
throw error;
|
|
140
148
|
}
|
|
141
149
|
}
|
|
@@ -163,7 +171,9 @@ class ScreenshotTool {
|
|
|
163
171
|
throw new Error(`Element not found: ${selector}`);
|
|
164
172
|
}
|
|
165
173
|
|
|
166
|
-
const filename =
|
|
174
|
+
const filename =
|
|
175
|
+
(options.filename as string | undefined) ||
|
|
176
|
+
`${selector.replace(/[^a-zA-Z0-9]/g, "_")}.png`;
|
|
167
177
|
const filepath = this.getFilePath(filename);
|
|
168
178
|
|
|
169
179
|
const elementScreenshotOptions = {
|
|
@@ -177,7 +187,10 @@ class ScreenshotTool {
|
|
|
177
187
|
console.log(`Element screenshot saved: ${filepath}`);
|
|
178
188
|
return filepath;
|
|
179
189
|
} catch (error) {
|
|
180
|
-
console.error(
|
|
190
|
+
console.error(
|
|
191
|
+
`Error taking element screenshot of ${page.url()}:`,
|
|
192
|
+
(error as Error).message,
|
|
193
|
+
);
|
|
181
194
|
throw error;
|
|
182
195
|
} finally {
|
|
183
196
|
await page.close();
|
|
@@ -251,7 +264,10 @@ class ScreenshotTool {
|
|
|
251
264
|
|
|
252
265
|
const responsiveScreenshotOptions = {
|
|
253
266
|
path: filepath,
|
|
254
|
-
fullPage:
|
|
267
|
+
fullPage:
|
|
268
|
+
(options.fullPage as boolean) !== undefined
|
|
269
|
+
? options.fullPage
|
|
270
|
+
: this.fullPage,
|
|
255
271
|
type: (options.type as "jpeg" | "png") || "png",
|
|
256
272
|
quality: (options.quality as number) || this.quality,
|
|
257
273
|
};
|
|
@@ -263,7 +279,10 @@ class ScreenshotTool {
|
|
|
263
279
|
console.log(`Responsive screenshot saved: ${filepath}`);
|
|
264
280
|
results.push({ viewport: viewport.name, success: true, filepath });
|
|
265
281
|
} catch (error) {
|
|
266
|
-
console.error(
|
|
282
|
+
console.error(
|
|
283
|
+
`Error taking responsive screenshot for ${viewport.name}:`,
|
|
284
|
+
(error as Error).message,
|
|
285
|
+
);
|
|
267
286
|
results.push({
|
|
268
287
|
viewport: viewport.name,
|
|
269
288
|
success: false,
|