@argos-ci/playwright 1.7.1 → 1.9.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
@@ -15,6 +15,11 @@ type ArgosScreenshotOptions = {
15
15
  * Custom CSS evaluated during the screenshot process.
16
16
  */
17
17
  argosCSS?: string;
18
+ /**
19
+ * Disable hover effects by moving the mouse to the top-left corner of the page.
20
+ * @default true
21
+ */
22
+ disableHover?: boolean;
18
23
  } & LocatorOptions & ScreenshotOptions<LocatorScreenshotOptions> & ScreenshotOptions<PageScreenshotOptions>;
19
- declare function argosScreenshot(page: Page, name: string, { element, has, hasText, viewports, argosCSS, ...options }?: ArgosScreenshotOptions): Promise<void>;
24
+ declare function argosScreenshot(page: Page, name: string, options?: ArgosScreenshotOptions): Promise<void>;
20
25
  export { ArgosScreenshotOptions, argosScreenshot };
package/dist/index.mjs CHANGED
@@ -1,17 +1,17 @@
1
- import { mkdir, readFile } from 'node:fs/promises';
1
+ import { mkdir } from 'node:fs/promises';
2
2
  import { relative, resolve, dirname } from 'node:path';
3
- import { createRequire } from 'node:module';
4
- import { resolveViewport } from '@argos-ci/browser';
3
+ import { resolveViewport, getGlobalScript } from '@argos-ci/browser';
5
4
  import { getGitRepositoryPath, readVersionFromPackage, getScreenshotName, writeMetadata, getMetadataPath } from '@argos-ci/util';
5
+ import { createRequire } from 'node:module';
6
6
 
7
7
  function getAttachmentName(name, type) {
8
8
  return `argos/${type}___${name}`;
9
9
  }
10
10
 
