@argos-ci/playwright 4.3.0 → 5.0.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
@@ -1,5 +1,5 @@
1
- import { ElementHandle, Locator, LocatorScreenshotOptions, PageScreenshotOptions, Page } from '@playwright/test';
2
- import { ViewportOption, StabilizationOptions } from '@argos-ci/browser';
1
+ import { ElementHandle, Locator, Page, PageScreenshotOptions, LocatorScreenshotOptions } from '@playwright/test';
2
+ import { ViewportOption, StabilizationPluginOptions } from '@argos-ci/browser';
3
3
  import { ScreenshotMetadata } from '@argos-ci/util';
4
4
 
5
5
  type LocatorOptions = Parameters<Page["locator"]>[1];
@@ -40,7 +40,7 @@ type ArgosScreenshotOptions = {
40
40
  * Pass an object to customize the stabilization.
41
41
  * @default true
42
42
  */
43
- stabilize?: boolean | StabilizationOptions;
43
+ stabilize?: boolean | StabilizationPluginOptions;
44
44
  /**
45
45
  * Run a function before taking the screenshot.
46
46
  * When using viewports, this function will run before taking sreenshots on each viewport.
@@ -51,7 +51,7 @@ type ArgosScreenshotOptions = {
51
51
  * Accepts an object to customize the stabilization.
52
52
  * Note that this function is independent of the `stabilize` option.
53
53
  */
54
- runStabilization: (options?: StabilizationOptions) => Promise<void>;
54
+ runStabilization: (options?: StabilizationPluginOptions) => Promise<void>;
55
55
  }) => Promise<void> | void;
