@argos-ci/playwright 1.9.3 → 2.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.mjs +16 -17
- package/dist/reporter.d.ts +3 -2
- package/dist/reporter.mjs +44 -10
- package/package.json +8 -6
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
|
|
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
|
|
180
|
+
};
|
|
181
|
+
const stabilizeAndScreenshot = async (name)=>{
|
|
182
182
|
await page.waitForFunction(()=>window.__ARGOS__.waitForStability());
|
|
183
183
|
const metadata = await collectMetadata(testInfo);
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
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
|
-
|
|
203
|
+
writeMetadata(screenshotPath, metadata)
|
|
205
204
|
]);
|
|
206
|
-
if (useArgosReporter) {
|
|
205
|
+
if (useArgosReporter && testInfo) {
|
|
207
206
|
await Promise.all([
|
|
208
|
-
testInfo.attach(getAttachmentName(
|
|
207
|
+
testInfo.attach(getAttachmentName(nameInProject, "metadata"), {
|
|
209
208
|
path: getMetadataPath(screenshotPath),
|
|
210
209
|
contentType: "application/json"
|
|
211
210
|
}),
|
|
212
|
-
testInfo.attach(getAttachmentName(
|
|
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.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type ArgosReporterOptions = Omit<UploadParameters, "files" | "root"> & {
|
|
|
9
9
|
uploadToArgos?: boolean;
|
|
10
10
|
};
|
|
11
11
|
declare class ArgosReporter implements Reporter {
|
|
12
|
-
|
|
12
|
+
createUploadDirPromise: null | Promise<string>;
|
|
13
13
|
config: ArgosReporterOptions;
|
|
14
14
|
playwrightConfig: FullConfig;
|
|
15
15
|
uploadToArgos: boolean;
|
|
@@ -17,7 +17,8 @@ declare class ArgosReporter implements Reporter {
|
|
|
17
17
|
writeFile(path: string, body: Buffer | string): Promise<void>;
|
|
18
18
|
copyFile(from: string, to: string): Promise<void>;
|
|
19
19
|
getAutomaticScreenshotName(test: TestCase, result: TestResult): string;
|
|
20
|
-
|
|
20
|
+
getUploadDir(): Promise<string>;
|
|
21
|
+
onBegin(config: FullConfig, _suite: Suite): void;
|
|
21
22
|
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
22
23
|
onEnd(_result: FullResult): Promise<{
|
|
23
24
|
status: "failed";
|
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,12 +104,17 @@ async function getMetadataFromTestCase(testCase, testResult) {
|
|
|
103
104
|
return metadata;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
const KEY = "@argos-ci/playwright";
|
|
108
|
+
const debug = createDebug(KEY);
|
|
109
|
+
|
|
110
|
+
async function createUploadDirectory() {
|
|
111
|
+
debug("Creating temporary directory for screenshots");
|
|
107
112
|
const osTmpDirectory = tmpdir();
|
|
108
113
|
const path = join(osTmpDirectory, "argos." + randomBytes(16).toString("hex"));
|
|
109
114
|
await mkdir(path, {
|
|
110
115
|
recursive: true
|
|
111
116
|
});
|
|
117
|
+
debug(`Temporary directory created: ${path}`);
|
|
112
118
|
return path;
|
|
113
119
|
}
|
|
114
120
|
async function getParallelFromConfig(config) {
|
|
@@ -124,31 +130,38 @@ async function getParallelFromConfig(config) {
|
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
132
|
class ArgosReporter {
|
|
127
|
-
|
|
133
|
+
createUploadDirPromise;
|
|
128
134
|
config;
|
|
129
135
|
playwrightConfig;
|
|
130
136
|
uploadToArgos;
|
|
131
137
|
constructor(config){
|
|
132
138
|
this.config = config;
|
|
133
139
|
this.uploadToArgos = config.uploadToArgos ?? true;
|
|
140
|
+
this.createUploadDirPromise = null;
|
|
134
141
|
}
|
|
135
142
|
async writeFile(path, body) {
|
|
143
|
+
const uploadDir = await this.getUploadDir();
|
|
136
144
|
const dir = dirname(path);
|
|
137
|
-
if (dir !==
|
|
145
|
+
if (dir !== uploadDir) {
|
|
138
146
|
await mkdir(dir, {
|
|
139
147
|
recursive: true
|
|
140
148
|
});
|
|
141
149
|
}
|
|
150
|
+
debug(`Writing file to ${path}`);
|
|
142
151
|
await writeFile(path, body);
|
|
152
|
+
debug(`File written to ${path}`);
|
|
143
153
|
}
|
|
144
154
|
async copyFile(from, to) {
|
|
155
|
+
const uploadDir = await this.getUploadDir();
|
|
145
156
|
const dir = dirname(to);
|
|
146
|
-
if (dir !==
|
|
157
|
+
if (dir !== uploadDir) {
|
|
147
158
|
await mkdir(dir, {
|
|
148
159
|
recursive: true
|
|
149
160
|
});
|
|
150
161
|
}
|
|
162
|
+
debug(`Copying file from ${from} to ${to}`);
|
|
151
163
|
await copyFile(from, to);
|
|
164
|
+
debug(`File copied from ${from} to ${to}`);
|
|
152
165
|
}
|
|
153
166
|
getAutomaticScreenshotName(test, result) {
|
|
154
167
|
let name = test.titlePath().join(" ");
|
|
@@ -156,14 +169,22 @@ class ArgosReporter {
|
|
|
156
169
|
name += result.status === "failed" || result.status === "timedOut" ? " (failed)" : "";
|
|
157
170
|
return name;
|
|
158
171
|
}
|
|
159
|
-
|
|
172
|
+
getUploadDir() {
|
|
173
|
+
if (!this.createUploadDirPromise) {
|
|
174
|
+
this.createUploadDirPromise = createUploadDirectory();
|
|
175
|
+
}
|
|
176
|
+
return this.createUploadDirPromise;
|
|
177
|
+
}
|
|
178
|
+
onBegin(config, _suite) {
|
|
179
|
+
debug("ArgosReporter:onBegin");
|
|
160
180
|
this.playwrightConfig = config;
|
|
161
|
-
this.uploadDir = await createTempDirectory();
|
|
162
181
|
}
|
|
163
182
|
async onTestEnd(test, result) {
|
|
183
|
+
const uploadDir = await this.getUploadDir();
|
|
184
|
+
debug("ArgosReporter:onTestEnd");
|
|
164
185
|
await Promise.all(result.attachments.map(async (attachment)=>{
|
|
165
186
|
if (checkIsArgosScreenshot(attachment) || checkIsArgosScreenshotMetadata(attachment)) {
|
|
166
|
-
const path = join(
|
|
187
|
+
const path = join(uploadDir, getAttachmentFilename(attachment.name));
|
|
167
188
|
await this.copyFile(attachment.path, path);
|
|
168
189
|
return;
|
|
169
190
|
}
|
|
@@ -172,7 +193,7 @@ class ArgosReporter {
|
|
|
172
193
|
const trace = result.attachments.find(checkIsTrace) ?? null;
|
|
173
194
|
const metadata = await getMetadataFromTestCase(test, result);
|
|
174
195
|
const name = this.getAutomaticScreenshotName(test, result);
|
|
175
|
-
const path = join(
|
|
196
|
+
const path = join(uploadDir, `${name}.png`);
|
|
176
197
|
await Promise.all([
|
|
177
198
|
this.writeFile(path + ".argos.json", JSON.stringify(metadata)),
|
|
178
199
|
this.copyFile(attachment.path, path),
|
|
@@ -183,14 +204,27 @@ class ArgosReporter {
|
|
|
183
204
|
}));
|
|
184
205
|
}
|
|
185
206
|
async onEnd(_result) {
|
|
186
|
-
|
|
207
|
+
debug("ArgosReporter:onEnd");
|
|
208
|
+
const uploadDir = await this.getUploadDir();
|
|
209
|
+
if (!this.uploadToArgos) {
|
|
210
|
+
debug("Not uploading to Argos because uploadToArgos is false.");
|
|
211
|
+
debug(`Upload directory: ${uploadDir}`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
debug("Getting parallel from config");
|
|
187
215
|
const parallel = await getParallelFromConfig(this.playwrightConfig);
|
|
216
|
+
if (parallel) {
|
|
217
|
+
debug(`Using parallel config — total: ${parallel.total}, nonce: "${parallel.nonce}"`);
|
|
218
|
+
} else {
|
|
219
|
+
debug("Non-parallel mode");
|
|
220
|
+
}
|
|
188
221
|
try {
|
|
222
|
+
debug("Uploading to Argos");
|
|
189
223
|
const res = await upload({
|
|
190
224
|
files: [
|
|
191
225
|
"**/*.png"
|
|
192
226
|
],
|
|
193
|
-
root:
|
|
227
|
+
root: uploadDir,
|
|
194
228
|
parallel: parallel ?? undefined,
|
|
195
229
|
...this.config
|
|
196
230
|
});
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -43,14 +43,16 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@argos-ci/browser": "1.5.0",
|
|
46
|
-
"@argos-ci/core": "1.5.
|
|
46
|
+
"@argos-ci/core": "1.5.5",
|
|
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.
|
|
52
|
+
"@argos-ci/cli": "1.0.12",
|
|
52
53
|
"@argos-ci/playwright": "workspace:.",
|
|
53
|
-
"@playwright/test": "^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": "
|
|
64
|
+
"gitHead": "4da90d82cfb93a1377497731164b9fbaeb9fb7f6"
|
|
63
65
|
}
|