@argos-ci/playwright 4.2.3 → 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,25 +141,65 @@ async function setViewportSize(page, viewportSize) {
141
141
  { width: viewportSize.width, height: viewportSize.height }
142
142
  );
143
143
  }
144
- async function setup(page, options) {
145
- const { disableHover = true, fullPage, argosCSS } = options;
144
+ function getStabilizationContext(options) {
145
+ const { fullPage, argosCSS, stabilize } = options;
146
+ return {
147
+ fullPage,
148
+ argosCSS,
149
+ options: stabilize
150
+ };
151
+ }
152
+ async function beforeAll(page, options) {
153
+ const { disableHover = true } = options;
154
+ const context = getStabilizationContext(options);
146
155
  await page.evaluate(
147
- ({ fullPage: fullPage2, argosCSS: argosCSS2 }) => window.__ARGOS__.setup({ fullPage: fullPage2, argosCSS: argosCSS2 }),
148
- { fullPage, argosCSS }
156
+ (context2) => window.__ARGOS__.beforeAll(context2),
157
+ context
149
158
  );
150
159
  if (disableHover) {
151
160
  await page.mouse.move(0, 0);
152
161
  }
153
162
  return async () => {
154
163
  await page.evaluate(
155
- ({ fullPage: fullPage2, argosCSS: argosCSS2 }) => window.__ARGOS__.teardown({
156
- fullPage: fullPage2,
157
- argosCSS: argosCSS2
158
- }),
159
- { fullPage, argosCSS }
164
+ () => window.__ARGOS__.afterAll()
160
165
  );
161
166
  };
162
167
  }
168
+ async function beforeEach(page, options) {
169
+ const context = getStabilizationContext(options);
170
+ await page.evaluate(
171
+ (context2) => window.__ARGOS__.beforeEach(context2),
172
+ context
173
+ );
174
+ return async () => {
175
+ await page.evaluate(
176
+ () => window.__ARGOS__.afterEach()
177
+ );
178
+ };
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
+ }
163
203
  function getScreenshotNames(name, testInfo) {
164
204
  if (testInfo) {
165
205
  const projectName = `${testInfo.project.name}/${name}`;
@@ -180,7 +220,6 @@ async function argosScreenshot(page, name, options = {}) {
180
220
  hasText,
181
221
  viewports,
182
222
  argosCSS: _argosCSS,
183
- stabilize = true,
184
223
  root = DEFAULT_SCREENSHOT_ROOT,
185
224
  ...playwrightOptions
186
225
  } = options;
@@ -203,7 +242,7 @@ async function argosScreenshot(page, name, options = {}) {
203
242
  ]);
204
243
  const originalViewportSize = getViewportSize(page);
205
244
  const fullPage = options.fullPage !== void 0 ? options.fullPage : handle === page;
206
- const teardown = await setup(page, options);
245
+ const afterAll = await beforeAll(page, options);
207
246
  const collectMetadata = async (testInfo2) => {
208
247
  const [colorScheme, mediaType, libMetadata, testMetadata] = await Promise.all([
209
248
  page.evaluate(
@@ -237,33 +276,15 @@ async function argosScreenshot(page, name, options = {}) {
237
276
  };
238
277
  return metadata;
239
278
  };
240
- const runStabilization = async (options2 = {}) => {
241
- try {
242
- await page.waitForFunction(
243
- (options3) => window.__ARGOS__.checkIsStable(options3),
244
- options2
245
- );
246
- } catch (error) {
247
- const reasons = await page.evaluate(
248
- (options3) => window.__ARGOS__.getStabilityFailureReasons(
249
- options3
250
- ),
251
- options2
252
- );
253
- throw new Error(
254
- `
255
- Failed to stabilize screenshot, found the following issues:
256
- ${reasons.map((reason) => `- ${reason}`).join("\n")}
257
- `.trim(),
258
- { cause: error }
259
- );
260
- }
261
- };
262
279
  const stabilizeAndScreenshot = async (name2) => {
263
- await options.beforeScreenshot?.({ runStabilization });
264
- if (stabilize) {
265
- await runStabilization(stabilize === true ? void 0 : stabilize);
266
- }
280
+ await options.beforeScreenshot?.({
281
+ runStabilization: (stabilizationOptions) => waitForReadiness(page, {
282
+ ...options,
283
+ stabilize: stabilizationOptions ?? options.stabilize
284
+ })
285
+ });
286
+ await waitForReadiness(page, options);
287
+ const afterEach = await beforeEach(page, options);
267
288
  const names = getScreenshotNames(name2, testInfo);
268
289
  const metadata = await collectMetadata(testInfo);
269
290
  metadata.transient = {};
@@ -302,9 +323,7 @@ ${reasons.map((reason) => `- ${reason}`).join("\n")}
302
323
  })
303
324
  ]);
304
325
  }
305
- await page.evaluate(
306
- () => window.__ARGOS__.afterEach()
307
- );
326
+ await afterEach();
308
327
  await options.afterScreenshot?.();
309
328
  };
310
329
  if (viewports) {
@@ -319,7 +338,7 @@ ${reasons.map((reason) => `- ${reason}`).join("\n")}
319
338
  } else {
320
339
  await stabilizeAndScreenshot(name);
321
340
  }
322
- await teardown();
341
+ await afterAll();
323
342
  }
324
343
 
325
344
  // src/csp.ts
@@ -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.2.3",
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.1.3",
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": "4f538068d5e42c378acdbaca292ab8cb1b49d031"
70
+ "gitHead": "6385df8f840714c9d77c52b2035bdbbc1b148791"
69
71
  }