@argos-ci/playwright 1.4.2 → 1.5.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.mjs CHANGED
@@ -164,7 +164,7 @@ async function argosScreenshot(page, name, { element, has, hasText, viewports, a
164
164
  async function stabilizeAndScreenshot(name) {
165
165
  await page.waitForFunction(()=>window.__ARGOS__.waitForStability());
166
166
  const metadata = await collectMetadata(testInfo);
167
- const screenshotPath = useArgosReporter ? null : resolve(screenshotFolder, `${name}.png`);
167
+ const screenshotPath = useArgosReporter ? testInfo.outputPath("argos", `${name}.png`) : resolve(screenshotFolder, `${name}.png`);
168
168
  if (screenshotPath) {
169
169
  const dir = dirname(screenshotPath);
170
170
  if (dir !== screenshotFolder) {
@@ -1,11 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult } from "@playwright/test/reporter";
3
3
  import { UploadParameters } from "@argos-ci/core";
4
- type ArgosReporterOptions = Omit<UploadParameters, "files" | "root">;
4
+ type ArgosReporterOptions = Omit<UploadParameters, "files" | "root"> & {
5
+ /**
6
+ * If `true`, the report will be uploaded to Argos.
7
+ */
8
+ uploadToArgos?: boolean;
9
+ };
5
10
  declare class ArgosReporter implements Reporter {
6
11
  uploadDir: string;
7
12
  config: ArgosReporterOptions;
8
13
  playwrightConfig: FullConfig;
14
+ uploadToArgos: boolean;
9
15
  constructor(config: ArgosReporterOptions);
10
16
  writeFile(path: string, body: Buffer | string): Promise<void>;
11
17
  getAutomaticScreenshotName(test: TestCase, result: TestResult): string;
package/dist/reporter.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import chalk from 'chalk';
1
2
  import { upload, readConfig } from '@argos-ci/core';
2
3
  import { randomBytes } from 'node:crypto';
3
4
  import { mkdir, writeFile, copyFile } from 'node:fs/promises';
@@ -22,10 +23,10 @@ function checkIsTrace(attachment) {
22
23
  return attachment.name === "trace" && attachment.contentType === "application/zip" && Boolean(attachment.path);
23
24
  }
24
25
  function checkIsArgosScreenshot(attachment) {
25
- return attachment.name.startsWith("argos/") && attachment.contentType === "image/png" && Boolean(attachment.body);
26
+ return attachment.name.startsWith("argos/") && attachment.contentType === "image/png" && Boolean(attachment.path);
26
27
  }
27
28
  function checkIsArgosScreenshotMetadata(attachment) {
28
- return attachment.name.startsWith("argos/") && attachment.contentType === "application/json" && Boolean(attachment.body);
29
+ return attachment.name.startsWith("argos/") && attachment.contentType === "application/json" && Boolean(attachment.path);
29
30
  }
30
31
  function checkIsAutomaticScreenshot(attachment) {
31
32
  return attachment.name === "screenshot" && attachment.contentType === "image/png" && Boolean(attachment.path);
@@ -126,8 +127,10 @@ class ArgosReporter {
126
127
  uploadDir;
127
128
  config;
128
129
  playwrightConfig;
130
+ uploadToArgos;
129
131
  constructor(config){
130
132
  this.config = config;
133
+ this.uploadToArgos = config.uploadToArgos ?? false;
131
134
  }
132
135
  async writeFile(path, body) {
133
136
  const dir = dirname(path);
@@ -152,7 +155,7 @@ class ArgosReporter {
152
155
  await Promise.all(result.attachments.map(async (attachment)=>{
153
156
  if (checkIsArgosScreenshot(attachment) || checkIsArgosScreenshotMetadata(attachment)) {
154
157
  const path = join(this.uploadDir, getAttachmentFilename(attachment.name));
155
- await this.writeFile(path, attachment.body);
158
+ await copyFile(attachment.path, path);
156
159
  return;
157
160
  }
158
161
  // Error screenshots are sent to Argos
@@ -171,9 +174,10 @@ class ArgosReporter {
171
174
  }));
172
175
  }
173
176
  async onEnd(_result) {
177
+ if (!this.uploadToArgos) return;
174
178
  const parallel = getParallelFromConfig(this.playwrightConfig);
175
179
  try {
176
- await upload({
180
+ const res = await upload({
177
181
  files: [
178
182
  "**/*.png"
179
183
  ],
@@ -181,6 +185,7 @@ class ArgosReporter {
181
185
  parallel: parallel ?? undefined,
182
186
  ...this.config
183
187
  });
188
+ console.log(chalk.green(`✅ Argos build created: ${res.build.url}`));
184
189
  } catch (error) {
185
190
  console.error(error);
186
191
  return {
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.4.2",
4
+ "version": "1.5.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -44,7 +44,8 @@
44
44
  "dependencies": {
45
45
  "@argos-ci/browser": "1.2.2",
46
46
  "@argos-ci/core": "1.3.0",
47
- "@argos-ci/util": "1.1.0"
47
+ "@argos-ci/util": "1.1.0",
48
+ "chalk": "^5.3.0"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@argos-ci/cli": "1.0.4",
@@ -56,7 +57,7 @@
56
57
  "prebuild": "rm -rf dist",
57
58
  "build": "rollup -c",
58
59
  "test": "pnpm exec playwright test",
59
- "e2e": "WITH_ARGOS_REPORTER=true pnpm run test"
60
+ "e2e": "pnpm run test"
60
61
  },
61
- "gitHead": "672a6e0fce11cd9e0acd8b77dad137d85d224ef9"
62
+ "gitHead": "dd3031f89cc03084a65b2b956783441d3dd75d9c"
62
63
  }