@argos-ci/playwright 6.4.2 → 6.6.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.cjs +4 -4
- package/dist/index.d.mts +185 -0
- package/dist/index.mjs +564 -0
- package/dist/reporter.d.mts +1984 -0
- package/dist/reporter.mjs +323 -0
- package/package.json +14 -14
- package/dist/index.d.ts +0 -158
- package/dist/index.js +0 -600
- package/dist/reporter.d.ts +0 -70
- package/dist/reporter.js +0 -387
package/dist/index.js
DELETED
|
@@ -1,600 +0,0 @@
|
|
|
1
|
-
// src/aria-snapshot.ts
|
|
2
|
-
import { writeFile } from "fs/promises";
|
|
3
|
-
import { getMetadataPath, writeMetadata } from "@argos-ci/util";
|
|
4
|
-
|
|
5
|
-
// src/util.ts
|
|
6
|
-
import { createRequire as createRequire2 } from "module";
|
|
7
|
-
|
|
8
|
-
// src/metadata.ts
|
|
9
|
-
import {
|
|
10
|
-
getGitRepositoryPath,
|
|
11
|
-
readVersionFromPackage
|
|
12
|
-
} from "@argos-ci/util";
|
|
13
|
-
import { relative } from "path";
|
|
14
|
-
import { createRequire } from "module";
|
|
15
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
16
|
-
var require2 = createRequire(import.meta.url);
|
|
17
|
-
function tryResolve(pkg) {
|
|
18
|
-
try {
|
|
19
|
-
return require2.resolve(pkg);
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
var metadataConfigStorage = new AsyncLocalStorage();
|
|
25
|
-
function setMetadataConfig(metadata) {
|
|
26
|
-
metadataConfigStorage.enterWith(metadata);
|
|
27
|
-
}
|
|
28
|
-
var DEFAULT_PLAYWRIGHT_LIBRARIES = [
|
|
29
|
-
"@playwright/test",
|
|
30
|
-
"playwright",
|
|
31
|
-
"playwright-core"
|
|
32
|
-
];
|
|
33
|
-
function getMetadataOverrides() {
|
|
34
|
-
return metadataConfigStorage.getStore();
|
|
35
|
-
}
|
|
36
|
-
async function getAutomationLibraryMetadata() {
|
|
37
|
-
const metadataConfig = metadataConfigStorage.getStore();
|
|
38
|
-
const libraries = metadataConfig?.playwrightLibraries ?? DEFAULT_PLAYWRIGHT_LIBRARIES;
|
|
39
|
-
for (const name of libraries) {
|
|
40
|
-
const pkgPath = tryResolve(`${name}/package.json`);
|
|
41
|
-
if (pkgPath) {
|
|
42
|
-
const version = await readVersionFromPackage(pkgPath);
|
|
43
|
-
return { version, name };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
throw new Error(
|
|
47
|
-
`Unable to find any of the following packages: ${libraries.join(", ")}`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
async function getArgosPlaywrightVersion() {
|
|
51
|
-
const pkgPath = require2.resolve("@argos-ci/playwright/package.json");
|
|
52
|
-
return readVersionFromPackage(pkgPath);
|
|
53
|
-
}
|
|
54
|
-
async function getSdkMetadata() {
|
|
55
|
-
const metadataConfig = metadataConfigStorage.getStore();
|
|
56
|
-
if (metadataConfig) {
|
|
57
|
-
return metadataConfig.sdk;
|
|
58
|
-
}
|
|
59
|
-
const argosPlaywrightVersion = await getArgosPlaywrightVersion();
|
|
60
|
-
return {
|
|
61
|
-
name: "@argos-ci/playwright",
|
|
62
|
-
version: argosPlaywrightVersion
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async function getLibraryMetadata() {
|
|
66
|
-
const [automationLibrary, sdk] = await Promise.all([
|
|
67
|
-
getAutomationLibraryMetadata(),
|
|
68
|
-
getSdkMetadata()
|
|
69
|
-
]);
|
|
70
|
-
return {
|
|
71
|
-
automationLibrary,
|
|
72
|
-
sdk
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function resolveTestFilePath(filepath, repositoryPath) {
|
|
76
|
-
if (!repositoryPath) {
|
|
77
|
-
return filepath;
|
|
78
|
-
}
|
|
79
|
-
return relative(repositoryPath, filepath);
|
|
80
|
-
}
|
|
81
|
-
async function getTestMetadata(testInfo) {
|
|
82
|
-
const repositoryPath = await getGitRepositoryPath();
|
|
83
|
-
const metadataConfig = metadataConfigStorage.getStore();
|
|
84
|
-
if (metadataConfig?.test) {
|
|
85
|
-
return {
|
|
86
|
-
...metadataConfig.test,
|
|
87
|
-
location: metadataConfig.test?.location ? {
|
|
88
|
-
file: resolveTestFilePath(
|
|
89
|
-
metadataConfig.test.location.file,
|
|
90
|
-
repositoryPath
|
|
91
|
-
),
|
|
92
|
-
line: metadataConfig.test.location.line,
|
|
93
|
-
column: metadataConfig.test.location.column
|
|
94
|
-
} : void 0
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
if (!testInfo) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const testMetadata = {
|
|
101
|
-
id: testInfo.testId,
|
|
102
|
-
title: testInfo.title,
|
|
103
|
-
titlePath: testInfo.titlePath,
|
|
104
|
-
retry: testInfo.retry,
|
|
105
|
-
retries: testInfo.project.retries,
|
|
106
|
-
repeat: testInfo.repeatEachIndex,
|
|
107
|
-
location: {
|
|
108
|
-
file: resolveTestFilePath(testInfo.file, repositoryPath),
|
|
109
|
-
line: testInfo.line,
|
|
110
|
-
column: testInfo.column
|
|
111
|
-
},
|
|
112
|
-
annotations: testInfo.annotations
|
|
113
|
-
};
|
|
114
|
-
return testMetadata;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/util.ts
|
|
118
|
-
import {
|
|
119
|
-
getGlobalScript
|
|
120
|
-
} from "@argos-ci/browser";
|
|
121
|
-
import { dirname, resolve } from "path";
|
|
122
|
-
import { mkdir } from "fs/promises";
|
|
123
|
-
var require3 = createRequire2(import.meta.url);
|
|
124
|
-
function checkIsUsingArgosReporter(testInfo) {
|
|
125
|
-
if (!testInfo) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
const reporterPath = require3.resolve("@argos-ci/playwright/reporter");
|
|
129
|
-
return testInfo.config.reporter.some(
|
|
130
|
-
(reporter) => reporter[0].includes("@argos-ci/playwright/reporter") || reporter[0] === reporterPath
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
var PNG_EXTENSION = `.png`;
|
|
134
|
-
var ARIA_EXTENSION = `.aria.yml`;
|
|
135
|
-
var METADATA_EXTENSION = `.argos.json`;
|
|
136
|
-
var MAX_NAME_LENGTH = 255 - PNG_EXTENSION.length - METADATA_EXTENSION.length;
|
|
137
|
-
async function getTestInfo() {
|
|
138
|
-
try {
|
|
139
|
-
const { test } = await import("@playwright/test");
|
|
140
|
-
return test.info();
|
|
141
|
-
} catch {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function checkIsPage(value) {
|
|
146
|
-
return Boolean(
|
|
147
|
-
value && typeof value === "object" && "bringToFront" in value && typeof value.bringToFront === "function"
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
function checkIsElementHandle(value) {
|
|
151
|
-
return Boolean(
|
|
152
|
-
value && typeof value === "object" && "asElement" in value && typeof value.asElement === "function"
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
function checkIsFrame(handler) {
|
|
156
|
-
return "page" in handler && typeof handler.page === "function";
|
|
157
|
-
}
|
|
158
|
-
function getPage(handler) {
|
|
159
|
-
if (checkIsFrame(handler)) {
|
|
160
|
-
return handler.page();
|
|
161
|
-
}
|
|
162
|
-
return handler;
|
|
163
|
-
}
|
|
164
|
-
function getViewportSize(page) {
|
|
165
|
-
const viewportSize = page.viewportSize();
|
|
166
|
-
if (!viewportSize) {
|
|
167
|
-
throw new Error("Snapshots can't be taken without a viewport.");
|
|
168
|
-
}
|
|
169
|
-
return viewportSize;
|
|
170
|
-
}
|
|
171
|
-
async function setViewportSize(page, viewportSize) {
|
|
172
|
-
await page.setViewportSize(viewportSize);
|
|
173
|
-
await page.waitForFunction(
|
|
174
|
-
({ width, height }) => window.innerWidth === width && window.innerHeight === height,
|
|
175
|
-
{ width: viewportSize.width, height: viewportSize.height }
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
function getSnapshotNames(name, testInfo) {
|
|
179
|
-
if (testInfo) {
|
|
180
|
-
const projectName = `${testInfo.project.name}/${name}`;
|
|
181
|
-
if (testInfo.repeatEachIndex > 0) {
|
|
182
|
-
return {
|
|
183
|
-
name: `${projectName} repeat-${testInfo.repeatEachIndex}`,
|
|
184
|
-
baseName: projectName
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return { name: projectName, baseName: null };
|
|
188
|
-
}
|
|
189
|
-
return { name, baseName: null };
|
|
190
|
-
}
|
|
191
|
-
async function injectArgos(handler) {
|
|
192
|
-
const injected = await handler.evaluate(
|
|
193
|
-
() => typeof window.__ARGOS__ !== "undefined"
|
|
194
|
-
);
|
|
195
|
-
if (!injected) {
|
|
196
|
-
await handler.addScriptTag({ content: getGlobalScript() });
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function prepare(args) {
|
|
200
|
-
const { handler, useArgosReporter, root } = args;
|
|
201
|
-
await Promise.all([
|
|
202
|
-
// Create the screenshot folder if it doesn't exist
|
|
203
|
-
useArgosReporter ? null : mkdir(root, { recursive: true }),
|
|
204
|
-
// Inject Argos script into the page
|
|
205
|
-
injectArgos(handler)
|
|
206
|
-
]);
|
|
207
|
-
}
|
|
208
|
-
async function getPathAndMetadata(args) {
|
|
209
|
-
const { handler, testInfo, names, extension, root, useArgosReporter } = args;
|
|
210
|
-
const overrides = getMetadataOverrides();
|
|
211
|
-
const path = useArgosReporter && testInfo ? testInfo.outputPath("argos", `${names.name}${extension}`) : resolve(root, `${names.name}${extension}`);
|
|
212
|
-
const dir = dirname(path);
|
|
213
|
-
const [colorScheme, mediaType, libMetadata, testMetadata] = await Promise.all(
|
|
214
|
-
[
|
|
215
|
-
handler.evaluate(
|
|
216
|
-
() => window.__ARGOS__.getColorScheme()
|
|
217
|
-
),
|
|
218
|
-
handler.evaluate(
|
|
219
|
-
() => window.__ARGOS__.getMediaType()
|
|
220
|
-
),
|
|
221
|
-
getLibraryMetadata(),
|
|
222
|
-
getTestMetadata(testInfo),
|
|
223
|
-
dir !== root ? mkdir(dir, { recursive: true }) : null
|
|
224
|
-
]
|
|
225
|
-
);
|
|
226
|
-
const viewportSize = checkIsFrame(handler) ? null : getViewportSize(handler);
|
|
227
|
-
const browser = getPage(handler).context().browser();
|
|
228
|
-
if (!browser) {
|
|
229
|
-
throw new Error("Can't take screenshots without a browser.");
|
|
230
|
-
}
|
|
231
|
-
const browserName = browser.browserType().name();
|
|
232
|
-
const browserVersion = browser.version();
|
|
233
|
-
const url = overrides?.url ?? handler.url();
|
|
234
|
-
const metadata = {
|
|
235
|
-
url,
|
|
236
|
-
colorScheme,
|
|
237
|
-
mediaType,
|
|
238
|
-
test: testMetadata,
|
|
239
|
-
browser: {
|
|
240
|
-
name: browserName,
|
|
241
|
-
version: browserVersion
|
|
242
|
-
},
|
|
243
|
-
...libMetadata
|
|
244
|
-
};
|
|
245
|
-
const viewport = viewportSize ?? getMetadataOverrides()?.viewport;
|
|
246
|
-
if (viewport) {
|
|
247
|
-
metadata.viewport = viewport;
|
|
248
|
-
}
|
|
249
|
-
metadata.transient = {};
|
|
250
|
-
if (names.baseName) {
|
|
251
|
-
metadata.transient.baseName = `${names.baseName}${extension}`;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
metadata,
|
|
255
|
-
path
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
function screenshotToSnapshotPath(value) {
|
|
259
|
-
return value.replace(/\.png$/, ARIA_EXTENSION);
|
|
260
|
-
}
|
|
261
|
-
async function beforeAll(handler, context, options) {
|
|
262
|
-
await handler.evaluate(
|
|
263
|
-
(context2) => window.__ARGOS__.beforeAll(context2),
|
|
264
|
-
context
|
|
265
|
-
);
|
|
266
|
-
if (options?.disableHover) {
|
|
267
|
-
await getPage(handler).mouse.move(0, 0);
|
|
268
|
-
}
|
|
269
|
-
return async () => {
|
|
270
|
-
await handler.evaluate(
|
|
271
|
-
() => window.__ARGOS__.afterAll()
|
|
272
|
-
);
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
async function beforeEach(handler, context) {
|
|
276
|
-
await handler.evaluate(
|
|
277
|
-
(context2) => window.__ARGOS__.beforeEach(context2),
|
|
278
|
-
context
|
|
279
|
-
);
|
|
280
|
-
return async () => {
|
|
281
|
-
await handler.evaluate(
|
|
282
|
-
() => window.__ARGOS__.afterEach()
|
|
283
|
-
);
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
async function increaseTimeout() {
|
|
287
|
-
const testInfo = await getTestInfo();
|
|
288
|
-
if (testInfo) {
|
|
289
|
-
const { timeout } = testInfo;
|
|
290
|
-
testInfo.setTimeout(timeout * 3);
|
|
291
|
-
return {
|
|
292
|
-
value: timeout,
|
|
293
|
-
reset: () => {
|
|
294
|
-
testInfo.setTimeout(timeout);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
async function waitForReadiness(handler, context) {
|
|
301
|
-
const timeout = await increaseTimeout();
|
|
302
|
-
try {
|
|
303
|
-
await handler.waitForFunction(
|
|
304
|
-
(context2) => {
|
|
305
|
-
const argos = window.__ARGOS__;
|
|
306
|
-
return argos.waitFor(context2);
|
|
307
|
-
},
|
|
308
|
-
context,
|
|
309
|
-
timeout ? { timeout: timeout.value } : void 0
|
|
310
|
-
);
|
|
311
|
-
timeout?.reset();
|
|
312
|
-
} catch (error) {
|
|
313
|
-
const reasons = await handler.evaluate(
|
|
314
|
-
(context2) => window.__ARGOS__.getWaitFailureExplanations(
|
|
315
|
-
context2
|
|
316
|
-
),
|
|
317
|
-
context
|
|
318
|
-
);
|
|
319
|
-
throw new Error(
|
|
320
|
-
`
|
|
321
|
-
Failed to stabilize screenshot, found the following issues:
|
|
322
|
-
${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
323
|
-
`.trim(),
|
|
324
|
-
{ cause: error }
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
async function attachAttachments(args) {
|
|
329
|
-
const { attachments, useArgosReporter, testInfo } = args;
|
|
330
|
-
if (useArgosReporter && testInfo) {
|
|
331
|
-
await Promise.all(
|
|
332
|
-
attachments.map(
|
|
333
|
-
(attachment) => testInfo.attach(attachment.name, {
|
|
334
|
-
path: attachment.path,
|
|
335
|
-
contentType: attachment.contentType
|
|
336
|
-
})
|
|
337
|
-
)
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// src/attachment.ts
|
|
343
|
-
function getAttachmentName(name, type) {
|
|
344
|
-
return `argos/${type}___${name}`;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/aria-snapshot.ts
|
|
348
|
-
var DEFAULT_SNAPSHOTS_ROOT = "./screenshots";
|
|
349
|
-
async function argosAriaSnapshot(handler, name, options = {}) {
|
|
350
|
-
const {
|
|
351
|
-
element,
|
|
352
|
-
has,
|
|
353
|
-
hasText,
|
|
354
|
-
hasNot,
|
|
355
|
-
hasNotText,
|
|
356
|
-
timeout,
|
|
357
|
-
root = DEFAULT_SNAPSHOTS_ROOT
|
|
358
|
-
} = options;
|
|
359
|
-
if (!handler) {
|
|
360
|
-
throw new Error("A Playwright `handler` object is required.");
|
|
361
|
-
}
|
|
362
|
-
if (!name) {
|
|
363
|
-
throw new Error("The `name` argument is required.");
|
|
364
|
-
}
|
|
365
|
-
const snapshotTarget = typeof element === "string" ? handler.locator(element, { has, hasText, hasNot, hasNotText }) : element ?? handler.locator("body");
|
|
366
|
-
const testInfo = await getTestInfo();
|
|
367
|
-
const useArgosReporter = checkIsUsingArgosReporter(testInfo);
|
|
368
|
-
await prepare({ handler, useArgosReporter, root });
|
|
369
|
-
const context = getStabilizationContext(options);
|
|
370
|
-
const afterAll = await beforeAll(handler, context);
|
|
371
|
-
const names = getSnapshotNames(name, testInfo);
|
|
372
|
-
const { path: snapshotPath, metadata } = await getPathAndMetadata({
|
|
373
|
-
handler,
|
|
374
|
-
extension: ARIA_EXTENSION,
|
|
375
|
-
names,
|
|
376
|
-
root,
|
|
377
|
-
testInfo,
|
|
378
|
-
useArgosReporter
|
|
379
|
-
});
|
|
380
|
-
await waitForReadiness(handler, context);
|
|
381
|
-
const afterEach = await beforeEach(handler, context);
|
|
382
|
-
await waitForReadiness(handler, context);
|
|
383
|
-
await Promise.all([
|
|
384
|
-
snapshotTarget.ariaSnapshot({ timeout }).then((snapshot) => {
|
|
385
|
-
return writeFile(snapshotPath, snapshot, "utf-8");
|
|
386
|
-
}),
|
|
387
|
-
writeMetadata(snapshotPath, metadata)
|
|
388
|
-
]);
|
|
389
|
-
const attachments = [
|
|
390
|
-
{
|
|
391
|
-
name: getAttachmentName(names.name, "aria"),
|
|
392
|
-
contentType: "application/yaml",
|
|
393
|
-
path: snapshotPath
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
name: getAttachmentName(names.name, "aria/metadata"),
|
|
397
|
-
contentType: "application/json",
|
|
398
|
-
path: getMetadataPath(snapshotPath)
|
|
399
|
-
}
|
|
400
|
-
];
|
|
401
|
-
await attachAttachments({ attachments, testInfo, useArgosReporter });
|
|
402
|
-
await afterEach();
|
|
403
|
-
await afterAll();
|
|
404
|
-
return attachments;
|
|
405
|
-
}
|
|
406
|
-
function getStabilizationContext(options) {
|
|
407
|
-
const { stabilize } = options;
|
|
408
|
-
return {
|
|
409
|
-
fullPage: false,
|
|
410
|
-
argosCSS: void 0,
|
|
411
|
-
viewports: void 0,
|
|
412
|
-
options: stabilize
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/screenshot.ts
|
|
417
|
-
import {
|
|
418
|
-
resolveViewport
|
|
419
|
-
} from "@argos-ci/browser";
|
|
420
|
-
import {
|
|
421
|
-
getMetadataPath as getMetadataPath2,
|
|
422
|
-
getScreenshotName,
|
|
423
|
-
validateThreshold,
|
|
424
|
-
writeMetadata as writeMetadata2
|
|
425
|
-
} from "@argos-ci/util";
|
|
426
|
-
import { writeFile as writeFile2 } from "fs/promises";
|
|
427
|
-
var DEFAULT_SCREENSHOT_ROOT = "./screenshots";
|
|
428
|
-
async function argosScreenshot(handler, name, options = {}) {
|
|
429
|
-
const {
|
|
430
|
-
element,
|
|
431
|
-
has,
|
|
432
|
-
hasText,
|
|
433
|
-
hasNot,
|
|
434
|
-
hasNotText,
|
|
435
|
-
viewports,
|
|
436
|
-
argosCSS: _argosCSS,
|
|
437
|
-
root = DEFAULT_SCREENSHOT_ROOT,
|
|
438
|
-
ariaSnapshot,
|
|
439
|
-
disableHover = true,
|
|
440
|
-
...playwrightOptions
|
|
441
|
-
} = options;
|
|
442
|
-
if (!handler) {
|
|
443
|
-
throw new Error("A Playwright `handler` object is required.");
|
|
444
|
-
}
|
|
445
|
-
if (!name) {
|
|
446
|
-
throw new Error("The `name` argument is required.");
|
|
447
|
-
}
|
|
448
|
-
const screenshotTarget = typeof element === "string" ? handler.locator(element, { has, hasText, hasNot, hasNotText }) : element ?? (checkIsFrame(handler) ? handler.locator("body") : handler);
|
|
449
|
-
const testInfo = await getTestInfo();
|
|
450
|
-
const useArgosReporter = checkIsUsingArgosReporter(testInfo);
|
|
451
|
-
await prepare({ handler, useArgosReporter, root });
|
|
452
|
-
const originalViewportSize = checkIsFrame(handler) ? null : getViewportSize(handler);
|
|
453
|
-
const fullPage = options.fullPage !== void 0 ? options.fullPage : screenshotTarget === handler;
|
|
454
|
-
const context = getStabilizationContext2(options);
|
|
455
|
-
const afterAll = await beforeAll(handler, context, { disableHover });
|
|
456
|
-
const stabilizeAndScreenshot = async (name2) => {
|
|
457
|
-
const names = getSnapshotNames(name2, testInfo);
|
|
458
|
-
const { path: screenshotPath, metadata } = await getPathAndMetadata({
|
|
459
|
-
handler,
|
|
460
|
-
extension: PNG_EXTENSION,
|
|
461
|
-
root,
|
|
462
|
-
names,
|
|
463
|
-
testInfo,
|
|
464
|
-
useArgosReporter
|
|
465
|
-
});
|
|
466
|
-
if (options.threshold !== void 0) {
|
|
467
|
-
validateThreshold(options.threshold);
|
|
468
|
-
metadata.transient.threshold = options.threshold;
|
|
469
|
-
}
|
|
470
|
-
await options.beforeScreenshot?.({
|
|
471
|
-
runStabilization: (stabilizationOptions) => waitForReadiness(
|
|
472
|
-
handler,
|
|
473
|
-
getStabilizationContext2({
|
|
474
|
-
...options,
|
|
475
|
-
stabilize: stabilizationOptions ?? options.stabilize
|
|
476
|
-
})
|
|
477
|
-
)
|
|
478
|
-
});
|
|
479
|
-
await waitForReadiness(handler, context);
|
|
480
|
-
const afterEach = await beforeEach(handler, context);
|
|
481
|
-
await waitForReadiness(handler, context);
|
|
482
|
-
const [snapshotPath] = await Promise.all([
|
|
483
|
-
(async () => {
|
|
484
|
-
if (!ariaSnapshot) {
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
const snapshotTarget = checkIsPage(screenshotTarget) ? screenshotTarget.locator("body") : screenshotTarget;
|
|
488
|
-
if (checkIsElementHandle(snapshotTarget)) {
|
|
489
|
-
throw new Error(
|
|
490
|
-
`Element handle is not supported with "ariaSnapshot" option. Use a Locator instead.`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
const snapshotPath2 = screenshotToSnapshotPath(screenshotPath);
|
|
494
|
-
const snapshotMetadata = {
|
|
495
|
-
...metadata,
|
|
496
|
-
transient: {
|
|
497
|
-
parentName: `${names.name}${PNG_EXTENSION}`,
|
|
498
|
-
...metadata.transient.baseName ? {
|
|
499
|
-
baseName: screenshotToSnapshotPath(
|
|
500
|
-
metadata.transient.baseName
|
|
501
|
-
)
|
|
502
|
-
} : {}
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
await Promise.all([
|
|
506
|
-
snapshotTarget.ariaSnapshot().then((snapshot) => {
|
|
507
|
-
return writeFile2(snapshotPath2, snapshot, "utf-8");
|
|
508
|
-
}),
|
|
509
|
-
writeMetadata2(snapshotPath2, snapshotMetadata)
|
|
510
|
-
]);
|
|
511
|
-
return snapshotPath2;
|
|
512
|
-
})(),
|
|
513
|
-
screenshotTarget.screenshot({
|
|
514
|
-
path: screenshotPath,
|
|
515
|
-
type: "png",
|
|
516
|
-
fullPage,
|
|
517
|
-
mask: [handler.locator('[data-visual-test="blackout"]')],
|
|
518
|
-
animations: "disabled",
|
|
519
|
-
...playwrightOptions
|
|
520
|
-
}),
|
|
521
|
-
writeMetadata2(screenshotPath, metadata)
|
|
522
|
-
]);
|
|
523
|
-
const attachments = [
|
|
524
|
-
{
|
|
525
|
-
name: getAttachmentName(names.name, "screenshot"),
|
|
526
|
-
contentType: "image/png",
|
|
527
|
-
path: screenshotPath
|
|
528
|
-
},
|
|
529
|
-
{
|
|
530
|
-
name: getAttachmentName(names.name, "screenshot/metadata"),
|
|
531
|
-
contentType: "application/json",
|
|
532
|
-
path: getMetadataPath2(screenshotPath)
|
|
533
|
-
}
|
|
534
|
-
];
|
|
535
|
-
if (snapshotPath) {
|
|
536
|
-
attachments.push(
|
|
537
|
-
{
|
|
538
|
-
name: getAttachmentName(names.name, "aria"),
|
|
539
|
-
contentType: "application/yaml",
|
|
540
|
-
path: snapshotPath
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
name: getAttachmentName(names.name, "aria/metadata"),
|
|
544
|
-
contentType: "application/json",
|
|
545
|
-
path: getMetadataPath2(snapshotPath)
|
|
546
|
-
}
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
await attachAttachments({ attachments, testInfo, useArgosReporter });
|
|
550
|
-
await afterEach();
|
|
551
|
-
await options.afterScreenshot?.();
|
|
552
|
-
return attachments;
|
|
553
|
-
};
|
|
554
|
-
const allAttachments = [];
|
|
555
|
-
if (viewports) {
|
|
556
|
-
if (checkIsFrame(handler)) {
|
|
557
|
-
throw new Error(`viewports option is not supported with an iframe`);
|
|
558
|
-
}
|
|
559
|
-
for (const viewport of viewports) {
|
|
560
|
-
const viewportSize = resolveViewport(viewport);
|
|
561
|
-
await setViewportSize(handler, viewportSize);
|
|
562
|
-
const attachments = await stabilizeAndScreenshot(
|
|
563
|
-
getScreenshotName(name, { viewportWidth: viewportSize.width })
|
|
564
|
-
);
|
|
565
|
-
allAttachments.push(...attachments);
|
|
566
|
-
}
|
|
567
|
-
if (!originalViewportSize) {
|
|
568
|
-
throw new Error(`Invariant: viewport size must be saved`);
|
|
569
|
-
}
|
|
570
|
-
await setViewportSize(handler, originalViewportSize);
|
|
571
|
-
} else {
|
|
572
|
-
const attachments = await stabilizeAndScreenshot(name);
|
|
573
|
-
allAttachments.push(...attachments);
|
|
574
|
-
}
|
|
575
|
-
await afterAll();
|
|
576
|
-
return allAttachments;
|
|
577
|
-
}
|
|
578
|
-
function getStabilizationContext2(options) {
|
|
579
|
-
const { fullPage, argosCSS, stabilize, viewports } = options;
|
|
580
|
-
return {
|
|
581
|
-
fullPage,
|
|
582
|
-
argosCSS,
|
|
583
|
-
viewports,
|
|
584
|
-
options: stabilize
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// src/csp.ts
|
|
589
|
-
import { getGlobalScript as getGlobalScript2 } from "@argos-ci/browser";
|
|
590
|
-
import { createHash } from "crypto";
|
|
591
|
-
function getCSPScriptHash() {
|
|
592
|
-
const hash = createHash("sha256").update(getGlobalScript2()).digest("base64");
|
|
593
|
-
return `'sha256-${hash}'`;
|
|
594
|
-
}
|
|
595
|
-
export {
|
|
596
|
-
setMetadataConfig as DO_NOT_USE_setMetadataConfig,
|
|
597
|
-
argosAriaSnapshot,
|
|
598
|
-
argosScreenshot,
|
|
599
|
-
getCSPScriptHash
|
|
600
|
-
};
|
package/dist/reporter.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { TestCase, Reporter, FullConfig, TestResult, FullResult } from '@playwright/test/reporter';
|
|
2
|
-
import { UploadParameters } from '@argos-ci/core';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Dynamic build name.
|
|
6
|
-
* We require all values in order to ensure it works correctly in parallel mode.
|
|
7
|
-
*/
|
|
8
|
-
type DynamicBuildName<T extends readonly string[]> = {
|
|
9
|
-
/**
|
|
10
|
-
* The values that the build name can take.
|
|
11
|
-
* It is required to ensure Argos will always upload
|
|
12
|
-
* for each build name in order to work in sharding mode.
|
|
13
|
-
*/
|
|
14
|
-
values: readonly [...T];
|
|
15
|
-
/**
|
|
16
|
-
* Get the build name for a test case.
|
|
17
|
-
* Returns any of the values in `values`.
|
|
18
|
-
*/
|
|
19
|
-
get: (test: TestCase) => T[number];
|
|
20
|
-
};
|
|
21
|
-
type ArgosReporterOptions<T extends string[] = string[]> = Omit<UploadParameters, "files" | "root" | "buildName" | "metadata"> & {
|
|
22
|
-
/**
|
|
23
|
-
* Upload the report to Argos.
|
|
24
|
-
* @default true
|
|
25
|
-
*/
|
|
26
|
-
uploadToArgos?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* If true, the reporter will not fail the test suite when the upload fails.
|
|
29
|
-
* @default false
|
|
30
|
-
*/
|
|
31
|
-
ignoreUploadFailures?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* The name of the build in Argos.
|
|
34
|
-
* Can be a string or a function that receives the test case and returns the build name.
|
|
35
|
-
*/
|
|
36
|
-
buildName?: string | DynamicBuildName<T> | null;
|
|
37
|
-
};
|
|
38
|
-
declare function createArgosReporterOptions<T extends string[]>(options: ArgosReporterOptions<T>): ArgosReporterOptions<T>;
|
|
39
|
-
declare class ArgosReporter implements Reporter {
|
|
40
|
-
rootUploadDirectoryPromise: null | Promise<string>;
|
|
41
|
-
uploadDirectoryPromises: Map<string, Promise<string>>;
|
|
42
|
-
config: ArgosReporterOptions;
|
|
43
|
-
playwrightConfig: FullConfig;
|
|
44
|
-
uploadToArgos: boolean;
|
|
45
|
-
constructor(config: ArgosReporterOptions);
|
|
46
|
-
/**
|
|
47
|
-
* Write a file to the temporary directory.
|
|
48
|
-
*/
|
|
49
|
-
writeFile(path: string, body: Buffer | string): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Copy a file to the temporary directory.
|
|
52
|
-
*/
|
|
53
|
-
copyFile(from: string, to: string): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Copy the trace file if found in the result.
|
|
56
|
-
*/
|
|
57
|
-
copyTraceIfFound(result: TestResult, path: string): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Get the root upload directory (cached).
|
|
60
|
-
*/
|
|
61
|
-
getRootUploadDirectory(): Promise<string>;
|
|
62
|
-
onBegin(config: FullConfig): void;
|
|
63
|
-
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
64
|
-
onEnd(result: FullResult): Promise<{
|
|
65
|
-
status: "failed";
|
|
66
|
-
} | undefined>;
|
|
67
|
-
printsToStdio(): boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { type ArgosReporterOptions, createArgosReporterOptions, ArgosReporter as default };
|