@argos-ci/playwright 3.3.0 → 3.4.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 +26 -1
- package/dist/index.mjs +48 -6
- package/dist/reporter.d.ts +0 -1
- package/dist/reporter.mjs +10 -7
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,31 @@ type ArgosScreenshotOptions = {
|
|
|
20
20
|
* @default true
|
|
21
21
|
*/
|
|
22
22
|
disableHover?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Sensitivity threshold between 0 and 1.
|
|
25
|
+
* The higher the threshold, the less sensitive the diff will be.
|
|
26
|
+
* @default 0.5
|
|
27
|
+
*/
|
|
28
|
+
threshold?: number;
|
|
23
29
|
} & LocatorOptions & ScreenshotOptions<LocatorScreenshotOptions> & ScreenshotOptions<PageScreenshotOptions>;
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Stabilize the UI and takes a screenshot of the application under test.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* argosScreenshot(page, "my-screenshot")
|
|
35
|
+
* @see https://argos-ci.com/docs/playwright#api-overview
|
|
36
|
+
*/
|
|
37
|
+
declare function argosScreenshot(
|
|
38
|
+
/**
|
|
39
|
+
* Playwright `page` object.
|
|
40
|
+
*/
|
|
41
|
+
page: Page,
|
|
42
|
+
/**
|
|
43
|
+
* Name of the screenshot. Must be unique.
|
|
44
|
+
*/
|
|
45
|
+
name: string,
|
|
46
|
+
/**
|
|
47
|
+
* Options for the screenshot.
|
|
48
|
+
*/
|
|
49
|
+
options?: ArgosScreenshotOptions): Promise<void>;
|
|
25
50
|
export { ArgosScreenshotOptions, argosScreenshot };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir } from 'node:fs/promises';
|
|
2
2
|
import { relative, resolve, dirname } from 'node:path';
|
|
3
3
|
import { resolveViewport, getGlobalScript } from '@argos-ci/browser';
|
|
4
|
-
import { getGitRepositoryPath, readVersionFromPackage, getScreenshotName, writeMetadata, getMetadataPath } from '@argos-ci/util';
|
|
4
|
+
import { getGitRepositoryPath, readVersionFromPackage, getScreenshotName, validateThreshold, writeMetadata, getMetadataPath } from '@argos-ci/util';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
|
|
7
7
|
function getAttachmentName(name, type) {
|
|
@@ -60,6 +60,7 @@ async function getTestMetadataFromTestInfo(testInfo) {
|
|
|
60
60
|
titlePath: testInfo.titlePath,
|
|
61
61
|
retry: testInfo.retry,
|
|
62
62
|
retries: testInfo.project.retries,
|
|
63
|
+
repeat: testInfo.repeatEachIndex,
|
|
63
64
|
location: {
|
|
64
65
|
file: repositoryPath ? relative(repositoryPath, testInfo.file) : testInfo.file,
|
|
65
66
|
line: testInfo.line,
|
|
@@ -125,7 +126,40 @@ function getViewportSize(page) {
|
|
|
125
126
|
});
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Get the screenshot names based on the test info.
|
|
131
|
+
*/ function getScreenshotNames(name, testInfo) {
|
|
132
|
+
if (testInfo) {
|
|
133
|
+
const projectName = `${testInfo.project.name}/${name}`;
|
|
134
|
+
if (testInfo.repeatEachIndex > 0) {
|
|
135
|
+
return {
|
|
136
|
+
name: `${projectName} repeat-${testInfo.repeatEachIndex}`,
|
|
137
|
+
baseName: projectName
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
name: projectName,
|
|
142
|
+
baseName: null
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
name,
|
|
147
|
+
baseName: null
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Stabilize the UI and takes a screenshot of the application under test.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* argosScreenshot(page, "my-screenshot")
|
|
155
|
+
* @see https://argos-ci.com/docs/playwright#api-overview
|
|
156
|
+
*/ async function argosScreenshot(/**
|
|
157
|
+
* Playwright `page` object.
|
|
158
|
+
*/ page, /**
|
|
159
|
+
* Name of the screenshot. Must be unique.
|
|
160
|
+
*/ name, /**
|
|
161
|
+
* Options for the screenshot.
|
|
162
|
+
*/ options = {}) {
|
|
129
163
|
const { element, has, hasText, viewports, argosCSS, ...playwrightOptions } = options;
|
|
130
164
|
if (!page) {
|
|
131
165
|
throw new Error("A Playwright `page` object is required.");
|
|
@@ -180,9 +214,17 @@ async function argosScreenshot(page, name, options = {}) {
|
|
|
180
214
|
};
|
|
181
215
|
const stabilizeAndScreenshot = async (name)=>{
|
|
182
216
|
await page.waitForFunction(()=>window.__ARGOS__.waitForStability());
|
|
217
|
+
const names = getScreenshotNames(name, testInfo);
|
|
183
218
|
const metadata = await collectMetadata(testInfo);
|
|
184
|
-
|
|
185
|
-
|
|
219
|
+
metadata.transient = {};
|
|
220
|
+
if (options.threshold !== undefined) {
|
|
221
|
+
validateThreshold(options.threshold);
|
|
222
|
+
metadata.transient.threshold = options.threshold;
|
|
223
|
+
}
|
|
224
|
+
if (names.baseName) {
|
|
225
|
+
metadata.transient.baseName = `${names.baseName}.png`;
|
|
226
|
+
}
|
|
227
|
+
const screenshotPath = useArgosReporter && testInfo ? testInfo.outputPath("argos", `${names.name}.png`) : resolve(screenshotFolder, `${names.name}.png`);
|
|
186
228
|
const dir = dirname(screenshotPath);
|
|
187
229
|
if (dir !== screenshotFolder) {
|
|
188
230
|
await mkdir(dirname(screenshotPath), {
|
|
@@ -204,11 +246,11 @@ async function argosScreenshot(page, name, options = {}) {
|
|
|
204
246
|
]);
|
|
205
247
|
if (useArgosReporter && testInfo) {
|
|
206
248
|
await Promise.all([
|
|
207
|
-
testInfo.attach(getAttachmentName(
|
|
249
|
+
testInfo.attach(getAttachmentName(names.name, "metadata"), {
|
|
208
250
|
path: getMetadataPath(screenshotPath),
|
|
209
251
|
contentType: "application/json"
|
|
210
252
|
}),
|
|
211
|
-
testInfo.attach(getAttachmentName(
|
|
253
|
+
testInfo.attach(getAttachmentName(names.name, "screenshot"), {
|
|
212
254
|
path: screenshotPath,
|
|
213
255
|
contentType: "image/png"
|
|
214
256
|
})
|
package/dist/reporter.d.ts
CHANGED
|
@@ -59,7 +59,6 @@ declare class ArgosReporter implements Reporter {
|
|
|
59
59
|
* Copy the trace file if found in the result.
|
|
60
60
|
*/
|
|
61
61
|
copyTraceIfFound(result: TestResult, path: string): Promise<void>;
|
|
62
|
-
getAutomaticScreenshotName(test: TestCase, result: TestResult): string;
|
|
63
62
|
/**
|
|
64
63
|
* Get the root upload directory (cached).
|
|
65
64
|
*/
|
package/dist/reporter.mjs
CHANGED
|
@@ -84,6 +84,7 @@ async function getTestMetadataFromTestCase(testCase, testResult) {
|
|
|
84
84
|
titlePath: testCase.titlePath(),
|
|
85
85
|
retry: testResult.retry,
|
|
86
86
|
retries: testCase.retries,
|
|
87
|
+
repeat: testCase.repeatEachIndex,
|
|
87
88
|
location: {
|
|
88
89
|
file: repositoryPath ? relative(repositoryPath, testCase.location.file) : testCase.location.file,
|
|
89
90
|
line: testCase.location.line,
|
|
@@ -152,6 +153,14 @@ async function getParallelFromConfig(config) {
|
|
|
152
153
|
index: config.shard.current
|
|
153
154
|
};
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Get the automatic screenshot name.
|
|
158
|
+
*/ function getAutomaticScreenshotName(test, result) {
|
|
159
|
+
let name = test.titlePath().join(" ");
|
|
160
|
+
name += result.retry > 0 ? ` #${result.retry + 1}` : "";
|
|
161
|
+
name += result.status === "failed" || result.status === "timedOut" ? " (failed)" : "";
|
|
162
|
+
return name;
|
|
163
|
+
}
|
|
155
164
|
class ArgosReporter {
|
|
156
165
|
rootUploadDirectoryPromise;
|
|
157
166
|
uploadDirectoryPromises;
|
|
@@ -188,12 +197,6 @@ class ArgosReporter {
|
|
|
188
197
|
await this.copyFile(trace.path, path + ".pw-trace.zip");
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
|
-
getAutomaticScreenshotName(test, result) {
|
|
192
|
-
let name = test.titlePath().join(" ");
|
|
193
|
-
name += result.retry > 0 ? ` #${result.retry + 1}` : "";
|
|
194
|
-
name += result.status === "failed" || result.status === "timedOut" ? " (failed)" : "";
|
|
195
|
-
return name;
|
|
196
|
-
}
|
|
197
200
|
/**
|
|
198
201
|
* Get the root upload directory (cached).
|
|
199
202
|
*/ getRootUploadDirectory() {
|
|
@@ -226,7 +229,7 @@ class ArgosReporter {
|
|
|
226
229
|
// Error screenshots are sent to Argos
|
|
227
230
|
if (checkIsAutomaticScreenshot(attachment)) {
|
|
228
231
|
const metadata = await getMetadataFromTestCase(test, result);
|
|
229
|
-
const name =
|
|
232
|
+
const name = getAutomaticScreenshotName(test, result);
|
|
230
233
|
const path = join(uploadDir, `${name}.png`);
|
|
231
234
|
await Promise.all([
|
|
232
235
|
this.writeFile(path + ".argos.json", JSON.stringify(metadata)),
|
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": "3.
|
|
4
|
+
"version": "3.4.0",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@argos-ci/browser": "2.1.2",
|
|
46
|
-
"@argos-ci/core": "2.
|
|
47
|
-
"@argos-ci/util": "2.
|
|
46
|
+
"@argos-ci/core": "2.4.0",
|
|
47
|
+
"@argos-ci/util": "2.1.0",
|
|
48
48
|
"chalk": "^5.3.0",
|
|
49
49
|
"debug": "^4.3.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@argos-ci/cli": "2.
|
|
52
|
+
"@argos-ci/cli": "2.3.0",
|
|
53
53
|
"@argos-ci/playwright": "workspace:.",
|
|
54
54
|
"@playwright/test": "^1.43.0",
|
|
55
55
|
"@types/debug": "^4.1.12",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"test": "pnpm exec -- playwright test",
|
|
62
62
|
"e2e": "UPLOAD_TO_ARGOS=true pnpm run test"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "aca82cf842a6d8310611a8594c581794df85cbd8"
|
|
65
65
|
}
|