@argos-ci/playwright 1.1.0 → 1.2.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
@@ -58,6 +58,8 @@ async function getTestMetadataFromTestInfo(testInfo) {
58
58
  id: testInfo.testId,
59
59
  title: testInfo.title,
60
60
  titlePath: testInfo.titlePath,
61
+ retry: testInfo.retry,
62
+ retries: testInfo.project.retries,
61
63
  location: {
62
64
  file: repositoryPath ? relative(repositoryPath, testInfo.file) : testInfo.file,
63
65
  line: testInfo.line,
@@ -8,6 +8,7 @@ declare class ArgosReporter implements Reporter {
8
8
  playwrightConfig: FullConfig;
9
9
  constructor(config: ArgosReporterOptions);
10
10
  writeFile(path: string, body: Buffer | string): Promise<void>;
11
+ getAutomaticScreenshotName(test: TestCase, result: TestResult): string;
11
12
  onBegin(config: FullConfig, _suite: Suite): Promise<void>;
12
13
  onTestEnd(test: TestCase, result: TestResult): Promise<void>;
13
14
  onEnd(_result: FullResult): Promise<{
package/dist/reporter.mjs CHANGED
@@ -18,6 +18,18 @@ function getAttachementFilename(name) {
18
18
  }
19
19
  throw new Error(`Unknown attachment name: ${name}`);
20
20
  }
21
+ function checkIsTrace(attachment) {
22
+ return attachment.name === "trace" && attachment.contentType === "application/zip" && Boolean(attachment.path);
23
+ }
24
+ function checkIsArgosScreenshot(attachment) {
25
+ return attachment.name.startsWith("argos/") && attachment.contentType === "image/png" && Boolean(attachment.body);
26
+ }
27
+ function checkIsArgosScreenshotMetadata(attachment) {
28
+ return attachment.name.startsWith("argos/") && attachment.contentType === "application/json" && Boolean(attachment.body);
29
+ }
30
+ function checkIsAutomaticScreenshot(attachment) {
31
+ return attachment.name === "screenshot" && attachment.contentType === "image/png" && Boolean(attachment.path);
32
+ }
21
33
 
22
34
  const require = createRequire(import.meta.url);
23
35
  const tryResolve = (pkg)=>{
@@ -63,11 +75,13 @@ async function getLibraryMetadata() {
63
75
  };
64
76
  return metadata;
65
77
  }
66
- async function getTestMetadataFromTestCase(testCase) {
78
+ async function getTestMetadataFromTestCase(testCase, testResult) {
67
79
  const repositoryPath = await getGitRepositoryPath();
68
80
  const testMetadata = {
69
81
  title: testCase.title,
70
82
  titlePath: testCase.titlePath(),
83
+ retry: testResult.retry,
84
+ retries: testCase.retries,
71
85
  location: {
72
86
  file: repositoryPath ? relative(repositoryPath, testCase.location.file) : testCase.location.file,
73
87
  line: testCase.location.line,
@@ -76,10 +90,10 @@ async function getTestMetadataFromTestCase(testCase) {
76
90
  };
77
91
  return testMetadata;
78
92
  }
79
- async function getMetadataFromTestCase(testCase) {
93
+ async function getMetadataFromTestCase(testCase, testResult) {
80
94
  const [libMetadata, testMetadata] = await Promise.all([
81
95
  getLibraryMetadata(),
82
- getTestMetadataFromTestCase(testCase)
96
+ getTestMetadataFromTestCase(testCase, testResult)
83
97
  ]);
84
98
  const metadata = {
85
99
  test: testMetadata,
@@ -124,29 +138,35 @@ class ArgosReporter {
124
138
  }
125
139
  await writeFile(path, body);
126
140
  }
141
+ getAutomaticScreenshotName(test, result) {
142
+ let name = test.titlePath().join(" ");
143
+ name += result.retry > 0 ? ` #${result.retry + 1}` : "";
144
+ name += result.status === "failed" || result.status === "timedOut" ? " (failed)" : "";
145
+ return name;
146
+ }
127
147
  async onBegin(config, _suite) {
128
148
  this.playwrightConfig = config;
129
149
  this.uploadDir = await createTempDirectory();
130
150
  }
131
151
  async onTestEnd(test, result) {
132
152
  await Promise.all(result.attachments.map(async (attachment)=>{
133
- if (attachment.name.startsWith("argos/")) {
134
- if (!attachment.body) {
135
- throw new Error("Missing attachment body");
136
- }
153
+ if (checkIsArgosScreenshot(attachment) || checkIsArgosScreenshotMetadata(attachment)) {
137
154
  const path = join(this.uploadDir, getAttachementFilename(attachment.name));
138
155
  await this.writeFile(path, attachment.body);
139
156
  return;
140
157
  }
141
158
  // Error screenshots are sent to Argos
142
- if (attachment.name === "screenshot" && attachment.contentType === "image/png" && attachment.path) {
143
- const metadata = await getMetadataFromTestCase(test);
144
- const name = test.titlePath().join(" ");
145
- const path = join(this.uploadDir, result.status === "failed" || result.status === "timedOut" ? `${name} (failed).png` : `${name}.png`);
159
+ if (checkIsAutomaticScreenshot(attachment)) {
160
+ const trace = result.attachments.find(checkIsTrace) ?? null;
161
+ const metadata = await getMetadataFromTestCase(test, result);
162
+ const name = this.getAutomaticScreenshotName(test, result);
163
+ const path = join(this.uploadDir, `${name}.png`);
146
164
  await Promise.all([
147
165
  this.writeFile(path + ".argos.json", JSON.stringify(metadata)),
148
- copyFile(attachment.path, path)
166
+ copyFile(attachment.path, path),
167
+ trace ? copyFile(trace.path, path + ".pw-trace.zip") : null
149
168
  ]);
169
+ return;
150
170
  }
151
171
  }));
152
172
  }
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.1.0",
4
+ "version": "1.2.1",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -43,11 +43,11 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@argos-ci/browser": "1.0.0",
46
- "@argos-ci/core": "1.1.0",
47
- "@argos-ci/util": "1.0.0"
46
+ "@argos-ci/core": "1.2.0",
47
+ "@argos-ci/util": "1.1.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@argos-ci/cli": "1.0.1",
50
+ "@argos-ci/cli": "1.0.2",
51
51
  "@argos-ci/playwright": "workspace:.",
52
52
  "@playwright/test": "^1.38.1",
53
53
  "@types/node": "^16.0.0"
@@ -55,8 +55,8 @@
55
55
  "scripts": {
56
56
  "prebuild": "rm -rf dist",
57
57
  "build": "rollup -c",
58
- "test": "pnpm exec playwright test --shard=2/4",
58
+ "test": "pnpm exec playwright test",
59
59
  "e2e": "WITH_ARGOS_REPORTER=true pnpm run test"
60
60
  },
61
- "gitHead": "08246344886ff258fab097c370b4ff29cb1121b0"
61
+ "gitHead": "cb1cd503c540349ca4444cd2cc5b6cd267cf85cf"
62
62
  }