@argos-ci/playwright 1.9.2 → 1.9.4-alpha.1

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
@@ -150,7 +150,7 @@ async function argosScreenshot(page, name, options = {}) {
150
150
  const originalViewportSize = getViewportSize(page);
151
151
  const fullPage = options.fullPage !== undefined ? options.fullPage : handle === page;
152
152
  const teardown = await setup(page, options);
153
- async function collectMetadata(testInfo) {
153
+ const collectMetadata = async (testInfo)=>{
154
154
  const [colorScheme, mediaType, libMetadata, testMetadata] = await Promise.all([
155
155
  page.evaluate(()=>window.__ARGOS__.getColorScheme()),
156
156
  page.evaluate(()=>window.__ARGOS__.getMediaType()),
@@ -177,22 +177,21 @@ async function argosScreenshot(page, name, options = {}) {
177
177
  ...libMetadata
178
178
  };
179
179
  return metadata;
180
- }
181
- async function stabilizeAndScreenshot(name) {
180
+ };
181
+ const stabilizeAndScreenshot = async (name)=>{
182
182
  await page.waitForFunction(()=>window.__ARGOS__.waitForStability());
183
183
  const metadata = await collectMetadata(testInfo);
184
- const screenshotPath = useArgosReporter ? testInfo.outputPath("argos", `${name}.png`) : resolve(screenshotFolder, `${name}.png`);
185
- if (screenshotPath) {
186
- const dir = dirname(screenshotPath);
187
- if (dir !== screenshotFolder) {
188
- await mkdir(dirname(screenshotPath), {
189
- recursive: true
190
- });
191
- }
184
+ const nameInProject = (testInfo === null || testInfo === void 0 ? void 0 : testInfo.project.name) ? `${testInfo.project.name}/${name}` : name;
185
+ const screenshotPath = useArgosReporter && testInfo ? testInfo.outputPath("argos", `${nameInProject}.png`) : resolve(screenshotFolder, `${nameInProject}.png`);
186
+ const dir = dirname(screenshotPath);
187
+ if (dir !== screenshotFolder) {
188
+ await mkdir(dirname(screenshotPath), {
189
+ recursive: true
190
+ });
192
191
  }
193
192
  await Promise.all([
194
193
  handle.screenshot({
195
- path: screenshotPath ?? undefined,
194
+ path: screenshotPath,
196
195
  type: "png",
197
196
  fullPage,
198
197
  mask: [
@@ -201,21 +200,21 @@ async function argosScreenshot(page, name, options = {}) {
201
200
  animations: "disabled",
202
201
  ...playwrightOptions
203
202
  }),
204
- screenshotPath ? writeMetadata(screenshotPath, metadata) : null
203
+ writeMetadata(screenshotPath, metadata)
205
204
  ]);
206
- if (useArgosReporter) {
205
+ if (useArgosReporter && testInfo) {
207
206
  await Promise.all([
208
- testInfo.attach(getAttachmentName(name, "metadata"), {
207
+ testInfo.attach(getAttachmentName(nameInProject, "metadata"), {
209
208
  path: getMetadataPath(screenshotPath),
210
209
  contentType: "application/json"
211
210
  }),
212
- testInfo.attach(getAttachmentName(name, "screenshot"), {
211
+ testInfo.attach(getAttachmentName(nameInProject, "screenshot"), {
213
212
  path: screenshotPath,
214
213
  contentType: "image/png"
215
214
  })
216
215
  ]);
217
216
  }
218
- }
217
+ };
219
218
  // If no viewports are specified, take a single screenshot
220
219
  if (viewports) {
221
220
  // Take screenshots for each viewport
package/dist/reporter.mjs CHANGED
@@ -6,6 +6,7 @@ import { tmpdir } from 'node:os';
6
6
  import { relative, dirname, join } from 'node:path';
7
7
  import { getGitRepositoryPath, readVersionFromPackage } from '@argos-ci/util';
8
8
  import { createRequire } from 'node:module';
9
+ import createDebug from 'debug';
9
10
 
10
11
  function getOriginalAttachmentName(name) {
11
12
  return name.replace(/^argos\/[^/]+___/, "");
@@ -103,6 +104,9 @@ async function getMetadataFromTestCase(testCase, testResult) {
103
104
  return metadata;
104
105
  }
105
106
 
107
+ const KEY = "@argos-ci/playwright";
108
+ const debug = createDebug(KEY);
109
+
106
110
  async function createTempDirectory() {
107
111
  const osTmpDirectory = tmpdir();
108
112
  const path = join(osTmpDirectory, "argos." + randomBytes(16).toString("hex"));
@@ -139,7 +143,9 @@ class ArgosReporter {
139
143
  recursive: true
140
144
  });
141
145
  }
146
+ debug(`Writing file to ${path}`);
142
147
  await writeFile(path, body);
148
+ debug(`File written to ${path}`);
143
149
  }
144
150
  async copyFile(from, to) {
145
151
  const dir = dirname(to);
@@ -148,7 +154,9 @@ class ArgosReporter {
148
154
  recursive: true
149
155
  });
150
156
  }
157
+ debug(`Copying file from ${from} to ${to}`);
151
158
  await copyFile(from, to);
159
+ debug(`File copied from ${from} to ${to}`);
152
160
  }
153
161
  getAutomaticScreenshotName(test, result) {
154
162
  let name = test.titlePath().join(" ");
@@ -157,10 +165,14 @@ class ArgosReporter {
157
165
  return name;
158
166
  }
159
167
  async onBegin(config, _suite) {
168
+ debug("ArgosReporter:onBegin");
160
169
  this.playwrightConfig = config;
170
+ debug(`Creating temporary directory for uploads`);
161
171
  this.uploadDir = await createTempDirectory();
172
+ debug(`Temporary directory created for uploads: ${this.uploadDir}`);
162
173
  }
163
174
  async onTestEnd(test, result) {
175
+ debug("ArgosReporter:onTestEnd");
164
176
  await Promise.all(result.attachments.map(async (attachment)=>{
165
177
  if (checkIsArgosScreenshot(attachment) || checkIsArgosScreenshotMetadata(attachment)) {
166
178
  const path = join(this.uploadDir, getAttachmentFilename(attachment.name));
@@ -183,9 +195,21 @@ class ArgosReporter {
183
195
  }));
184
196
  }
185
197
  async onEnd(_result) {
186
- if (!this.uploadToArgos) return;
198
+ debug("ArgosReporter:onEnd");
199
+ if (!this.uploadToArgos) {
200
+ debug("Not uploading to Argos because uploadToArgos is false.");
201
+ debug(`Upload directory: ${this.uploadDir}`);
202
+ return;
203
+ }
204
+ debug("Getting parallel from config");
187
205
  const parallel = await getParallelFromConfig(this.playwrightConfig);
206
+ if (parallel) {
207
+ debug(`Using parallel config — total: ${parallel.total}, nonce: "${parallel.nonce}"`);
208
+ } else {
209
+ debug("Non-parallel mode");
210
+ }
188
211
  try {
212
+ debug("Uploading to Argos");
189
213
  const res = await upload({
190
214
  files: [
191
215
  "**/*.png"
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.9.2",
4
+ "version": "1.9.4-alpha.1+f0cee6a",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -42,15 +42,17 @@
42
42
  "node": ">=16.0.0"
43
43
  },
44
44
  "dependencies": {
45
- "@argos-ci/browser": "1.4.1",
46
- "@argos-ci/core": "1.5.4",
45
+ "@argos-ci/browser": "1.5.0",
46
+ "@argos-ci/core": "1.5.5-alpha.3+f0cee6a",
47
47
  "@argos-ci/util": "1.2.1",
48
- "chalk": "^5.3.0"
48
+ "chalk": "^5.3.0",
49
+ "debug": "^4.3.4"
49
50
  },
50
51
  "devDependencies": {
51
- "@argos-ci/cli": "1.0.11",
52
+ "@argos-ci/cli": "1.0.12-alpha.3+f0cee6a",
52
53
  "@argos-ci/playwright": "workspace:.",
53
- "@playwright/test": "^1.38.1",
54
+ "@playwright/test": "^1.42.1",
55
+ "@types/debug": "^4.1.12",
54
56
  "@types/node": "^16.0.0"
55
57
  },
56
58
  "scripts": {
@@ -59,5 +61,5 @@
59
61
  "test": "pnpm exec playwright test",
60
62
  "e2e": "UPLOAD_TO_ARGOS=true pnpm run test"
61
63
  },
62
- "gitHead": "3c0a10a7ec14c294c801491aca79cacb2f07edc2"
64
+ "gitHead": "f0cee6a09987b4af96e8d6705f958a40ebe2b866"
63
65
  }