@argos-ci/puppeteer 1.3.2 → 1.4.1-alpha.2
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/dist/index.d.ts +8 -0
- package/dist/index.mjs +21 -9
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -14,5 +14,13 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
|
|
|
14
14
|
*/
|
|
15
15
|
argosCSS?: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* @param page Puppeteer `page` object.
|
|
19
|
+
* @param name The name of the screenshot or the full path to the screenshot.
|
|
20
|
+
* @param options In addition to Puppeteer's `ScreenshotOptions`, you can pass:
|
|
21
|
+
* @param options.element ElementHandle or string selector of the element to take a screenshot of.
|
|
22
|
+
* @param options.viewports Viewports to take screenshots of.
|
|
23
|
+
* @param options.argosCSS Custom CSS evaluated during the screenshot process.
|
|
24
|
+
*/
|
|
17
25
|
declare function argosScreenshot(page: Page, name: string, { element, viewports, argosCSS, ...options }?: ArgosScreenshotOptions): Promise<void>;
|
|
18
26
|
export { ArgosScreenshotOptions, argosScreenshot };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, mkdir } from 'node:fs/promises';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { resolveViewport } from '@argos-ci/browser';
|
|
5
5
|
import { getScreenshotName, writeMetadata, readVersionFromPackage } from '@argos-ci/util';
|
|
@@ -39,20 +39,30 @@ async function getBrowserInfo(page) {
|
|
|
39
39
|
browserVersion
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
async function
|
|
42
|
+
async function getScreenshotPath(name) {
|
|
43
|
+
if (name.endsWith(".png")) return name;
|
|
44
|
+
const screenshotFolder = resolve(process.cwd(), "screenshots/argos");
|
|
45
|
+
await mkdir(screenshotFolder, {
|
|
46
|
+
recursive: true
|
|
47
|
+
});
|
|
48
|
+
return resolve(screenshotFolder, name + ".png");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @param page Puppeteer `page` object.
|
|
52
|
+
* @param name The name of the screenshot or the full path to the screenshot.
|
|
53
|
+
* @param options In addition to Puppeteer's `ScreenshotOptions`, you can pass:
|
|
54
|
+
* @param options.element ElementHandle or string selector of the element to take a screenshot of.
|
|
55
|
+
* @param options.viewports Viewports to take screenshots of.
|
|
56
|
+
* @param options.argosCSS Custom CSS evaluated during the screenshot process.
|
|
57
|
+
*/ async function argosScreenshot(page, name, { element, viewports, argosCSS, ...options } = {}) {
|
|
43
58
|
if (!page) {
|
|
44
59
|
throw new Error("A Puppeteer `page` object is required.");
|
|
45
60
|
}
|
|
46
61
|
if (!name) {
|
|
47
62
|
throw new Error("The `name` argument is required.");
|
|
48
63
|
}
|
|
49
|
-
const screenshotFolder = resolve(process.cwd(), "screenshots/argos");
|
|
50
64
|
const [originalViewport] = await Promise.all([
|
|
51
65
|
getViewport(page),
|
|
52
|
-
// Create the screenshot folder if it doesn't exist
|
|
53
|
-
mkdir(screenshotFolder, {
|
|
54
|
-
recursive: true
|
|
55
|
-
}),
|
|
56
66
|
// Inject Argos script into the page
|
|
57
67
|
injectArgos(page)
|
|
58
68
|
]);
|
|
@@ -99,8 +109,10 @@ async function argosScreenshot(page, name, { element, viewports, argosCSS, ...op
|
|
|
99
109
|
}
|
|
100
110
|
async function stabilizeAndScreenshot(name) {
|
|
101
111
|
await page.waitForFunction(()=>window.__ARGOS__.waitForStability());
|
|
102
|
-
const screenshotPath =
|
|
103
|
-
|
|
112
|
+
const [screenshotPath, metadata] = await Promise.all([
|
|
113
|
+
getScreenshotPath(name),
|
|
114
|
+
collectMetadata()
|
|
115
|
+
]);
|
|
104
116
|
await writeMetadata(screenshotPath, metadata);
|
|
105
117
|
const screenshotOptions = {
|
|
106
118
|
path: screenshotPath,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/puppeteer",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. Puppeteer commands and utilities for Argos visual testing.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.1-alpha.2+505aabe",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@argos-ci/util": "1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@argos-ci/cli": "1.0.6",
|
|
47
|
+
"@argos-ci/cli": "1.0.7-alpha.6+505aabe",
|
|
48
48
|
"@types/jest": "^28.1.8",
|
|
49
49
|
"@types/node": "^16.0.0",
|
|
50
50
|
"eslint": "^8.23.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"argos-upload": "pnpm exec argos upload screenshots --build-name \"argos-puppeteer-e2e-node-$NODE_VERSION-$OS\"",
|
|
64
64
|
"e2e": "pnpm run test && pnpm run argos-upload"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "505aabe2ed2b8455172e9a8a473bccf683591a7c"
|
|
67
67
|
}
|