@argos-ci/puppeteer 1.5.0 → 1.6.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/dist/index.d.ts CHANGED
@@ -13,6 +13,11 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
13
13
  * Custom CSS evaluated during the screenshot process.
14
14
  */
15
15
  argosCSS?: string;
16
+ /**
17
+ * Disable hover effects by moving the mouse to the top-left corner of the page.
18
+ * @default true
19
+ */
20
+ disableHover?: boolean;
16
21
  };
17
22
  /**
18
23
  * @param page Puppeteer `page` object.
@@ -22,5 +27,5 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
22
27
  * @param options.viewports Viewports to take screenshots of.
23
28
  * @param options.argosCSS Custom CSS evaluated during the screenshot process.
24
29
  */
25
- declare function argosScreenshot(page: Page, name: string, { element, viewports, argosCSS, ...options }?: ArgosScreenshotOptions): Promise<void>;
30
+ declare function argosScreenshot(page: Page, name: string, options?: ArgosScreenshotOptions): Promise<void>;
26
31
  export { ArgosScreenshotOptions, argosScreenshot };
package/dist/index.mjs CHANGED
@@ -45,6 +45,35 @@ async function getScreenshotPath(name) {
45
45
  });
46
46
  return resolve(screenshotFolder, name + ".png");
47
47
  }
48
+ function checkIsFullPage(options) {
49
+ return options.fullPage !== undefined ? options.fullPage : options.element === undefined;
50
+ }
51
+ /**
52
+ * Setup Argos for the screenshot process.
53
+ * @returns A function to teardown Argos.
54
+ */ async function setup(page, options) {
55
+ const { disableHover = true, argosCSS } = options;
56
+ const fullPage = checkIsFullPage(options);
57
+ await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.setup({
58
+ fullPage,
59
+ argosCSS
60
+ }), {
61
+ fullPage,
62
+ argosCSS
63
+ });
64
+ if (disableHover) {
65
+ await page.mouse.move(0, 0);
66
+ }
67
+ return async ()=>{
68
+ await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.teardown({
69
+ fullPage,
70
+ argosCSS
71
+ }), {
72
+ fullPage,
73
+ argosCSS
74
+ });
75
+ };
76
+ }
48
77
  /**
49
78
  * @param page Puppeteer `page` object.
50
79
  * @param name The name of the screenshot or the full path to the screenshot.
@@ -52,7 +81,8 @@ async function getScreenshotPath(name) {
52
81
  * @param options.element ElementHandle or string selector of the element to take a screenshot of.
53
82
  * @param options.viewports Viewports to take screenshots of.
54
83
  * @param options.argosCSS Custom CSS evaluated during the screenshot process.
55
- */ async function argosScreenshot(page, name, { element, viewports, argosCSS, ...options } = {}) {
84
+ */ async function argosScreenshot(page, name, options = {}) {
85
+ const { element, viewports, argosCSS, ...puppeteerOptions } = options;
56
86
  if (!page) {
57
87
  throw new Error("A Puppeteer `page` object is required.");
58
88
  }
@@ -64,14 +94,8 @@ async function getScreenshotPath(name) {
64
94
  // Inject Argos script into the page
65
95
  injectArgos(page)
66
96
  ]);
67
- const fullPage = options.fullPage !== undefined ? options.fullPage : element === undefined;
68
- await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.setup({
69
- fullPage,
70
- argosCSS
71
- }), {
72
- fullPage,
73
- argosCSS
74
- });
97
+ const teardown = await setup(page, options);
98
+ const fullPage = checkIsFullPage(options);
75
99
  async function collectMetadata() {
76
100
  const [colorScheme, mediaType, puppeteerVersion, argosPuppeteerVersion, { browserName, browserVersion }] = await Promise.all([
77
101
  page.evaluate(()=>window.__ARGOS__.getColorScheme()),
@@ -116,7 +140,7 @@ async function getScreenshotPath(name) {
116
140
  path: screenshotPath,
117
141
  type: "png",
118
142
  fullPage,
119
- ...options
143
+ ...puppeteerOptions
120
144
  };
121
145
  // If no element is specified, take a screenshot of the whole page
122
146
  if (element === undefined) {
@@ -151,14 +175,7 @@ async function getScreenshotPath(name) {
151
175
  } else {
152
176
  await stabilizeAndScreenshot(name);
153
177
  }
154
- // Teardown Argos
155
- await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.teardown({
156
- fullPage,
157
- argosCSS
158
- }), {
159
- fullPage,
160
- argosCSS
161
- });
178
+ await teardown();
162
179
  }
163
180
 
164
181
  export { argosScreenshot };
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.5.0",
4
+ "version": "1.6.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -40,11 +40,11 @@
40
40
  "puppeteer": ">=1"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/browser": "1.4.0",
43
+ "@argos-ci/browser": "1.4.1",
44
44
  "@argos-ci/util": "1.2.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@argos-ci/cli": "1.0.8",
47
+ "@argos-ci/cli": "1.0.9",
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": "dbd169d2307a498a7c44001197924947c28be803"
66
+ "gitHead": "47e813466b9224cb428eb44ee4d4d450f737763e"
67
67
  }