playwright-performance-regression 0.0.0 → 0.1.0-next.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/CHANGELOG.md +286 -0
- package/LICENSE +21 -0
- package/README.md +214 -2
- package/dist/chunk-3CLCMD2Q.js +3411 -0
- package/dist/chunk-4SFI55HF.cjs +319 -0
- package/dist/chunk-B64P2D5A.js +756 -0
- package/dist/chunk-DYLCGMI2.js +63 -0
- package/dist/chunk-GCA73FFP.cjs +1139 -0
- package/dist/chunk-HBGADXLP.js +254 -0
- package/dist/chunk-L5C63HEF.js +1097 -0
- package/dist/chunk-WZVQK7CQ.cjs +758 -0
- package/dist/cli.js +3833 -0
- package/dist/config.cjs +256 -0
- package/dist/config.d.cts +15 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +252 -0
- package/dist/fixture.cjs +16 -0
- package/dist/fixture.d.cts +22 -0
- package/dist/fixture.d.ts +22 -0
- package/dist/fixture.js +4 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +637 -0
- package/dist/index.d.ts +637 -0
- package/dist/index.js +1 -0
- package/dist/perf-api-V4PeHVE0.d.cts +22 -0
- package/dist/perf-api-V4PeHVE0.d.ts +22 -0
- package/dist/reporter.cjs +4787 -0
- package/dist/reporter.d.cts +18 -0
- package/dist/reporter.d.ts +18 -0
- package/dist/reporter.js +1406 -0
- package/dist/test.cjs +14 -0
- package/dist/test.d.cts +7 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +10 -0
- package/package.json +144 -4
- package/schemas/common.schema.json +81 -0
- package/schemas/config.schema.json +875 -0
- package/schemas/outcome.schema.json +44 -0
- package/schemas/run-report.schema.json +505 -0
- package/schemas/samples.schema.json +169 -0
- package/schemas/thresholds.schema.json +138 -0
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,1406 @@
|
|
|
1
|
+
import { getRegistered, notWrappedWarning } from './chunk-DYLCGMI2.js';
|
|
2
|
+
import { relativeSlashPath, directoryOf, resolvePath, writeTextAtomic, writeJsonStable, thresholdsFilePaths, loadThresholds, readHostInfo, readCiInfo, Aggregator, parseSampleBatch, schemaIssueToIssue, addKeyedRequest, colorEnabled, assessRun, evaluate, formatThresholdsDiff, buildOutcome, renderHtmlReport, stringifyStable, deriveThresholds, diffThresholds, formatThresholdsDiffMarkdown, SCHEMA_VERSIONS, hashHex, isFailedTest, resultId, testIdentity, painter, compareText, plural, padEnd, padStart, textWidth, truncateMiddle, roundMs } from './chunk-3CLCMD2Q.js';
|
|
3
|
+
import { version, readModeState, generateRunId, PACKAGE_NAME, SAMPLES_ATTACHMENT_NAME, CLI_COMMAND } from './chunk-HBGADXLP.js';
|
|
4
|
+
import { resolveConfig } from './chunk-L5C63HEF.js';
|
|
5
|
+
|
|
6
|
+
// src/core/normalize/constants.ts
|
|
7
|
+
var NORMALIZE_RULES_VERSION = 1;
|
|
8
|
+
var MAX_KEY_LENGTH = 2e3;
|
|
9
|
+
var CARDINALITY_MIN_KEYS = 10;
|
|
10
|
+
var MAX_KEYS_WARNING = 1e3;
|
|
11
|
+
|
|
12
|
+
// src/core/normalize/explosion.ts
|
|
13
|
+
var EXAMPLES = 3;
|
|
14
|
+
function parseKey(key) {
|
|
15
|
+
const space = key.indexOf(" ");
|
|
16
|
+
if (space <= 0) return null;
|
|
17
|
+
const slash = key.indexOf("/", space + 1);
|
|
18
|
+
if (slash < 0) return null;
|
|
19
|
+
const head = key.slice(0, slash);
|
|
20
|
+
if (head.slice(space + 1).includes("?")) return null;
|
|
21
|
+
const rest = key.slice(slash + 1);
|
|
22
|
+
const mark = rest.indexOf("?");
|
|
23
|
+
const path = mark < 0 ? rest : rest.slice(0, mark);
|
|
24
|
+
return {
|
|
25
|
+
head,
|
|
26
|
+
segments: path === "" ? [] : path.split("/"),
|
|
27
|
+
query: mark < 0 ? "" : rest.slice(mark)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function detectKeyExplosion(endpointKeys) {
|
|
31
|
+
const unique = [...new Set(endpointKeys)].sort();
|
|
32
|
+
const groups = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const key of unique) {
|
|
34
|
+
const parsed = parseKey(key);
|
|
35
|
+
if (parsed === null) continue;
|
|
36
|
+
parsed.segments.forEach((_, i) => {
|
|
37
|
+
const template = parsed.segments.map((s, j) => j === i ? "*" : s).join("/");
|
|
38
|
+
const id = `${parsed.head}/${template}${parsed.query}`;
|
|
39
|
+
const list2 = groups.get(id);
|
|
40
|
+
if (list2 === void 0) groups.set(id, [key]);
|
|
41
|
+
else list2.push(key);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const issues = [];
|
|
45
|
+
for (const template of [...groups.keys()].sort()) {
|
|
46
|
+
const keys = groups.get(template) ?? [];
|
|
47
|
+
if (keys.length < CARDINALITY_MIN_KEYS) continue;
|
|
48
|
+
const examples = keys.slice(0, EXAMPLES).join(", ");
|
|
49
|
+
issues.push({
|
|
50
|
+
code: "NORMALIZE_HIGH_CARDINALITY",
|
|
51
|
+
message: `${keys.length} endpoint keys differ only in one path segment: ${template} (e.g. ${examples}).`,
|
|
52
|
+
hint: "If the segment is test data, replace it with keys.extraIdPatterns or a keys.keyBuilder function."
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (unique.length > MAX_KEYS_WARNING) {
|
|
56
|
+
issues.push({
|
|
57
|
+
code: "NORMALIZE_TOO_MANY_KEYS",
|
|
58
|
+
message: `The run has ${unique.length} endpoint keys, more than ${MAX_KEYS_WARNING}.`,
|
|
59
|
+
hint: "Check the keys for test data and normalize it with keys.extraIdPatterns, keys.dropQueryParams or keys.keyBuilder."
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return issues;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/core/normalize/patterns.ts
|
|
66
|
+
var ID_PATTERNS = {
|
|
67
|
+
number: /^[0-9]+$/,
|
|
68
|
+
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
69
|
+
hex: /^[0-9a-f]{16,}$/i,
|
|
70
|
+
token: /^(?=[^0-9]*[0-9])(?:[A-Za-z0-9~=]{24,}|(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])[A-Za-z0-9_.~=-]{24,})$/,
|
|
71
|
+
mixed: /^(?=[^0-9]*[0-9])(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])[A-Za-z0-9_-]{16,}$/,
|
|
72
|
+
email: /^[^@\s/]+@[^@\s/]+\.[^@\s/]+$/
|
|
73
|
+
};
|
|
74
|
+
function compileIdMatcher(keys) {
|
|
75
|
+
const email = keys.idPatterns.email ? ID_PATTERNS.email : void 0;
|
|
76
|
+
const ids = [];
|
|
77
|
+
for (const name of ["number", "uuid", "hex", "token", "mixed"]) {
|
|
78
|
+
if (keys.idPatterns[name]) {
|
|
79
|
+
const re = ID_PATTERNS[name];
|
|
80
|
+
ids.push((text) => re.test(text));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const pattern of keys.extraIdPatterns) {
|
|
84
|
+
if (typeof pattern === "string") {
|
|
85
|
+
ids.push((text) => text === pattern);
|
|
86
|
+
} else {
|
|
87
|
+
const re = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
88
|
+
ids.push((text) => re.test(text));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return (text) => {
|
|
92
|
+
if (email?.test(text) === true) return ":email";
|
|
93
|
+
return ids.some((test) => test(text)) ? ":id" : null;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/core/normalize/key-builder.ts
|
|
98
|
+
var HINT_EXTEND = "Use keys.extraIdPatterns or keys.keyBuilder for ids in other formats.";
|
|
99
|
+
function parseHttpUrl(text) {
|
|
100
|
+
if (!URL.canParse(text)) return null;
|
|
101
|
+
const url = new URL(text);
|
|
102
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url : null;
|
|
103
|
+
}
|
|
104
|
+
function canonicalOrigin(text) {
|
|
105
|
+
return parseHttpUrl(text)?.origin ?? null;
|
|
106
|
+
}
|
|
107
|
+
function canonicalOrigins(origins) {
|
|
108
|
+
const set = /* @__PURE__ */ new Set();
|
|
109
|
+
for (const origin of origins) {
|
|
110
|
+
const canonical = canonicalOrigin(origin);
|
|
111
|
+
if (canonical !== null) set.add(canonical);
|
|
112
|
+
}
|
|
113
|
+
return [...set].sort();
|
|
114
|
+
}
|
|
115
|
+
var SEGMENT_ESCAPE = /[%/?#& \u0000-\u001f\u007f-\u009f]/g;
|
|
116
|
+
var NAME_ESCAPE = /[%&=# \u0000-\u001f\u007f-\u009f]/g;
|
|
117
|
+
var VALUE_ESCAPE = /[%&=#, \u0000-\u001f\u007f-\u009f]/g;
|
|
118
|
+
var escape = (text, chars) => text.replace(chars, encodeURIComponent);
|
|
119
|
+
function normalizePath(pathname, matchId) {
|
|
120
|
+
const segments2 = [];
|
|
121
|
+
for (const raw of pathname.split("/")) {
|
|
122
|
+
const segment = raw.split(";", 1)[0] ?? "";
|
|
123
|
+
if (segment === "") continue;
|
|
124
|
+
let decoded;
|
|
125
|
+
try {
|
|
126
|
+
decoded = decodeURIComponent(segment);
|
|
127
|
+
} catch {
|
|
128
|
+
segments2.push(segment);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
segments2.push(matchId(decoded) ?? escape(decoded, SEGMENT_ESCAPE));
|
|
132
|
+
}
|
|
133
|
+
return `/${segments2.join("/")}`;
|
|
134
|
+
}
|
|
135
|
+
function normalizeQuery(params, keys, matchId) {
|
|
136
|
+
const drop = new Set(keys.dropQueryParams);
|
|
137
|
+
const keep = new Set(keys.keepQueryValues);
|
|
138
|
+
const names = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const [rawName, value] of params) {
|
|
140
|
+
const name = rawName.replace(/\[[0-9]+\]/g, "[]");
|
|
141
|
+
if (name === "" || drop.has(name) || matchId(name) !== null) continue;
|
|
142
|
+
const encoded = escape(name, NAME_ESCAPE);
|
|
143
|
+
if (!keep.has(name)) {
|
|
144
|
+
if (!names.has(encoded)) names.set(encoded, null);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const values = names.get(encoded) ?? /* @__PURE__ */ new Set();
|
|
148
|
+
values.add(matchId(value) ?? escape(value, VALUE_ESCAPE));
|
|
149
|
+
names.set(encoded, values);
|
|
150
|
+
}
|
|
151
|
+
return [...names.keys()].sort().map((name) => {
|
|
152
|
+
const values = names.get(name);
|
|
153
|
+
return values ? `${name}=${[...values].sort().join(",")}` : name;
|
|
154
|
+
}).join("&");
|
|
155
|
+
}
|
|
156
|
+
function truncateKey(key) {
|
|
157
|
+
if (key.length <= MAX_KEY_LENGTH) return key;
|
|
158
|
+
const suffix = `…~${hashHex(key)}`;
|
|
159
|
+
let cut = MAX_KEY_LENGTH - suffix.length;
|
|
160
|
+
const before = key.charCodeAt(cut - 1);
|
|
161
|
+
const after = key.charCodeAt(cut);
|
|
162
|
+
if (before >= 55296 && before <= 56319 && after >= 56320 && after <= 57343) cut -= 1;
|
|
163
|
+
return key.slice(0, cut) + suffix;
|
|
164
|
+
}
|
|
165
|
+
function createKeyBuilder(cfg, ctx) {
|
|
166
|
+
const matchId = compileIdMatcher(cfg);
|
|
167
|
+
const labels = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const origin of canonicalOrigins(ctx.baseOrigins)) labels.set(origin, "");
|
|
169
|
+
for (const [origin, label] of Object.entries(cfg.origins)) {
|
|
170
|
+
const canonical = canonicalOrigin(origin);
|
|
171
|
+
if (canonical !== null) labels.set(canonical, label);
|
|
172
|
+
}
|
|
173
|
+
const keyBuilder = cfg.keyBuilder;
|
|
174
|
+
return (sample) => {
|
|
175
|
+
const method = sample.method.toUpperCase();
|
|
176
|
+
const url = parseHttpUrl(sample.url);
|
|
177
|
+
const issues = [];
|
|
178
|
+
let key;
|
|
179
|
+
if (keyBuilder !== void 0) {
|
|
180
|
+
let custom;
|
|
181
|
+
try {
|
|
182
|
+
custom = keyBuilder({ method, url: sample.url, resourceType: sample.resourceType });
|
|
183
|
+
} catch (error) {
|
|
184
|
+
issues.push({
|
|
185
|
+
code: "NORMALIZE_KEY_BUILDER_THREW",
|
|
186
|
+
message: `keys.keyBuilder threw an exception: ${error instanceof Error ? error.message : String(error)}. The built-in normalization was used instead.`,
|
|
187
|
+
hint: "Fix the keyBuilder function; it must not throw."
|
|
188
|
+
});
|
|
189
|
+
custom = void 0;
|
|
190
|
+
}
|
|
191
|
+
if (typeof custom === "string" && custom.trim() !== "") {
|
|
192
|
+
key = custom;
|
|
193
|
+
} else if (custom !== void 0) {
|
|
194
|
+
issues.push({
|
|
195
|
+
code: "NORMALIZE_KEY_BUILDER_INVALID",
|
|
196
|
+
message: "keys.keyBuilder returned a value that is neither a non-empty string nor undefined. The built-in normalization was used instead.",
|
|
197
|
+
hint: "Return the whole key as a non-empty string, or undefined for the built-in normalization."
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (key === void 0) {
|
|
202
|
+
if (url === null) {
|
|
203
|
+
issues.push({
|
|
204
|
+
code: "NORMALIZE_UNSUPPORTED_URL",
|
|
205
|
+
message: "A request URL could not be parsed or does not use http/https; the sample was skipped."
|
|
206
|
+
});
|
|
207
|
+
return { ok: false, issues };
|
|
208
|
+
}
|
|
209
|
+
const label = labels.get(url.origin) ?? url.host;
|
|
210
|
+
const query = cfg.query === "names" ? normalizeQuery(url.searchParams, cfg, matchId) : "";
|
|
211
|
+
key = `${method} ${label}${normalizePath(url.pathname, matchId)}${query === "" ? "" : `?${query}`}`;
|
|
212
|
+
}
|
|
213
|
+
const truncated = truncateKey(key);
|
|
214
|
+
if (truncated !== key) {
|
|
215
|
+
issues.push({
|
|
216
|
+
code: "NORMALIZE_KEY_TRUNCATED",
|
|
217
|
+
message: `An endpoint key longer than ${MAX_KEY_LENGTH} characters was truncated and suffixed with its hash.`,
|
|
218
|
+
hint: HINT_EXTEND
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
ok: true,
|
|
223
|
+
key: truncated,
|
|
224
|
+
origin: url?.origin ?? null,
|
|
225
|
+
label: url === null ? null : labels.get(url.origin) ?? url.host,
|
|
226
|
+
issues
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/core/normalize/fingerprint.ts
|
|
232
|
+
function measuredBaseOrigins(projects) {
|
|
233
|
+
const origins = [];
|
|
234
|
+
for (const project of projects) {
|
|
235
|
+
if (project.role !== "measured" || project.baseURL == null) continue;
|
|
236
|
+
const origin = canonicalOrigin(project.baseURL);
|
|
237
|
+
if (origin !== null) origins.push(origin);
|
|
238
|
+
}
|
|
239
|
+
return canonicalOrigins(origins);
|
|
240
|
+
}
|
|
241
|
+
function normalizationFingerprint(cfg, ctx) {
|
|
242
|
+
const { keyBuilder, extraIdPatterns, ...rest } = cfg;
|
|
243
|
+
const keys = {
|
|
244
|
+
...rest,
|
|
245
|
+
extraIdPatterns: extraIdPatterns.map(
|
|
246
|
+
(p) => typeof p === "string" ? p : { regex: p.source, flags: p.flags }
|
|
247
|
+
),
|
|
248
|
+
keyBuilder: keyBuilder === void 0 ? void 0 : "[function]"
|
|
249
|
+
};
|
|
250
|
+
return hashHex(
|
|
251
|
+
stringifyStable({
|
|
252
|
+
rulesVersion: NORMALIZE_RULES_VERSION,
|
|
253
|
+
keys,
|
|
254
|
+
baseOrigins: canonicalOrigins(ctx.baseOrigins)
|
|
255
|
+
})
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/core/report/issues.ts
|
|
260
|
+
function collapseIssues(issues) {
|
|
261
|
+
const result = [];
|
|
262
|
+
const index = /* @__PURE__ */ new Map();
|
|
263
|
+
for (const issue of issues) {
|
|
264
|
+
const id = `${issue.code}\0${issue.message}`;
|
|
265
|
+
const at = index.get(id);
|
|
266
|
+
const first = at === void 0 ? void 0 : result[at];
|
|
267
|
+
if (first === void 0) {
|
|
268
|
+
index.set(id, result.length);
|
|
269
|
+
result.push({ ...issue });
|
|
270
|
+
} else {
|
|
271
|
+
first.count = (first.count ?? 1) + (issue.count ?? 1);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/core/report/build-run-report.ts
|
|
278
|
+
function compareText2(a, b) {
|
|
279
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
280
|
+
}
|
|
281
|
+
function compareSlowest(a, b) {
|
|
282
|
+
return b.duration - a.duration || compareText2(a.test.file, b.test.file) || a.test.line - b.test.line || a.test.repeatEachIndex - b.test.repeatEachIndex;
|
|
283
|
+
}
|
|
284
|
+
function buildAggregate(stats, evaluation, rawUrls) {
|
|
285
|
+
return {
|
|
286
|
+
...stats,
|
|
287
|
+
statuses: { ...stats.statuses },
|
|
288
|
+
timeSources: { ...stats.timeSources },
|
|
289
|
+
stats: stats.stats === null ? null : {
|
|
290
|
+
min: roundMs(stats.stats.min),
|
|
291
|
+
avg: roundMs(stats.stats.avg),
|
|
292
|
+
max: roundMs(stats.stats.max),
|
|
293
|
+
percentiles: Object.fromEntries(
|
|
294
|
+
Object.entries(stats.stats.percentiles).map(([name, value]) => [
|
|
295
|
+
name,
|
|
296
|
+
roundMs(value)
|
|
297
|
+
])
|
|
298
|
+
)
|
|
299
|
+
},
|
|
300
|
+
ttfb: stats.ttfb === null ? null : { p50: roundMs(stats.ttfb.p50), p95: roundMs(stats.ttfb.p95) },
|
|
301
|
+
// Raw URLs only with report.rawUrls (D-11, 02-REQ-16).
|
|
302
|
+
slowest: stats.slowest.map(({ url, ...sample }) => ({
|
|
303
|
+
...sample,
|
|
304
|
+
test: { ...sample.test },
|
|
305
|
+
duration: roundMs(sample.duration),
|
|
306
|
+
...rawUrls && url !== void 0 ? { url } : {}
|
|
307
|
+
})).sort(compareSlowest),
|
|
308
|
+
topTests: stats.topTests.map((t) => ({ ...t })).sort(
|
|
309
|
+
(a, b) => b.sampleCount - a.sampleCount || compareText2(a.file, b.file) || a.line - b.line || compareText2(a.title, b.title) || compareText2(a.project, b.project)
|
|
310
|
+
),
|
|
311
|
+
samples: {
|
|
312
|
+
durations: stats.samples.durations.map(roundMs).sort((a, b) => a - b),
|
|
313
|
+
sampled: stats.samples.sampled
|
|
314
|
+
},
|
|
315
|
+
evaluation: structuredClone(evaluation)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function buildAggregates(kind, aggregates, perKey, rawUrls) {
|
|
319
|
+
for (const key of Object.keys(perKey)) {
|
|
320
|
+
if (!Object.hasOwn(aggregates, key)) {
|
|
321
|
+
throw new Error(`buildRunReport: evaluation for unknown ${kind} key "${key}"`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const result = {};
|
|
325
|
+
for (const key of Object.keys(aggregates).sort()) {
|
|
326
|
+
const stats = aggregates[key];
|
|
327
|
+
const evaluation = Object.hasOwn(perKey, key) ? perKey[key] : void 0;
|
|
328
|
+
if (stats === void 0 || evaluation === void 0) {
|
|
329
|
+
throw new Error(`buildRunReport: no evaluation for ${kind} key "${key}"`);
|
|
330
|
+
}
|
|
331
|
+
result[key] = buildAggregate(stats, evaluation, rawUrls);
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
function buildRunReport(input) {
|
|
336
|
+
const { meta, aggregates, evaluation } = input;
|
|
337
|
+
const rawUrls = input.config.report?.rawUrls === true;
|
|
338
|
+
const kindOrder = { api: 0, custom: 1 };
|
|
339
|
+
return {
|
|
340
|
+
schemaVersion: SCHEMA_VERSIONS.runReport,
|
|
341
|
+
tool: { ...meta.tool },
|
|
342
|
+
runId: meta.runId,
|
|
343
|
+
mode: meta.mode,
|
|
344
|
+
startedAt: meta.startedAt,
|
|
345
|
+
finishedAt: meta.finishedAt,
|
|
346
|
+
env: meta.env,
|
|
347
|
+
configDir: meta.configDir,
|
|
348
|
+
config: structuredClone(input.config),
|
|
349
|
+
normalization: input.normalization,
|
|
350
|
+
ci: meta.ci === null ? null : { ...meta.ci },
|
|
351
|
+
host: { ...meta.host },
|
|
352
|
+
playwright: { ...meta.playwright },
|
|
353
|
+
runConditions: structuredClone(input.runConditions),
|
|
354
|
+
tests: { ...input.tests },
|
|
355
|
+
evaluation: {
|
|
356
|
+
status: evaluation.status,
|
|
357
|
+
gateEnabled: evaluation.gateEnabled,
|
|
358
|
+
counts: structuredClone(evaluation.counts)
|
|
359
|
+
},
|
|
360
|
+
thresholdFiles: evaluation.thresholdFiles.map((file) => ({
|
|
361
|
+
...file,
|
|
362
|
+
generated: file.generated === null ? null : structuredClone(file.generated),
|
|
363
|
+
unseenKeys: [...file.unseenKeys].sort(compareText2)
|
|
364
|
+
})).sort((a, b) => kindOrder[a.kind] - kindOrder[b.kind]),
|
|
365
|
+
warnings: collapseIssues(input.warnings),
|
|
366
|
+
toolErrors: collapseIssues(input.toolErrors),
|
|
367
|
+
origins: aggregates.origins.map((o) => ({ ...o })).sort((a, b) => compareText2(a.origin, b.origin)),
|
|
368
|
+
endpoints: buildAggregates("api", aggregates.endpoints, evaluation.perKey.api, rawUrls),
|
|
369
|
+
custom: buildAggregates("custom", aggregates.custom, evaluation.perKey.custom, rawUrls)
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/console/summary.ts
|
|
374
|
+
var MAX_WARNINGS = 10;
|
|
375
|
+
var MAX_VIOLATION_ROWS = 20;
|
|
376
|
+
var MAX_SLOWEST_LINES = 5;
|
|
377
|
+
var MIN_KEY_WIDTH = 30;
|
|
378
|
+
var KINDS = ["api", "custom"];
|
|
379
|
+
var RULE_ORDER = [
|
|
380
|
+
"median",
|
|
381
|
+
"percentile",
|
|
382
|
+
"p99",
|
|
383
|
+
"apdex",
|
|
384
|
+
"wilson",
|
|
385
|
+
"errors"
|
|
386
|
+
];
|
|
387
|
+
var TIME_RULES = /* @__PURE__ */ new Set([
|
|
388
|
+
"median",
|
|
389
|
+
"percentile",
|
|
390
|
+
"p99"
|
|
391
|
+
]);
|
|
392
|
+
function exceedance(check) {
|
|
393
|
+
if (check.rule === "apdex") return check.actual === 0 ? Infinity : check.limit / check.actual;
|
|
394
|
+
return check.limit === 0 ? Infinity : check.actual / check.limit;
|
|
395
|
+
}
|
|
396
|
+
function overText(check) {
|
|
397
|
+
const r = exceedance(check);
|
|
398
|
+
if (!Number.isFinite(r)) return ">999%";
|
|
399
|
+
const over = Math.round((r - 1) * 100);
|
|
400
|
+
return over > 999 ? ">999%" : `+${over}%`;
|
|
401
|
+
}
|
|
402
|
+
function violations(report) {
|
|
403
|
+
const list2 = [];
|
|
404
|
+
for (const kind of KINDS) {
|
|
405
|
+
const aggregates = kind === "api" ? report.endpoints : report.custom;
|
|
406
|
+
for (const [key, aggregate] of Object.entries(aggregates)) {
|
|
407
|
+
for (const check of aggregate.evaluation.checks) {
|
|
408
|
+
if (!check.passed) {
|
|
409
|
+
list2.push({ kind, key, check, evaluation: aggregate.evaluation, r: exceedance(check) });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return list2.sort(
|
|
415
|
+
(a, b) => Number(b.check.blocking) - Number(a.check.blocking) || (a.r === b.r ? 0 : b.r > a.r ? 1 : -1) || KINDS.indexOf(a.kind) - KINDS.indexOf(b.kind) || compareText(a.key, b.key) || RULE_ORDER.indexOf(a.check.rule) - RULE_ORDER.indexOf(b.check.rule)
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
function isMuted(evaluation) {
|
|
419
|
+
return evaluation.muted !== null && !evaluation.muted.expired;
|
|
420
|
+
}
|
|
421
|
+
function header(report) {
|
|
422
|
+
const t = report.tests;
|
|
423
|
+
const executions = t.expected + t.unexpected + t.flaky;
|
|
424
|
+
const details = [`${t.expected} passed`, `${t.unexpected} failed`];
|
|
425
|
+
if (t.flaky > 0) details.push(`${t.flaky} flaky`);
|
|
426
|
+
if (t.skipped > 0) details.push(`${t.skipped} skipped`);
|
|
427
|
+
const parts = [report.tool.name, `mode: ${report.mode}`];
|
|
428
|
+
if (report.env !== null) parts.push(`env: ${report.env}`);
|
|
429
|
+
parts.push(`${plural(executions, "test")} (${details.join(", ")})`);
|
|
430
|
+
const ci = report.ci;
|
|
431
|
+
if (ci !== null && (ci.branch !== null || ci.commit !== null)) {
|
|
432
|
+
const commit = ci.commit === null ? "" : `@${ci.commit.slice(0, 7)}`;
|
|
433
|
+
parts.push(`${ci.branch ?? ""}${commit}`);
|
|
434
|
+
}
|
|
435
|
+
return parts.join(" · ");
|
|
436
|
+
}
|
|
437
|
+
function issueLines(title, issues, limit, marker, more) {
|
|
438
|
+
if (issues.length === 0) return [];
|
|
439
|
+
const lines = [title];
|
|
440
|
+
for (const issue of issues.slice(0, limit)) {
|
|
441
|
+
const times = issue.count !== void 0 && issue.count > 1 ? ` (×${issue.count})` : "";
|
|
442
|
+
lines.push(` ${marker} ${issue.code}: ${issue.message}${times}`);
|
|
443
|
+
if (issue.hint !== void 0) lines.push(` Hint: ${issue.hint}`);
|
|
444
|
+
}
|
|
445
|
+
if (issues.length > limit) {
|
|
446
|
+
lines.push(` … and ${issues.length - limit} more ${more} (see report)`);
|
|
447
|
+
}
|
|
448
|
+
return [...lines, ""];
|
|
449
|
+
}
|
|
450
|
+
var LABEL_WIDTH = "Endpoints: ".length;
|
|
451
|
+
function counterLines(report) {
|
|
452
|
+
const counts = report.evaluation.counts;
|
|
453
|
+
const shown = KINDS.filter(
|
|
454
|
+
(kind) => kind === "api" || counts.custom.keys > 0 || counts.custom.unseenThresholdEntries > 0
|
|
455
|
+
);
|
|
456
|
+
const columns = [
|
|
457
|
+
{ label: "keys", value: (k) => counts[k].keys },
|
|
458
|
+
{ label: "from file", value: (k) => counts[k].fromFile },
|
|
459
|
+
{ label: "default", value: (k) => counts[k].fromDefaults },
|
|
460
|
+
{ label: "too few samples", value: (k) => counts[k].tooFewSamples },
|
|
461
|
+
{ label: "median only", value: (k) => counts[k].medianOnly },
|
|
462
|
+
{ label: "unseen entries", value: (k) => counts[k].unseenThresholdEntries, optional: true },
|
|
463
|
+
{
|
|
464
|
+
label: "not evaluated",
|
|
465
|
+
value: (k) => counts[k].notEvaluated - counts[k].tooFewSamples,
|
|
466
|
+
optional: true
|
|
467
|
+
}
|
|
468
|
+
];
|
|
469
|
+
const used = columns.filter((c) => !c.optional || shown.some((k) => c.value(k) > 0));
|
|
470
|
+
const widths = used.map((c) => Math.max(...shown.map((k) => String(c.value(k)).length)));
|
|
471
|
+
return shown.map((kind) => {
|
|
472
|
+
const label = padEnd(kind === "api" ? "Endpoints:" : "Custom:", LABEL_WIDTH);
|
|
473
|
+
const cells = used.flatMap((c, i) => {
|
|
474
|
+
const value = c.value(kind);
|
|
475
|
+
if (c.optional && value === 0) return [];
|
|
476
|
+
const label2 = c.label === "keys" && value === 1 ? "key" : c.label;
|
|
477
|
+
return [`${padStart(String(value), widths[i] ?? 0)} ${label2}`];
|
|
478
|
+
});
|
|
479
|
+
return label + cells.join(" · ");
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
function mutedLines(report) {
|
|
483
|
+
const lines = [];
|
|
484
|
+
for (const kind of KINDS) {
|
|
485
|
+
const aggregates = kind === "api" ? report.endpoints : report.custom;
|
|
486
|
+
for (const key of Object.keys(aggregates).sort(compareText)) {
|
|
487
|
+
const muted = aggregates[key]?.evaluation.muted;
|
|
488
|
+
if (muted === void 0 || muted === null || muted.expired) continue;
|
|
489
|
+
const label = lines.length === 0 ? "Muted:" : "";
|
|
490
|
+
lines.push(`${padEnd(label, LABEL_WIDTH)}${key} until ${muted.until} — "${muted.note}"`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return lines;
|
|
494
|
+
}
|
|
495
|
+
function formatTime(ms) {
|
|
496
|
+
return `${Math.round(ms)} ms`;
|
|
497
|
+
}
|
|
498
|
+
function formatActual(check) {
|
|
499
|
+
if (TIME_RULES.has(check.rule)) return formatTime(check.actual);
|
|
500
|
+
const observed = check.observed === null ? "" : ` (${check.observed.toFixed(3)})`;
|
|
501
|
+
return `${check.actual.toFixed(3)}${observed}`;
|
|
502
|
+
}
|
|
503
|
+
function formatLimit(check) {
|
|
504
|
+
return TIME_RULES.has(check.rule) ? formatTime(check.limit) : check.limit.toFixed(3);
|
|
505
|
+
}
|
|
506
|
+
function tableLines(report, list2, width, paint) {
|
|
507
|
+
const level = report.config.checks?.time?.percentile?.level ?? "percentile";
|
|
508
|
+
const shown = list2.slice(0, MAX_VIOLATION_ROWS);
|
|
509
|
+
const rows = shown.map((v) => ({
|
|
510
|
+
marker: v.check.blocking ? "✖" : "!",
|
|
511
|
+
kind: v.kind,
|
|
512
|
+
key: v.key,
|
|
513
|
+
rule: v.check.rule === "percentile" ? level : v.check.rule,
|
|
514
|
+
actual: formatActual(v.check),
|
|
515
|
+
limit: formatLimit(v.check),
|
|
516
|
+
over: overText(v.check),
|
|
517
|
+
n: String(v.check.n),
|
|
518
|
+
src: v.evaluation.thresholdSource,
|
|
519
|
+
flag: [v.check.hardLimitExceeded ? "HARD" : "", isMuted(v.evaluation) ? "MUTED" : ""].filter((f) => f !== "").join(" ")
|
|
520
|
+
}));
|
|
521
|
+
const head = {
|
|
522
|
+
marker: " ",
|
|
523
|
+
kind: "kind",
|
|
524
|
+
key: "key",
|
|
525
|
+
rule: "rule",
|
|
526
|
+
actual: "actual",
|
|
527
|
+
limit: "limit",
|
|
528
|
+
over: "over",
|
|
529
|
+
n: "n",
|
|
530
|
+
src: "src",
|
|
531
|
+
flag: "flag"
|
|
532
|
+
};
|
|
533
|
+
const all = [head, ...rows];
|
|
534
|
+
const w = (field) => Math.max(...all.map((r) => textWidth(r[field])));
|
|
535
|
+
const widths = {
|
|
536
|
+
kind: w("kind"),
|
|
537
|
+
rule: w("rule"),
|
|
538
|
+
actual: w("actual"),
|
|
539
|
+
limit: w("limit"),
|
|
540
|
+
over: w("over"),
|
|
541
|
+
n: w("n"),
|
|
542
|
+
src: w("src"),
|
|
543
|
+
flag: w("flag")
|
|
544
|
+
};
|
|
545
|
+
const fixed = 4 + widths.kind + widths.rule + widths.actual + widths.limit + widths.over + widths.n + widths.src + widths.flag + 2 * 8;
|
|
546
|
+
const keyWidth = Math.max(MIN_KEY_WIDTH, Math.min(width - fixed, w("key")));
|
|
547
|
+
const line = (r, isHead) => {
|
|
548
|
+
const marker = isHead || r.marker === " " ? r.marker : paint(r.marker, r.marker === "✖" ? "red" : "yellow");
|
|
549
|
+
const flag = r.flag.includes("HARD") && !isHead ? paint(r.flag, "red") : r.flag;
|
|
550
|
+
return [
|
|
551
|
+
` ${marker} ${padEnd(r.kind, widths.kind)}`,
|
|
552
|
+
padEnd(truncateMiddle(r.key, keyWidth), keyWidth),
|
|
553
|
+
padEnd(r.rule, widths.rule),
|
|
554
|
+
padStart(r.actual, widths.actual),
|
|
555
|
+
padStart(r.limit, widths.limit),
|
|
556
|
+
padStart(r.over, widths.over),
|
|
557
|
+
padStart(r.n, widths.n),
|
|
558
|
+
padEnd(r.src, widths.src),
|
|
559
|
+
flag
|
|
560
|
+
].join(" ").trimEnd();
|
|
561
|
+
};
|
|
562
|
+
const lines = [line(head, true), ...rows.map((r) => line(r, false))];
|
|
563
|
+
if (list2.length > shown.length) {
|
|
564
|
+
lines.push(` … and ${list2.length - shown.length} more violations (see report)`);
|
|
565
|
+
}
|
|
566
|
+
return lines;
|
|
567
|
+
}
|
|
568
|
+
function slowestLines(report, list2) {
|
|
569
|
+
const seen = /* @__PURE__ */ new Set();
|
|
570
|
+
const lines = [];
|
|
571
|
+
for (const v of list2) {
|
|
572
|
+
if (!v.check.blocking || lines.length >= MAX_SLOWEST_LINES) continue;
|
|
573
|
+
const id = `${v.kind}\0${v.key}`;
|
|
574
|
+
if (seen.has(id)) continue;
|
|
575
|
+
seen.add(id);
|
|
576
|
+
const aggregate = (v.kind === "api" ? report.endpoints : report.custom)[v.key];
|
|
577
|
+
const slowest = aggregate?.slowest[0];
|
|
578
|
+
if (slowest === void 0) continue;
|
|
579
|
+
const t = slowest.test;
|
|
580
|
+
lines.push(
|
|
581
|
+
` slowest: ${v.key} — ${formatTime(slowest.duration)} in "${t.title}" (${t.file}:${t.line})`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
return lines;
|
|
585
|
+
}
|
|
586
|
+
function resultLine(report, paint) {
|
|
587
|
+
const counts = report.evaluation.counts;
|
|
588
|
+
const sum = (field) => counts.api[field] + counts.custom[field];
|
|
589
|
+
const gate = report.config.gate;
|
|
590
|
+
const policy = gate?.warnOnly === true ? " (gate.warnOnly)" : gate?.tolerance === void 0 ? "" : ` (tolerance: ${gate.tolerance})`;
|
|
591
|
+
let word;
|
|
592
|
+
let style;
|
|
593
|
+
let reason;
|
|
594
|
+
const status = report.evaluation.status;
|
|
595
|
+
if (report.toolErrors.length > 0 || status === "error") {
|
|
596
|
+
word = "ERROR";
|
|
597
|
+
style = "red";
|
|
598
|
+
reason = `${plural(report.toolErrors.length, "tool error")}; the result is not trustworthy`;
|
|
599
|
+
} else if (status === "failed") {
|
|
600
|
+
word = "FAILED";
|
|
601
|
+
style = "red";
|
|
602
|
+
reason = `${plural(sum("blockingViolations"), "blocking violation")}${policy}`;
|
|
603
|
+
} else if (status === "warned") {
|
|
604
|
+
word = "PASSED WITH WARNINGS";
|
|
605
|
+
style = "yellow";
|
|
606
|
+
reason = `${plural(sum("violations"), "key")} with violations, none blocking${policy}`;
|
|
607
|
+
} else {
|
|
608
|
+
word = "PASSED";
|
|
609
|
+
style = "green";
|
|
610
|
+
reason = `no violations in ${plural(sum("keys") - sum("notEvaluated"), "evaluated key")}`;
|
|
611
|
+
}
|
|
612
|
+
const informational = report.mode === "thresholds" ? " (informational, gate disabled)" : "";
|
|
613
|
+
return `${paint(word, style)}: ${reason}${informational}`;
|
|
614
|
+
}
|
|
615
|
+
function toSlash(path) {
|
|
616
|
+
return path.replace(/\\/gu, "/");
|
|
617
|
+
}
|
|
618
|
+
function rootOf(path) {
|
|
619
|
+
const drive = /^[A-Za-z]:\//u.exec(path);
|
|
620
|
+
if (drive !== null) return drive[0];
|
|
621
|
+
return path.startsWith("/") ? "/" : "";
|
|
622
|
+
}
|
|
623
|
+
function segments(path) {
|
|
624
|
+
const result = [];
|
|
625
|
+
for (const part of path.slice(rootOf(path).length).split("/")) {
|
|
626
|
+
if (part === "" || part === ".") continue;
|
|
627
|
+
if (part === ".." && result.length > 0 && result[result.length - 1] !== "..") result.pop();
|
|
628
|
+
else result.push(part);
|
|
629
|
+
}
|
|
630
|
+
return result;
|
|
631
|
+
}
|
|
632
|
+
function relativePath(from, to) {
|
|
633
|
+
const a = toSlash(from);
|
|
634
|
+
const b = toSlash(to);
|
|
635
|
+
if (rootOf(a) === "" || rootOf(a) !== rootOf(b)) return b;
|
|
636
|
+
const x = segments(a);
|
|
637
|
+
const y = segments(b);
|
|
638
|
+
let common = 0;
|
|
639
|
+
while (common < x.length && common < y.length && x[common] === y[common]) common += 1;
|
|
640
|
+
const parts = [...x.slice(common).map(() => ".."), ...y.slice(common)];
|
|
641
|
+
return parts.length === 0 ? "." : parts.join("/");
|
|
642
|
+
}
|
|
643
|
+
function resolvePath2(base, path) {
|
|
644
|
+
const p = toSlash(path);
|
|
645
|
+
if (rootOf(p) !== "") return rootOf(p) + segments(p).join("/");
|
|
646
|
+
const b = toSlash(base);
|
|
647
|
+
return rootOf(b) + segments(`${b}/${p}`).join("/");
|
|
648
|
+
}
|
|
649
|
+
function reportLine(report, cwd, html) {
|
|
650
|
+
const options = report.config.report;
|
|
651
|
+
if (options?.dir === void 0) return [];
|
|
652
|
+
const dir = resolvePath2(report.configDir, options.dir);
|
|
653
|
+
const withHtml = html ?? options.html !== false;
|
|
654
|
+
const files = [...withHtml ? ["report.html"] : [], "report.json"];
|
|
655
|
+
return [`Report: ${files.map((f) => relativePath(cwd, `${dir}/${f}`)).join(" · ")}`];
|
|
656
|
+
}
|
|
657
|
+
function formatSummary(report, opts) {
|
|
658
|
+
const paint = painter(opts.color);
|
|
659
|
+
const list2 = violations(report);
|
|
660
|
+
const lines = [header(report), ""];
|
|
661
|
+
lines.push(...issueLines("Errors:", report.toolErrors, Infinity, paint("✖", "red"), "errors"));
|
|
662
|
+
lines.push(
|
|
663
|
+
...issueLines("Warnings:", report.warnings, MAX_WARNINGS, paint("!", "yellow"), "warnings")
|
|
664
|
+
);
|
|
665
|
+
lines.push(...counterLines(report), ...mutedLines(report), "");
|
|
666
|
+
if (list2.length > 0) {
|
|
667
|
+
lines.push(...tableLines(report, list2, opts.width, paint));
|
|
668
|
+
const slowest = slowestLines(report, list2);
|
|
669
|
+
if (slowest.length > 0) lines.push("", ...slowest);
|
|
670
|
+
lines.push("");
|
|
671
|
+
}
|
|
672
|
+
lines.push(resultLine(report, paint), ...reportLine(report, opts.cwd, opts.html));
|
|
673
|
+
return `${lines.join("\n")}
|
|
674
|
+
`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/reporter/begin.ts
|
|
678
|
+
function browserOf(project) {
|
|
679
|
+
return project.use.browserName ?? project.use.defaultBrowserType ?? "chromium";
|
|
680
|
+
}
|
|
681
|
+
function roleOf(project, all, measured) {
|
|
682
|
+
if (measured.has(project.name)) return "measured";
|
|
683
|
+
return all.some((p) => p.teardown === project.name) ? "teardown" : "dependency";
|
|
684
|
+
}
|
|
685
|
+
function readRunConditions(config, measured, overridden) {
|
|
686
|
+
return {
|
|
687
|
+
workers: config.workers,
|
|
688
|
+
projects: config.projects.map((project) => ({
|
|
689
|
+
name: project.name,
|
|
690
|
+
role: roleOf(project, config.projects, measured),
|
|
691
|
+
browserName: browserOf(project),
|
|
692
|
+
repeatEach: project.repeatEach,
|
|
693
|
+
retries: project.retries
|
|
694
|
+
})),
|
|
695
|
+
overriddenSettings: [...overridden]
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
function runConditionsWarning(conditions, repeat) {
|
|
699
|
+
const diffs = [];
|
|
700
|
+
if (conditions.workers !== 1) diffs.push(`workers ${conditions.workers} (expected 1)`);
|
|
701
|
+
for (const project of conditions.projects) {
|
|
702
|
+
const name = `project ${JSON.stringify(project.name)}`;
|
|
703
|
+
const expected = project.role === "measured" ? repeat : 1;
|
|
704
|
+
if (project.repeatEach !== expected) {
|
|
705
|
+
diffs.push(`${name} repeatEach ${project.repeatEach} (expected ${expected})`);
|
|
706
|
+
}
|
|
707
|
+
if (project.retries !== 0) diffs.push(`${name} retries ${project.retries} (expected 0)`);
|
|
708
|
+
}
|
|
709
|
+
if (diffs.length === 0) return null;
|
|
710
|
+
return {
|
|
711
|
+
code: "RUN_CONDITIONS_CHANGED",
|
|
712
|
+
message: `The run conditions differ from those set for perf mode: ${diffs.join("; ")}.`,
|
|
713
|
+
hint: "Do not pass --workers, --retries or --repeat-each to a perf-mode run; set repetitions with run.repeat or --repeat."
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
function duplicateBaseUrlLabels(conditions, config, keys) {
|
|
717
|
+
const baseOrigins = measuredBaseOrigins(
|
|
718
|
+
conditions.projects.map((p, i) => ({ role: p.role, baseURL: config.projects[i]?.use.baseURL }))
|
|
719
|
+
);
|
|
720
|
+
const labelled = /* @__PURE__ */ new Map();
|
|
721
|
+
for (const [origin, label] of Object.entries(keys.origins)) {
|
|
722
|
+
const canonical = canonicalOrigin(origin);
|
|
723
|
+
if (canonical !== null) labelled.set(canonical, label);
|
|
724
|
+
}
|
|
725
|
+
const unlabelled = baseOrigins.filter((origin) => !labelled.has(origin));
|
|
726
|
+
if (unlabelled.length === 0) return null;
|
|
727
|
+
const empty = [
|
|
728
|
+
...unlabelled,
|
|
729
|
+
...[...labelled].filter(([, label]) => label === "").map(([origin]) => origin)
|
|
730
|
+
].sort();
|
|
731
|
+
if (empty.length < 2) return null;
|
|
732
|
+
return {
|
|
733
|
+
code: "CONFIG_DUPLICATE_ORIGIN_LABEL",
|
|
734
|
+
message: `${empty.map((o) => JSON.stringify(o)).join(", ")} share the empty label (use.baseURL of measured projects), so their endpoint keys are merged`,
|
|
735
|
+
hint: "Give each origin its own label in keys.origins unless merging their keys is intended."
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function list(names) {
|
|
739
|
+
return names.map((n) => n === "" ? "(default)" : n).join(", ");
|
|
740
|
+
}
|
|
741
|
+
function overriddenLine(conditions) {
|
|
742
|
+
const parts = [];
|
|
743
|
+
if (conditions.overridden.length > 0) {
|
|
744
|
+
parts.push(`perf mode overrides ${conditions.overridden.join(", ")}`);
|
|
745
|
+
}
|
|
746
|
+
if (conditions.removedProjects.length > 0) {
|
|
747
|
+
parts.push(`removed projects ${list(conditions.removedProjects)}`);
|
|
748
|
+
}
|
|
749
|
+
if (conditions.removedReporters.length > 0) {
|
|
750
|
+
parts.push(`removed reporters ${list(conditions.removedReporters)}`);
|
|
751
|
+
}
|
|
752
|
+
return parts.length === 0 ? null : `${parts.join("; ")}.`;
|
|
753
|
+
}
|
|
754
|
+
function plural2(n, word) {
|
|
755
|
+
return `${n} ${n === 1 ? word : `${word}s`}`;
|
|
756
|
+
}
|
|
757
|
+
function executionsLine(mode, tests, measured, repeat, workers) {
|
|
758
|
+
const inMeasured = tests.filter((t) => measured.has(t.parent.project()?.name ?? ""));
|
|
759
|
+
const unique = inMeasured.filter((t) => t.repeatEachIndex === 0).length;
|
|
760
|
+
const others = tests.length - inMeasured.length;
|
|
761
|
+
const extra = others > 0 ? `, plus ${plural2(others, "setup or teardown execution")}` : "";
|
|
762
|
+
return `perf mode "${mode}": ${plural2(inMeasured.length, "test execution")} (${plural2(unique, "test")} × ${plural2(repeat, "repeat")}), ${plural2(workers, "worker")}${extra}.`;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/reporter/samples.ts
|
|
766
|
+
function testTitle(test) {
|
|
767
|
+
const titles = [test.title];
|
|
768
|
+
for (let suite = test.parent; suite?.type === "describe"; suite = suite.parent) {
|
|
769
|
+
titles.unshift(suite.title);
|
|
770
|
+
}
|
|
771
|
+
return titles.join(" › ");
|
|
772
|
+
}
|
|
773
|
+
function projectName(test) {
|
|
774
|
+
return test.parent.project()?.name ?? "";
|
|
775
|
+
}
|
|
776
|
+
function testMeta(test, result, file) {
|
|
777
|
+
const title = testTitle(test);
|
|
778
|
+
const project = projectName(test);
|
|
779
|
+
return {
|
|
780
|
+
identity: testIdentity(project, file, title),
|
|
781
|
+
resultId: resultId(test.id, test.repeatEachIndex, result.retry),
|
|
782
|
+
title,
|
|
783
|
+
project,
|
|
784
|
+
file,
|
|
785
|
+
line: test.location.line,
|
|
786
|
+
repeatEachIndex: test.repeatEachIndex,
|
|
787
|
+
failed: isFailedTest(result.status, test.expectedStatus)
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function sampleAttachments(result) {
|
|
791
|
+
return result.attachments.filter((a) => a.name === SAMPLES_ATTACHMENT_NAME).map((a) => a.body === void 0 ? "" : a.body.toString("utf8"));
|
|
792
|
+
}
|
|
793
|
+
function hasTraceOrVideo(result) {
|
|
794
|
+
return result.attachments.some((a) => a.name === "trace" || a.name === "video");
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// src/reporter/session.ts
|
|
798
|
+
var PENDING_TOP_KEYS = 5;
|
|
799
|
+
var DEFAULT_WIDTH = 120;
|
|
800
|
+
function runSettings(registered, env, packageVersion) {
|
|
801
|
+
if (registered !== void 0) {
|
|
802
|
+
return {
|
|
803
|
+
config: registered.config,
|
|
804
|
+
snapshot: registered.snapshot,
|
|
805
|
+
mode: registered.mode,
|
|
806
|
+
packageVersion: registered.packageVersion,
|
|
807
|
+
measuredProjects: registered.measuredProjects,
|
|
808
|
+
runConditions: registered.runConditions,
|
|
809
|
+
registered: true,
|
|
810
|
+
warnings: [...registered.warnings],
|
|
811
|
+
toolErrors: []
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
const read = readModeState(env);
|
|
815
|
+
if (read.ok && read.value === null) return null;
|
|
816
|
+
const mode = read.ok && read.value !== null ? read.value : { mode: "test" };
|
|
817
|
+
const resolved = resolveConfig(void 0, {
|
|
818
|
+
mode: mode.mode,
|
|
819
|
+
...mode.repeat === void 0 ? {} : { repeat: mode.repeat },
|
|
820
|
+
...mode.env === void 0 ? {} : { env: mode.env }
|
|
821
|
+
});
|
|
822
|
+
if (!resolved.ok) throw new Error("the default package config is not valid");
|
|
823
|
+
return {
|
|
824
|
+
config: resolved.value.config,
|
|
825
|
+
snapshot: resolved.value.snapshot,
|
|
826
|
+
mode,
|
|
827
|
+
packageVersion,
|
|
828
|
+
measuredProjects: null,
|
|
829
|
+
runConditions: { overridden: [], removedProjects: [], removedReporters: [] },
|
|
830
|
+
registered: false,
|
|
831
|
+
warnings: [notWrappedWarning()],
|
|
832
|
+
toolErrors: read.ok ? [] : read.issues
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function internalError(where, error) {
|
|
836
|
+
const text = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
837
|
+
return {
|
|
838
|
+
code: "REPORTER_INTERNAL_ERROR",
|
|
839
|
+
message: `Unexpected error in the reporter (${where}): ${text}`,
|
|
840
|
+
hint: "This is a bug in the package; please report it with the message above."
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
function plural3(n, word, many = `${word}s`) {
|
|
844
|
+
return `${n} ${n === 1 ? word : many}`;
|
|
845
|
+
}
|
|
846
|
+
var RunSession = class {
|
|
847
|
+
host;
|
|
848
|
+
settings;
|
|
849
|
+
options;
|
|
850
|
+
warnings;
|
|
851
|
+
toolErrors;
|
|
852
|
+
startedAt;
|
|
853
|
+
runId;
|
|
854
|
+
configDir;
|
|
855
|
+
maxFailures = 0;
|
|
856
|
+
measured = /* @__PURE__ */ new Set();
|
|
857
|
+
conditions;
|
|
858
|
+
normalization;
|
|
859
|
+
aggregator;
|
|
860
|
+
keyOf;
|
|
861
|
+
/** onBegin failed: the evaluation is not possible. */
|
|
862
|
+
fatal = false;
|
|
863
|
+
testsStarted = 0;
|
|
864
|
+
testsSeen = /* @__PURE__ */ new Set();
|
|
865
|
+
notInstrumented = 0;
|
|
866
|
+
retried = 0;
|
|
867
|
+
withArtifacts = 0;
|
|
868
|
+
pending = /* @__PURE__ */ new Map();
|
|
869
|
+
playwrightVersion = "";
|
|
870
|
+
constructor(host, settings, options = {}) {
|
|
871
|
+
this.host = host;
|
|
872
|
+
this.settings = settings;
|
|
873
|
+
this.options = options;
|
|
874
|
+
this.warnings = [...settings.warnings];
|
|
875
|
+
this.toolErrors = [...settings.toolErrors];
|
|
876
|
+
this.startedAt = host.now();
|
|
877
|
+
this.runId = settings.mode.runId ?? generateRunId(this.startedAt, host.random);
|
|
878
|
+
this.configDir = host.cwd;
|
|
879
|
+
this.conditions = { workers: 1, projects: [], overriddenSettings: [] };
|
|
880
|
+
const keys = settings.config.keys;
|
|
881
|
+
this.normalization = normalizationFingerprint(keys, { baseOrigins: [] });
|
|
882
|
+
this.aggregator = this.createAggregator();
|
|
883
|
+
this.keyOf = createKeyBuilder(keys, { baseOrigins: [] });
|
|
884
|
+
}
|
|
885
|
+
get mode() {
|
|
886
|
+
return this.settings.mode.mode;
|
|
887
|
+
}
|
|
888
|
+
get repeat() {
|
|
889
|
+
return this.settings.config.run.repeat[this.mode];
|
|
890
|
+
}
|
|
891
|
+
createAggregator() {
|
|
892
|
+
const cfg = this.settings.config;
|
|
893
|
+
return new Aggregator({
|
|
894
|
+
advanced: cfg.advanced,
|
|
895
|
+
successStatuses: cfg.measure.successStatuses,
|
|
896
|
+
errors: cfg.checks.errors,
|
|
897
|
+
measuredProjects: this.measured,
|
|
898
|
+
evaluatedPercentile: cfg.checks.time.percentile.level,
|
|
899
|
+
rawUrls: cfg.report.rawUrls
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
info(line) {
|
|
903
|
+
this.host.stdout.write(`${PACKAGE_NAME}: ${line}
|
|
904
|
+
`);
|
|
905
|
+
}
|
|
906
|
+
/** A hook threw: the error goes to the report and the outcome file (01-REQ-16). */
|
|
907
|
+
recordInternalError(where, error) {
|
|
908
|
+
this.toolErrors.push(internalError(where, error));
|
|
909
|
+
if (where === "onBegin") this.fatal = true;
|
|
910
|
+
}
|
|
911
|
+
begin(config, suite) {
|
|
912
|
+
this.playwrightVersion = config.version;
|
|
913
|
+
this.startedAt = this.host.now();
|
|
914
|
+
if (this.settings.mode.runId === void 0) {
|
|
915
|
+
this.runId = generateRunId(this.startedAt, this.host.random);
|
|
916
|
+
}
|
|
917
|
+
const io = this.host.io;
|
|
918
|
+
this.configDir = config.configFile === void 0 ? config.rootDir : io.directoryOf(config.configFile);
|
|
919
|
+
this.maxFailures = config.maxFailures;
|
|
920
|
+
const names = this.settings.measuredProjects ?? config.projects.map((p) => p.name);
|
|
921
|
+
this.measured = new Set(names);
|
|
922
|
+
this.conditions = readRunConditions(
|
|
923
|
+
config,
|
|
924
|
+
this.measured,
|
|
925
|
+
this.settings.runConditions.overridden
|
|
926
|
+
);
|
|
927
|
+
const baseOrigins = measuredBaseOrigins(
|
|
928
|
+
this.conditions.projects.map((p, i) => ({
|
|
929
|
+
role: p.role,
|
|
930
|
+
baseURL: config.projects[i]?.use.baseURL
|
|
931
|
+
}))
|
|
932
|
+
);
|
|
933
|
+
const keys = this.settings.config.keys;
|
|
934
|
+
this.normalization = normalizationFingerprint(keys, { baseOrigins });
|
|
935
|
+
this.keyOf = createKeyBuilder(keys, { baseOrigins });
|
|
936
|
+
this.aggregator = this.createAggregator();
|
|
937
|
+
if (this.settings.registered) {
|
|
938
|
+
const changed = runConditionsWarning(this.conditions, this.repeat);
|
|
939
|
+
if (changed !== null) this.warnings.push(changed);
|
|
940
|
+
}
|
|
941
|
+
const duplicate = duplicateBaseUrlLabels(this.conditions, config, keys);
|
|
942
|
+
if (duplicate !== null) this.warnings.push(duplicate);
|
|
943
|
+
if (config.shard !== null) {
|
|
944
|
+
this.toolErrors.push({
|
|
945
|
+
code: "RUN_SHARDED",
|
|
946
|
+
message: `The perf-mode run is sharded (--shard ${config.shard.current}/${config.shard.total}): each machine would evaluate only part of the keys.`,
|
|
947
|
+
hint: "Run perf mode on one machine without --shard."
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
const overridden = overriddenLine(this.settings.runConditions);
|
|
951
|
+
if (overridden !== null) this.info(overridden);
|
|
952
|
+
this.info(
|
|
953
|
+
executionsLine(this.mode, suite.allTests(), this.measured, this.repeat, config.workers)
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
testBegin() {
|
|
957
|
+
this.testsStarted += 1;
|
|
958
|
+
}
|
|
959
|
+
testEnd(test, result) {
|
|
960
|
+
this.testsSeen.add(test);
|
|
961
|
+
if (result.retry > 0) this.retried += 1;
|
|
962
|
+
if (hasTraceOrVideo(result)) this.withArtifacts += 1;
|
|
963
|
+
const bodies = sampleAttachments(result);
|
|
964
|
+
const measured = this.measured.has(projectName(test));
|
|
965
|
+
if (bodies.length === 0) {
|
|
966
|
+
if (measured && result.status !== "skipped") this.notInstrumented += 1;
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const meta = testMeta(
|
|
970
|
+
test,
|
|
971
|
+
result,
|
|
972
|
+
this.host.io.relativeSlashPath(this.configDir, test.location.file)
|
|
973
|
+
);
|
|
974
|
+
if (bodies.length > 1) {
|
|
975
|
+
this.warnings.push({
|
|
976
|
+
code: "ATTACHMENT_DUPLICATE",
|
|
977
|
+
message: `Test "${meta.title}" has ${bodies.length} ${SAMPLES_ATTACHMENT_NAME} attachments; all of them were processed.`,
|
|
978
|
+
hint: "Apply withPerfFixtures() once per test object."
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
for (const body of bodies) {
|
|
982
|
+
const parsed = parseSampleBatch(body, meta.title);
|
|
983
|
+
if (!parsed.ok) {
|
|
984
|
+
this.toolErrors.push(...parsed.issues.map(schemaIssueToIssue));
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
const batch = parsed.value;
|
|
988
|
+
this.warnings.push(...batch.diagnostics);
|
|
989
|
+
batch.requests.forEach((sample, ordinal) => {
|
|
990
|
+
const keyed = addKeyedRequest(
|
|
991
|
+
this.aggregator,
|
|
992
|
+
this.keyOf,
|
|
993
|
+
{ ...sample, test: meta, ordinal },
|
|
994
|
+
batch.collector.browserName
|
|
995
|
+
);
|
|
996
|
+
this.warnings.push(...keyed.issues);
|
|
997
|
+
if (keyed.ok && sample.status === "PENDING" && measured) {
|
|
998
|
+
this.pending.set(keyed.key, (this.pending.get(keyed.key) ?? 0) + 1);
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
batch.custom.forEach((sample, ordinal) => {
|
|
1002
|
+
this.aggregator.addCustom(sample.name, { ...sample, test: meta, ordinal });
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
/** Warnings known only at the end of the run (09, chapter 12.1). */
|
|
1007
|
+
runWarnings() {
|
|
1008
|
+
const issues = [];
|
|
1009
|
+
if (this.notInstrumented > 0) {
|
|
1010
|
+
issues.push({
|
|
1011
|
+
code: "TESTS_NOT_INSTRUMENTED",
|
|
1012
|
+
message: `${plural3(this.notInstrumented, "test result")} of measured projects ${this.notInstrumented === 1 ? "has" : "have"} no ${SAMPLES_ATTACHMENT_NAME} attachment, so ${this.notInstrumented === 1 ? "it was" : "they were"} not measured.`,
|
|
1013
|
+
hint: 'Import test from a test object wrapped with withPerfFixtures() (or from "playwright-performance-regression/test"); a crashed worker also loses the attachment.'
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
if (this.retried > 0) {
|
|
1017
|
+
issues.push({
|
|
1018
|
+
code: "RUN_CONDITIONS_CHANGED",
|
|
1019
|
+
message: `${plural3(this.retried, "test result is a retry", "test results are retries")} (retry > 0), although perf mode sets retries to 0; samples of retries are counted.`,
|
|
1020
|
+
hint: "Remove retries set in test files (test.describe.configure({ retries })) for perf-mode runs."
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
if (this.withArtifacts > 0) {
|
|
1024
|
+
issues.push({
|
|
1025
|
+
code: "RUN_CONDITIONS_CHANGED",
|
|
1026
|
+
message: `${plural3(this.withArtifacts, "test result has", "test results have")} a trace or video attachment, although perf mode turns them off; recording slows the browser down.`,
|
|
1027
|
+
hint: "Remove test.use({ trace, video }) from test files for perf-mode runs."
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
return issues;
|
|
1031
|
+
}
|
|
1032
|
+
pendingWarning() {
|
|
1033
|
+
if (this.pending.size === 0) return null;
|
|
1034
|
+
let total = 0;
|
|
1035
|
+
for (const n of this.pending.values()) total += n;
|
|
1036
|
+
const top = [...this.pending].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)).slice(0, PENDING_TOP_KEYS).map(([key, n]) => `${key} (${n})`);
|
|
1037
|
+
return {
|
|
1038
|
+
code: "COLLECTOR_REQUESTS_PENDING",
|
|
1039
|
+
message: `${plural3(total, "request was", "requests were")} still pending at the end of a test; most in: ${top.join(", ")}.`,
|
|
1040
|
+
hint: "Exclude long polling and streaming with measure.exclude, or raise measure.pendingTimeoutMs."
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
testsResult(status) {
|
|
1044
|
+
const tests = { status, expected: 0, unexpected: 0, flaky: 0, skipped: 0 };
|
|
1045
|
+
for (const test of this.testsSeen) tests[test.outcome()] += 1;
|
|
1046
|
+
return tests;
|
|
1047
|
+
}
|
|
1048
|
+
source() {
|
|
1049
|
+
const browsers = this.conditions.projects.filter((p) => p.role === "measured" && p.browserName !== null).map((p) => p.browserName);
|
|
1050
|
+
const { nodeVersion: _, ...host } = this.host.host;
|
|
1051
|
+
return {
|
|
1052
|
+
browsers: [...new Set(browsers)].sort(),
|
|
1053
|
+
playwrightVersion: this.playwrightVersion,
|
|
1054
|
+
host,
|
|
1055
|
+
normalization: this.normalization
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
reportInput(status, finishedAt, aggregates, evaluation, warnings, toolErrors) {
|
|
1059
|
+
return {
|
|
1060
|
+
meta: {
|
|
1061
|
+
tool: { name: PACKAGE_NAME, version: this.settings.packageVersion },
|
|
1062
|
+
runId: this.runId,
|
|
1063
|
+
mode: this.mode,
|
|
1064
|
+
startedAt: this.startedAt.toISOString(),
|
|
1065
|
+
finishedAt: finishedAt.toISOString(),
|
|
1066
|
+
env: this.settings.config.run.env,
|
|
1067
|
+
configDir: this.configDir,
|
|
1068
|
+
ci: this.host.ci,
|
|
1069
|
+
host: this.host.host,
|
|
1070
|
+
playwright: { version: this.playwrightVersion }
|
|
1071
|
+
},
|
|
1072
|
+
config: this.settings.snapshot,
|
|
1073
|
+
normalization: this.normalization,
|
|
1074
|
+
runConditions: this.conditions,
|
|
1075
|
+
tests: this.testsResult(status),
|
|
1076
|
+
aggregates,
|
|
1077
|
+
evaluation,
|
|
1078
|
+
warnings,
|
|
1079
|
+
toolErrors
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
terminal() {
|
|
1083
|
+
const out = this.host.stdout;
|
|
1084
|
+
return {
|
|
1085
|
+
width: out.isTTY === true && out.columns !== void 0 && out.columns > 0 ? out.columns : DEFAULT_WIDTH,
|
|
1086
|
+
color: colorEnabled(out, this.host.env)
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* onEnd (01, chapter 3.3, steps 8–9). Returns the status for Playwright: `failed` when the
|
|
1091
|
+
* outcome exit code is not 0, otherwise nothing, so Playwright keeps its own (01-REQ-17).
|
|
1092
|
+
*/
|
|
1093
|
+
async end(result) {
|
|
1094
|
+
if (this.testsStarted === 0) return void 0;
|
|
1095
|
+
let outcome;
|
|
1096
|
+
try {
|
|
1097
|
+
outcome = await this.finish(result);
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
this.recordInternalError("onEnd", error);
|
|
1100
|
+
outcome = this.fallbackOutcome(result);
|
|
1101
|
+
for (const issue of outcome.toolErrors) {
|
|
1102
|
+
this.host.stderr.write(`${PACKAGE_NAME}: ${issue.code}: ${issue.message}
|
|
1103
|
+
`);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
await this.writeOutcome(outcome);
|
|
1107
|
+
return outcome.exitCode === 0 ? void 0 : { status: "failed" };
|
|
1108
|
+
}
|
|
1109
|
+
async finish(result) {
|
|
1110
|
+
const cfg = this.settings.config;
|
|
1111
|
+
const io = this.host.io;
|
|
1112
|
+
const finishedAt = this.host.now();
|
|
1113
|
+
const warnings = [...this.warnings, ...this.runWarnings()];
|
|
1114
|
+
const toolErrors = [...this.toolErrors];
|
|
1115
|
+
const aggregates = this.aggregator.finalize();
|
|
1116
|
+
warnings.push(...aggregates.issues, ...detectKeyExplosion(Object.keys(aggregates.endpoints)));
|
|
1117
|
+
const pending = this.pendingWarning();
|
|
1118
|
+
if (pending !== null) warnings.push(pending);
|
|
1119
|
+
const tests = this.testsResult(result.status);
|
|
1120
|
+
const assessment = assessRun(
|
|
1121
|
+
{ tests, maxFailures: this.maxFailures, sharded: false },
|
|
1122
|
+
cfg.gate
|
|
1123
|
+
);
|
|
1124
|
+
warnings.push(...assessment.warnings);
|
|
1125
|
+
toolErrors.push(...assessment.toolErrors);
|
|
1126
|
+
const location = {
|
|
1127
|
+
configDir: this.configDir,
|
|
1128
|
+
dir: cfg.thresholds.dir,
|
|
1129
|
+
filePrefix: cfg.thresholds.filePrefix,
|
|
1130
|
+
env: cfg.run.env
|
|
1131
|
+
};
|
|
1132
|
+
const loaded = await io.loadThresholds(location);
|
|
1133
|
+
const evaluation = evaluate(aggregates, loaded, cfg, {
|
|
1134
|
+
mode: this.mode,
|
|
1135
|
+
env: cfg.run.env,
|
|
1136
|
+
fatalToolError: this.fatal,
|
|
1137
|
+
source: this.source(),
|
|
1138
|
+
startedAt: this.startedAt.toISOString()
|
|
1139
|
+
});
|
|
1140
|
+
warnings.push(...evaluation.warnings);
|
|
1141
|
+
toolErrors.push(...evaluation.toolErrors);
|
|
1142
|
+
const build = () => buildRunReport(
|
|
1143
|
+
this.reportInput(result.status, finishedAt, aggregates, evaluation, warnings, toolErrors)
|
|
1144
|
+
);
|
|
1145
|
+
let report = build();
|
|
1146
|
+
const reportDir = io.resolvePath(this.configDir, cfg.report.dir);
|
|
1147
|
+
const paths = {
|
|
1148
|
+
reportJson: null,
|
|
1149
|
+
reportHtml: null,
|
|
1150
|
+
thresholds: [],
|
|
1151
|
+
thresholdsDiff: null
|
|
1152
|
+
};
|
|
1153
|
+
let diffs = [];
|
|
1154
|
+
let diffPaths = [];
|
|
1155
|
+
if (this.mode === "thresholds") {
|
|
1156
|
+
const derived = await this.deriveAndWrite(
|
|
1157
|
+
report,
|
|
1158
|
+
loaded,
|
|
1159
|
+
location,
|
|
1160
|
+
paths,
|
|
1161
|
+
warnings,
|
|
1162
|
+
toolErrors
|
|
1163
|
+
);
|
|
1164
|
+
diffs = derived.diffs;
|
|
1165
|
+
diffPaths = derived.paths;
|
|
1166
|
+
report = build();
|
|
1167
|
+
}
|
|
1168
|
+
const writeJson = async () => {
|
|
1169
|
+
try {
|
|
1170
|
+
const path = io.resolvePath(reportDir, "report.json");
|
|
1171
|
+
await io.writeJsonStable(path, report);
|
|
1172
|
+
paths.reportJson = path;
|
|
1173
|
+
return true;
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
toolErrors.push({
|
|
1176
|
+
code: "REPORT_WRITE_FAILED",
|
|
1177
|
+
message: `The run report could not be written to ${reportDir}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1178
|
+
hint: "Check that report.dir is writable."
|
|
1179
|
+
});
|
|
1180
|
+
report = build();
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
await writeJson();
|
|
1185
|
+
if (cfg.report.html) {
|
|
1186
|
+
const issue = await this.writeHtml(report, io.resolvePath(reportDir, "report.html"), paths);
|
|
1187
|
+
if (issue !== null) {
|
|
1188
|
+
toolErrors.push(issue);
|
|
1189
|
+
report = build();
|
|
1190
|
+
if (paths.reportJson !== null) await writeJson();
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
const { width, color } = this.terminal();
|
|
1194
|
+
this.host.stdout.write(
|
|
1195
|
+
formatSummary(report, { width, color, cwd: this.host.cwd, html: paths.reportHtml !== null })
|
|
1196
|
+
);
|
|
1197
|
+
if (diffs.length > 0) {
|
|
1198
|
+
this.host.stdout.write(
|
|
1199
|
+
formatThresholdsDiff(diffs, {
|
|
1200
|
+
paths: diffPaths.map((p) => io.relativeSlashPath(this.host.cwd, p)),
|
|
1201
|
+
width,
|
|
1202
|
+
color,
|
|
1203
|
+
prune: this.settings.mode.prune === true,
|
|
1204
|
+
diffPath: paths.thresholdsDiff === null ? null : io.relativeSlashPath(this.host.cwd, paths.thresholdsDiff)
|
|
1205
|
+
})
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
return buildOutcome(report, paths);
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Writes report.html next to report.json (11-REQ-04). The page is rendered from the report as
|
|
1212
|
+
* written to JSON, so `report` renders the same HTML from report.json (11-AC-10). Returns the
|
|
1213
|
+
* HTML_RENDER_FAILED or HTML_WRITE_FAILED tool error (11, chapter 13), or null.
|
|
1214
|
+
*/
|
|
1215
|
+
async writeHtml(report, path, paths) {
|
|
1216
|
+
const render = this.options.renderHtml ?? renderHtmlReport;
|
|
1217
|
+
let page;
|
|
1218
|
+
try {
|
|
1219
|
+
page = render(JSON.parse(stringifyStable(report)));
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
return {
|
|
1222
|
+
code: "HTML_RENDER_FAILED",
|
|
1223
|
+
message: `The HTML report could not be rendered: ${error instanceof Error ? error.stack ?? error.message : String(error)}`,
|
|
1224
|
+
hint: "This is a bug in the package; please report it with the message above. report.json is complete."
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
try {
|
|
1228
|
+
await this.host.io.writeTextAtomic(path, page);
|
|
1229
|
+
paths.reportHtml = path;
|
|
1230
|
+
return null;
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
return {
|
|
1233
|
+
code: "HTML_WRITE_FAILED",
|
|
1234
|
+
message: `The HTML report could not be written to ${path}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1235
|
+
hint: `Check that report.dir is writable; \`${CLI_COMMAND} report\` renders it again from report.json.`
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Derivation in thresholds mode (10, chapter 3): refusals and write errors are tool errors, so
|
|
1241
|
+
* nothing is written for an incomplete run (04-REQ-36); the diff file failing is a warning.
|
|
1242
|
+
* Returns the diffs and the absolute path of each thresholds file.
|
|
1243
|
+
*/
|
|
1244
|
+
async deriveAndWrite(report, loaded, location, paths, warnings, toolErrors) {
|
|
1245
|
+
const cfg = this.settings.config;
|
|
1246
|
+
const io = this.host.io;
|
|
1247
|
+
const derived = deriveThresholds(report, cfg, loaded, {
|
|
1248
|
+
env: cfg.run.env,
|
|
1249
|
+
prune: this.settings.mode.prune === true,
|
|
1250
|
+
toolVersion: this.settings.packageVersion
|
|
1251
|
+
});
|
|
1252
|
+
if (!derived.ok) {
|
|
1253
|
+
toolErrors.push(...derived.issues);
|
|
1254
|
+
return { diffs: [], paths: [] };
|
|
1255
|
+
}
|
|
1256
|
+
warnings.push(...derived.value.warnings);
|
|
1257
|
+
const absolute = io.thresholdsFilePaths(location);
|
|
1258
|
+
for (const file of derived.value.files) {
|
|
1259
|
+
if (file.content === null || !file.changed) continue;
|
|
1260
|
+
try {
|
|
1261
|
+
await io.writeJsonStable(absolute[file.kind], file.content);
|
|
1262
|
+
paths.thresholds.push(absolute[file.kind]);
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
toolErrors.push({
|
|
1265
|
+
code: "THRESHOLDS_WRITE_FAILED",
|
|
1266
|
+
message: `The thresholds file ${loaded[file.kind].path} could not be written: ${error instanceof Error ? error.message : String(error)}`,
|
|
1267
|
+
hint: "Check that thresholds.dir is writable, then derive the thresholds again."
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
const diffs = derived.value.files.map(
|
|
1272
|
+
(file) => diffThresholds(loaded[file.kind], file, report, cfg)
|
|
1273
|
+
);
|
|
1274
|
+
const filePaths = derived.value.files.map((file) => absolute[file.kind]);
|
|
1275
|
+
const diffPath = io.resolvePath(
|
|
1276
|
+
io.resolvePath(this.configDir, cfg.report.dir),
|
|
1277
|
+
"thresholds-diff.md"
|
|
1278
|
+
);
|
|
1279
|
+
try {
|
|
1280
|
+
await io.writeTextAtomic(
|
|
1281
|
+
diffPath,
|
|
1282
|
+
formatThresholdsDiffMarkdown(
|
|
1283
|
+
diffs,
|
|
1284
|
+
derived.value.files.map((file) => loaded[file.kind].path)
|
|
1285
|
+
)
|
|
1286
|
+
);
|
|
1287
|
+
paths.thresholdsDiff = diffPath;
|
|
1288
|
+
} catch (error) {
|
|
1289
|
+
warnings.push({
|
|
1290
|
+
code: "THRESHOLDS_DIFF_WRITE_FAILED",
|
|
1291
|
+
message: `The thresholds diff could not be written to ${diffPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1292
|
+
hint: "The thresholds files are written; check that report.dir is writable."
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
return { diffs, paths: filePaths };
|
|
1296
|
+
}
|
|
1297
|
+
/** The outcome when building the report failed: exit code 3 with the error (02-REQ-27). */
|
|
1298
|
+
fallbackOutcome(result) {
|
|
1299
|
+
return {
|
|
1300
|
+
schemaVersion: SCHEMA_VERSIONS.outcome,
|
|
1301
|
+
runId: this.runId,
|
|
1302
|
+
mode: this.mode,
|
|
1303
|
+
exitCode: 3,
|
|
1304
|
+
tests: { status: result.status },
|
|
1305
|
+
evaluation: { status: "error", gateEnabled: this.mode === "test" },
|
|
1306
|
+
toolErrors: this.toolErrors.map((issue) => ({ ...issue })),
|
|
1307
|
+
paths: { reportJson: null, reportHtml: null, thresholds: [], thresholdsDiff: null }
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
/** Last step of onEnd (02-REQ-27); without PW_PERF_OUTCOME_FILE there is no outcome file. */
|
|
1311
|
+
async writeOutcome(outcome) {
|
|
1312
|
+
const file = this.settings.mode.outcomeFile;
|
|
1313
|
+
if (file === void 0) return;
|
|
1314
|
+
try {
|
|
1315
|
+
await this.host.io.writeJsonStable(file, outcome);
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
this.host.stderr.write(
|
|
1318
|
+
`${PACKAGE_NAME}: OUTCOME_WRITE_FAILED: the outcome file could not be written to ${file}: ${error instanceof Error ? error.message : String(error)}
|
|
1319
|
+
`
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
// src/reporter/perf-reporter.ts
|
|
1326
|
+
function processHost() {
|
|
1327
|
+
const env = process.env;
|
|
1328
|
+
return {
|
|
1329
|
+
env,
|
|
1330
|
+
io: {
|
|
1331
|
+
loadThresholds,
|
|
1332
|
+
thresholdsFilePaths,
|
|
1333
|
+
writeJsonStable,
|
|
1334
|
+
writeTextAtomic,
|
|
1335
|
+
resolvePath,
|
|
1336
|
+
directoryOf,
|
|
1337
|
+
relativeSlashPath
|
|
1338
|
+
},
|
|
1339
|
+
stdout: process.stdout,
|
|
1340
|
+
stderr: process.stderr,
|
|
1341
|
+
cwd: process.cwd(),
|
|
1342
|
+
now: () => /* @__PURE__ */ new Date(),
|
|
1343
|
+
random: Math.random,
|
|
1344
|
+
ci: readCiInfo(env),
|
|
1345
|
+
host: readHostInfo(env)
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
var PerfReporter = class {
|
|
1349
|
+
/** Reporter options from the Playwright config; none are defined yet. */
|
|
1350
|
+
options;
|
|
1351
|
+
session;
|
|
1352
|
+
startError;
|
|
1353
|
+
constructor(options = {}) {
|
|
1354
|
+
this.options = options;
|
|
1355
|
+
let session = null;
|
|
1356
|
+
let startError;
|
|
1357
|
+
try {
|
|
1358
|
+
const host = processHost();
|
|
1359
|
+
const settings = runSettings(getRegistered(), host.env, version);
|
|
1360
|
+
session = settings === null ? null : new RunSession(host, settings);
|
|
1361
|
+
} catch (error) {
|
|
1362
|
+
startError = error;
|
|
1363
|
+
}
|
|
1364
|
+
this.session = session;
|
|
1365
|
+
this.startError = startError;
|
|
1366
|
+
if (startError !== void 0) {
|
|
1367
|
+
process.stderr.write(
|
|
1368
|
+
`playwright-performance-regression: REPORTER_INTERNAL_ERROR: the reporter could not start: ${startError instanceof Error ? startError.message : String(startError)}
|
|
1369
|
+
`
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
onBegin(config, suite) {
|
|
1374
|
+
const session = this.session;
|
|
1375
|
+
if (session === null) return;
|
|
1376
|
+
try {
|
|
1377
|
+
session.begin(config, suite);
|
|
1378
|
+
} catch (error) {
|
|
1379
|
+
session.recordInternalError("onBegin", error);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
onTestBegin() {
|
|
1383
|
+
this.session?.testBegin();
|
|
1384
|
+
}
|
|
1385
|
+
onTestEnd(test, result) {
|
|
1386
|
+
const session = this.session;
|
|
1387
|
+
if (session === null) return;
|
|
1388
|
+
try {
|
|
1389
|
+
session.testEnd(test, result);
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
session.recordInternalError("onTestEnd", error);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
async onEnd(result) {
|
|
1395
|
+
if (this.session === null) return void 0;
|
|
1396
|
+
return this.session.end(result);
|
|
1397
|
+
}
|
|
1398
|
+
printsToStdio() {
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
// src/entries/reporter.ts
|
|
1404
|
+
var reporter_default = PerfReporter;
|
|
1405
|
+
|
|
1406
|
+
export { PerfReporter, reporter_default as default };
|