11
- const require$2 = createRequire(import.meta.url);
11
+ const require$1 = createRequire(import.meta.url);
12
12
  const tryResolve = (pkg)=>{
13
13
  try {
14
- return require$2.resolve(pkg);
14
+ return require$1.resolve(pkg);
15
15
  } catch {
16
16
  return null;
17
17
  }
@@ -35,7 +35,7 @@ async function getAutomationLibrary() {
35
35
  throw new Error(`Unable to find any of the following packages: ${libraries.join(", ")}`);
36
36
  }
37
37
  async function getArgosPlaywrightVersion() {
38
- const pkgPath = require$2.resolve("@argos-ci/playwright/package.json");
38
+ const pkgPath = require$1.resolve("@argos-ci/playwright/package.json");
39
39
  return readVersionFromPackage(pkgPath);
40
40
  }
41
41
  async function getLibraryMetadata() {
@@ -69,23 +69,20 @@ async function getTestMetadataFromTestInfo(testInfo) {
69
69
  return testMetadata;
70
70
  }
71
71
 
72
- const require$1 = createRequire(import.meta.url);
72
+ const require = createRequire(import.meta.url);
73
73
  function checkIsUsingArgosReporter(testInfo) {
74
- const reporterPath = require$1.resolve("@argos-ci/playwright/reporter");
74
+ const reporterPath = require.resolve("@argos-ci/playwright/reporter");
75
75
  return testInfo.config.reporter.some((reporter)=>reporter[0].includes("@argos-ci/playwright/reporter") || reporter[0] === reporterPath);
76
76
  }
77
77
 
78
- const require = createRequire(import.meta.url);
79
78
  const screenshotFolder = "./screenshots";
80
79
  /**
81
80
  * Inject Argos script into the page.
82
81
  */ async function injectArgos(page) {
83
82
  const injected = await page.evaluate(()=>typeof window.__ARGOS__ !== "undefined");
84
83
  if (injected) return;
85
- const fileName = require.resolve("@argos-ci/browser/global.js");
86
- const content = await readFile(fileName, "utf-8");
87
84
  await page.addScriptTag({
88
- content
85
+ content: getGlobalScript()
89
86
  });
90
87
  }
91
88
  async function getTestInfo() {
@@ -103,7 +100,33 @@ function getViewportSize(page) {
103
100
  }
104
101
  return viewportSize;
105
102
  }
106
- async function argosScreenshot(page, name, { element, has, hasText, viewports, argosCSS, ...options } = {}) {
103
+ /**
104
+ * Setup Argos for the screenshot process.
105
+ * @returns A function to teardown Argos.
106
+ */ async function setup(page, options) {
107
+ const { disableHover = true, fullPage, argosCSS } = options;
108
+ await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.setup({
109
+ fullPage,
110
+ argosCSS
111
+ }), {
112
+ fullPage,
113
+ argosCSS
114
+ });
115
+ if (disableHover) {
116
+ await page.mouse.move(0, 0);
117
+ }
118
+ return async ()=>{
119
+ await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.teardown({
120
+ fullPage,
121
+ argosCSS
122
+ }), {
123
+ fullPage,
124
+ argosCSS
125
+ });
126
+ };
127
+ }
128
+ async function argosScreenshot(page, name, options = {}) {
129
+ const { element, has, hasText, viewports, argosCSS, ...playwrightOptions } = options;
107
130
  if (!page) {
108
131
  throw new Error("A Playwright `page` object is required.");
109
132
  }
@@ -126,13 +149,7 @@ async function argosScreenshot(page, name, { element, has, hasText, viewports, a
126
149
  ]);
127
150
  const originalViewportSize = getViewportSize(page);
128
151
  const fullPage = options.fullPage !== undefined ? options.fullPage : handle === page;
129
- await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.setup({
130
- fullPage,
131
- argosCSS
132
- }), {
133
- fullPage,
134
- argosCSS
135
- });
152
+ const teardown = await setup(page, options);
136
153
  async function collectMetadata(testInfo) {
137
154
  const [colorScheme, mediaType, libMetadata, testMetadata] = await Promise.all([
138
155
  page.evaluate(()=>window.__ARGOS__.getColorScheme()),
@@ -182,7 +199,7 @@ async function argosScreenshot(page, name, { element, has, hasText, viewports, a
182
199
  page.locator('[data-visual-test="blackout"]')
183
200
  ],
184
201
  animations: "disabled",
185
- ...options
202
+ ...playwrightOptions
186
203
  }),
187
204
  screenshotPath ? writeMetadata(screenshotPath, metadata) : null
188
205
  ]);
@@ -214,14 +231,7 @@ async function argosScreenshot(page, name, { element, has, hasText, viewports, a
214
231
  } else {
215
232
  await stabilizeAndScreenshot(name);
216
233
  }
217
- // Teardown Argos
218
- await page.evaluate(({ fullPage, argosCSS })=>window.__ARGOS__.teardown({
219
- fullPage,
220
- argosCSS
221
- }), {
222
- fullPage,
223
- argosCSS
224
- });
234
+ await teardown();
225
235
  }
226
236
 
227
237
  export { argosScreenshot };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/playwright",
3
3
  "description": "Visual testing solution to avoid visual regression. Playwright commands and utilities for Argos visual testing.",
4
- "version": "1.7.1",
4
+ "version": "1.9.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -42,13 +42,13 @@
42
42
  "node": ">=16.0.0"
43
43
  },
44
44
  "dependencies": {
45
- "@argos-ci/browser": "1.3.0",
46
- "@argos-ci/core": "1.5.1",
45
+ "@argos-ci/browser": "1.4.1",
46
+ "@argos-ci/core": "1.5.2",
47
47
  "@argos-ci/util": "1.2.0",
48
48
  "chalk": "^5.3.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@argos-ci/cli": "1.0.8",
51
+ "@argos-ci/cli": "1.0.9",
52
52
  "@argos-ci/playwright": "workspace:.",
53
53
  "@playwright/test": "^1.38.1",
54
54
  "@types/node": "^16.0.0"
@@ -59,5 +59,5 @@
59
59
  "test": "pnpm exec playwright test",
60
60
  "e2e": "UPLOAD_TO_ARGOS=true pnpm run test"
61
61
  },
62
- "gitHead": "174a9847d8a547d4fa4acb7602ea3687dc9bde8e"
62
+ "gitHead": "47e813466b9224cb428eb44ee4d4d450f737763e"
63
63
  }