56
56
  /**
57
57
  * Run a function after taking the screenshot.
package/dist/index.js CHANGED
@@ -141,14 +141,20 @@ async function setViewportSize(page, viewportSize) {
141
141
  { width: viewportSize.width, height: viewportSize.height }
142
142
  );
143
143
  }
144
+ function getStabilizationContext(options) {
145
+ const { fullPage, argosCSS, stabilize } = options;
146
+ return {
147
+ fullPage,
148
+ argosCSS,
149
+ options: stabilize
150
+ };
151
+ }
144
152
  async function beforeAll(page, options) {
145
- const { disableHover = true, fullPage, argosCSS } = options;
153
+ const { disableHover = true } = options;
154
+ const context = getStabilizationContext(options);
146
155
  await page.evaluate(
147
- ({ fullPage: fullPage2, argosCSS: argosCSS2 }) => window.__ARGOS__.beforeAll({
148
- fullPage: fullPage2,
149
- argosCSS: argosCSS2
150
- }),
151
- { fullPage, argosCSS }
156
+ (context2) => window.__ARGOS__.beforeAll(context2),
157
+ context
152
158
  );
153
159
  if (disableHover) {
154
160
  await page.mouse.move(0, 0);
@@ -160,13 +166,10 @@ async function beforeAll(page, options) {
160
166
  };
161
167
  }
162
168
  async function beforeEach(page, options) {
163
- const { fullPage, argosCSS } = options;
169
+ const context = getStabilizationContext(options);
164
170
  await page.evaluate(
165
- ({ fullPage: fullPage2, argosCSS: argosCSS2 }) => window.__ARGOS__.beforeEach({
166
- fullPage: fullPage2,
167
- argosCSS: argosCSS2
168
- }),
169
- { fullPage, argosCSS }
171
+ (context2) => window.__ARGOS__.beforeEach(context2),
172
+ context
170
173
  );
171
174
  return async () => {
172
175
  await page.evaluate(
@@ -174,6 +177,29 @@ async function beforeEach(page, options) {
174
177
  );
175
178
  };
176
179
  }
180
+ async function waitForReadiness(page, options) {
181
+ const context = getStabilizationContext(options);
182
+ try {
183
+ await page.waitForFunction(
184
+ (context2) => window.__ARGOS__.waitFor(context2),
185
+ context
186
+ );
187
+ } catch (error) {
188
+ const reasons = await page.evaluate(
189
+ (context2) => window.__ARGOS__.getWaitFailureExplanations(
190
+ context2
191
+ ),
192
+ context
193
+ );
194
+ throw new Error(
195
+ `
196
+ Failed to stabilize screenshot, found the following issues:
197
+ ${reasons.map((reason) => `- ${reason}`).join("\n")}
198
+ `.trim(),
199
+ { cause: error }
200
+ );
201
+ }
202
+ }
177
203
  function getScreenshotNames(name, testInfo) {
178
204
  if (testInfo) {
179
205
  const projectName = `${testInfo.project.name}/${name}`;
@@ -194,7 +220,6 @@ async function argosScreenshot(page, name, options = {}) {
194
220
  hasText,
195
221
  viewports,
196
222
  argosCSS: _argosCSS,
197
- stabilize = true,
198
223
  root = DEFAULT_SCREENSHOT_ROOT,
199
224
  ...playwrightOptions
200
225
  } = options;
@@ -251,33 +276,14 @@ async function argosScreenshot(page, name, options = {}) {
251
276
  };
252
277
  return metadata;
253
278
  };
254
- const runStabilization = async (options2 = {}) => {
255
- try {
256
- await page.waitForFunction(
257
- (options3) => window.__ARGOS__.waitFor(options3),
258
- options2
259
- );
260
- } catch (error) {
261
- const reasons = await page.evaluate(
262
- (options3) => window.__ARGOS__.getWaitFailureExplanations(
263
- options3
264
- ),
265
- options2
266
- );
267
- throw new Error(
268
- `
269
- Failed to stabilize screenshot, found the following issues:
270
- ${reasons.map((reason) => `- ${reason}`).join("\n")}
271
- `.trim(),
272
- { cause: error }
273
- );
274
- }
275
- };
276
279
  const stabilizeAndScreenshot = async (name2) => {
277
- await options.beforeScreenshot?.({ runStabilization });
278
- if (stabilize) {
279
- await runStabilization(stabilize === true ? void 0 : stabilize);
280
- }
280
+ await options.beforeScreenshot?.({
281
+ runStabilization: (stabilizationOptions) => waitForReadiness(page, {
282
+ ...options,
283
+ stabilize: stabilizationOptions ?? options.stabilize
284
+ })
285
+ });
286
+ await waitForReadiness(page, options);
281
287
  const afterEach = await beforeEach(page, options);
282
288
  const names = getScreenshotNames(name2, testInfo);
283
289
  const metadata = await collectMetadata(testInfo);
@@ -1,4 +1,4 @@
1
- import { Reporter, FullConfig, TestResult, TestCase, FullResult } from '@playwright/test/reporter';
1
+ import { Reporter, TestCase, FullConfig, TestResult, FullResult } from '@playwright/test/reporter';
2
2
  import { UploadParameters } from '@argos-ci/core';
3
3
 
4
4
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/playwright",
3
3
  "description": "Playwright SDK for visual testing with Argos.",
4
- "version": "4.3.0",
4
+ "version": "5.0.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -47,23 +47,25 @@
47
47
  "node": ">=18.16.0"
48
48
  },
49
49
  "dependencies": {
50
- "@argos-ci/browser": "3.2.0",
51
- "@argos-ci/core": "3.1.0",
52
- "@argos-ci/util": "2.3.0",
50
+ "@argos-ci/browser": "4.0.0",
51
+ "@argos-ci/core": "3.1.1",
52
+ "@argos-ci/util": "2.3.1",
53
53
  "chalk": "^5.4.1",
54
54
  "debug": "^4.4.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@argos-ci/cli": "2.5.5",
58
- "@argos-ci/playwright": "workspace:.",
59
- "@playwright/test": "^1.49.1",
57
+ "@playwright/test": "^1.51.1",
60
58
  "@types/debug": "^4.1.12",
61
59
  "@types/node": "^18.19.44"
62
60
  },
63
61
  "scripts": {
64
62
  "build": "tsup && cp ./src/index.cjs ./dist",
65
- "test": "pnpm exec -- playwright test",
66
- "e2e": "UPLOAD_TO_ARGOS=true pnpm run test"
63
+ "test-e2e": "pnpm exec -- playwright test",
64
+ "build-e2e": "playwright install chromium --with-deps",
65
+ "e2e": "UPLOAD_TO_ARGOS=true pnpm run test-e2e",
66
+ "check-types": "tsc",
67
+ "check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
68
+ "lint": "eslint ."
67
69
  },
68
- "gitHead": "fae9639b570fb2cd937ce8695eed1941c25678db"
70
+ "gitHead": "6385df8f840714c9d77c52b2035bdbbc1b148791"
69
71
  }