playwright-performance-regression 0.1.0-next.1 → 0.1.0-next.3
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 +181 -0
- package/README.md +70 -51
- package/dist/{chunk-GCA73FFP.cjs → chunk-2JO5HVPC.cjs} +351 -44
- package/dist/{chunk-WZVQK7CQ.cjs → chunk-44ASXVQN.cjs} +96 -198
- package/dist/{chunk-L5C63HEF.js → chunk-AQ2XKYNV.js} +347 -45
- package/dist/chunk-BAOTUUTV.cjs +611 -0
- package/dist/chunk-DX36GFOZ.js +558 -0
- package/dist/chunk-LTRHMBVY.js +5592 -0
- package/dist/{chunk-B64P2D5A.js → chunk-MUZFQKGQ.js} +82 -184
- package/dist/cli.js +2825 -1406
- package/dist/config.cjs +91 -44
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/config.js +84 -37
- package/dist/fixture.cjs +5 -5
- package/dist/fixture.d.cts +2 -2
- package/dist/fixture.d.ts +2 -2
- package/dist/fixture.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +110 -22
- package/dist/index.d.ts +110 -22
- package/dist/index.js +1 -1
- package/dist/perf-api-Rm1h1O_-.d.cts +12 -0
- package/dist/perf-api-Rm1h1O_-.d.ts +12 -0
- package/dist/reporter.cjs +5184 -1207
- package/dist/reporter.js +2029 -245
- package/dist/test.cjs +4 -4
- package/dist/test.js +3 -3
- package/package.json +3 -1
- package/schemas/common.schema.json +2 -2
- package/schemas/config.schema.json +57 -21
- package/schemas/outcome.schema.json +1 -1
- package/schemas/run-report.schema.json +534 -19
- package/schemas/samples.schema.json +4 -39
- package/schemas/thresholds.schema.json +1 -1
- package/dist/chunk-3CLCMD2Q.js +0 -3411
- package/dist/chunk-4SFI55HF.cjs +0 -319
- package/dist/chunk-HBGADXLP.js +0 -254
- package/dist/perf-api-V4PeHVE0.d.cts +0 -22
- package/dist/perf-api-V4PeHVE0.d.ts +0 -22
package/dist/reporter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getRegistered, notWrappedWarning } from './chunk-DYLCGMI2.js';
|
|
2
|
-
import { relativeSlashPath, directoryOf, resolvePath, writeTextAtomic, writeJsonStable, thresholdsFilePaths, loadThresholds, readHostInfo, readCiInfo,
|
|
3
|
-
import { version, readModeState, generateRunId, PACKAGE_NAME, SAMPLES_ATTACHMENT_NAME, CLI_COMMAND } from './chunk-
|
|
4
|
-
import { resolveConfig } from './chunk-
|
|
2
|
+
import { listDirSync, readTextFileSync, readTextFile, tempPath, readPackageInfo, removeFileSync, relativeSlashPath, directoryOf, resolvePath, writeTextAtomic, writeJsonStable, thresholdsFilePaths, loadThresholds, askTerminal, runPass, readHostInfo, readCiInfo, parseRunReport, asciiTerminal, parseSampleBatch, schemaIssueToIssue, addKeyedRequest, resultId, colorEnabled, outcomeLine, nextLine, assessRun, evaluate, formatThresholdsDiff, buildOutcome, SCHEMA_VERSIONS, renderHtmlReport, stringifyStable, deriveThresholds, diffThresholds, formatThresholdsDiffMarkdown, hashHex, Aggregator, plural, box, isFailedTest, testIdentity, painter, marks, padEnd, truncateMiddle, compareText, textWidth, boxLines, table, roundMs, roundRatio, compileStatusMatcher } from './chunk-LTRHMBVY.js';
|
|
3
|
+
import { version, readModeState, generateRunId, PACKAGE_NAME, testFilters, testArgsFromArgv, DEFAULT_MAX_TESTS, isCiEnv, SAMPLES_ATTACHMENT_NAME, passCommand, writeModeState, checkStateFileName, CLI_COMMAND, KINDS } from './chunk-DX36GFOZ.js';
|
|
4
|
+
import { resolveConfig, compileHostPatterns, isHostPattern, matchingPattern, perfDefaults } from './chunk-AQ2XKYNV.js';
|
|
5
5
|
|
|
6
6
|
// src/core/normalize/constants.ts
|
|
7
7
|
var NORMALIZE_RULES_VERSION = 1;
|
|
@@ -135,21 +135,21 @@ function normalizePath(pathname, matchId) {
|
|
|
135
135
|
function normalizeQuery(params, keys, matchId) {
|
|
136
136
|
const drop = new Set(keys.dropQueryParams);
|
|
137
137
|
const keep = new Set(keys.keepQueryValues);
|
|
138
|
-
const
|
|
138
|
+
const names2 = /* @__PURE__ */ new Map();
|
|
139
139
|
for (const [rawName, value] of params) {
|
|
140
140
|
const name = rawName.replace(/\[[0-9]+\]/g, "[]");
|
|
141
141
|
if (name === "" || drop.has(name) || matchId(name) !== null) continue;
|
|
142
142
|
const encoded = escape(name, NAME_ESCAPE);
|
|
143
143
|
if (!keep.has(name)) {
|
|
144
|
-
if (!
|
|
144
|
+
if (!names2.has(encoded)) names2.set(encoded, null);
|
|
145
145
|
continue;
|
|
146
146
|
}
|
|
147
|
-
const values =
|
|
147
|
+
const values = names2.get(encoded) ?? /* @__PURE__ */ new Set();
|
|
148
148
|
values.add(matchId(value) ?? escape(value, VALUE_ESCAPE));
|
|
149
|
-
|
|
149
|
+
names2.set(encoded, values);
|
|
150
150
|
}
|
|
151
|
-
return [...
|
|
152
|
-
const values =
|
|
151
|
+
return [...names2.keys()].sort().map((name) => {
|
|
152
|
+
const values = names2.get(name);
|
|
153
153
|
return values ? `${name}=${[...values].sort().join(",")}` : name;
|
|
154
154
|
}).join("&");
|
|
155
155
|
}
|
|
@@ -162,14 +162,32 @@ function truncateKey(key) {
|
|
|
162
162
|
if (before >= 55296 && before <= 56319 && after >= 56320 && after <= 57343) cut -= 1;
|
|
163
163
|
return key.slice(0, cut) + suffix;
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
for (const [origin, label] of Object.entries(cfg.origins)) {
|
|
165
|
+
function originLabels(origins, baseOrigins) {
|
|
166
|
+
const exact = /* @__PURE__ */ new Map();
|
|
167
|
+
for (const [origin, label] of Object.entries(origins)) {
|
|
168
|
+
if (isHostPattern(origin)) continue;
|
|
170
169
|
const canonical = canonicalOrigin(origin);
|
|
171
|
-
if (canonical !== null)
|
|
170
|
+
if (canonical !== null) exact.set(canonical, label);
|
|
172
171
|
}
|
|
172
|
+
const patterns = compileHostPatterns(origins);
|
|
173
|
+
const base = new Set(canonicalOrigins(baseOrigins));
|
|
174
|
+
const memo = /* @__PURE__ */ new Map();
|
|
175
|
+
return (url) => {
|
|
176
|
+
const known = memo.get(url.origin);
|
|
177
|
+
if (known !== void 0) return known;
|
|
178
|
+
const label = exact.get(url.origin) ?? matchingPattern(patterns, url)?.label ?? (base.has(url.origin) ? "" : null);
|
|
179
|
+
memo.set(url.origin, label);
|
|
180
|
+
return label;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function coveredByOrigins(origins, origin) {
|
|
184
|
+
const url = parseHttpUrl(origin);
|
|
185
|
+
if (url === null) return false;
|
|
186
|
+
return originLabels(origins, [])(url) !== null;
|
|
187
|
+
}
|
|
188
|
+
function createKeyBuilder(cfg, ctx) {
|
|
189
|
+
const matchId = compileIdMatcher(cfg);
|
|
190
|
+
const labelOf = originLabels(cfg.origins, ctx.baseOrigins);
|
|
173
191
|
const keyBuilder = cfg.keyBuilder;
|
|
174
192
|
return (sample) => {
|
|
175
193
|
const method = sample.method.toUpperCase();
|
|
@@ -177,20 +195,20 @@ function createKeyBuilder(cfg, ctx) {
|
|
|
177
195
|
const issues = [];
|
|
178
196
|
let key;
|
|
179
197
|
if (keyBuilder !== void 0) {
|
|
180
|
-
let
|
|
198
|
+
let built;
|
|
181
199
|
try {
|
|
182
|
-
|
|
200
|
+
built = keyBuilder({ method, url: sample.url, resourceType: sample.resourceType });
|
|
183
201
|
} catch (error) {
|
|
184
202
|
issues.push({
|
|
185
203
|
code: "NORMALIZE_KEY_BUILDER_THREW",
|
|
186
204
|
message: `keys.keyBuilder threw an exception: ${error instanceof Error ? error.message : String(error)}. The built-in normalization was used instead.`,
|
|
187
205
|
hint: "Fix the keyBuilder function; it must not throw."
|
|
188
206
|
});
|
|
189
|
-
|
|
207
|
+
built = void 0;
|
|
190
208
|
}
|
|
191
|
-
if (typeof
|
|
192
|
-
key =
|
|
193
|
-
} else if (
|
|
209
|
+
if (typeof built === "string" && built.trim() !== "") {
|
|
210
|
+
key = built;
|
|
211
|
+
} else if (built !== void 0) {
|
|
194
212
|
issues.push({
|
|
195
213
|
code: "NORMALIZE_KEY_BUILDER_INVALID",
|
|
196
214
|
message: "keys.keyBuilder returned a value that is neither a non-empty string nor undefined. The built-in normalization was used instead.",
|
|
@@ -206,7 +224,7 @@ function createKeyBuilder(cfg, ctx) {
|
|
|
206
224
|
});
|
|
207
225
|
return { ok: false, issues };
|
|
208
226
|
}
|
|
209
|
-
const label =
|
|
227
|
+
const label = labelOf(url) ?? url.host;
|
|
210
228
|
const query = cfg.query === "names" ? normalizeQuery(url.searchParams, cfg, matchId) : "";
|
|
211
229
|
key = `${method} ${label}${normalizePath(url.pathname, matchId)}${query === "" ? "" : `?${query}`}`;
|
|
212
230
|
}
|
|
@@ -222,7 +240,7 @@ function createKeyBuilder(cfg, ctx) {
|
|
|
222
240
|
ok: true,
|
|
223
241
|
key: truncated,
|
|
224
242
|
origin: url?.origin ?? null,
|
|
225
|
-
label: url === null ? null :
|
|
243
|
+
label: url === null ? null : labelOf(url) ?? url.host,
|
|
226
244
|
issues
|
|
227
245
|
};
|
|
228
246
|
};
|
|
@@ -251,11 +269,186 @@ function normalizationFingerprint(cfg, ctx) {
|
|
|
251
269
|
stringifyStable({
|
|
252
270
|
rulesVersion: NORMALIZE_RULES_VERSION,
|
|
253
271
|
keys,
|
|
254
|
-
|
|
272
|
+
// Only baseURL origins keys.origins does not map change the keys (07-REQ-26).
|
|
273
|
+
baseOrigins: canonicalOrigins(ctx.baseOrigins).filter(
|
|
274
|
+
(origin) => !coveredByOrigins(cfg.origins, origin)
|
|
275
|
+
)
|
|
255
276
|
})
|
|
256
277
|
);
|
|
257
278
|
}
|
|
258
279
|
|
|
280
|
+
// src/core/report/hints.ts
|
|
281
|
+
var NEAR_LIMIT_USAGE = 0.9;
|
|
282
|
+
var TAIL_MEDIAN_USAGE = 0.8;
|
|
283
|
+
var MAX_HINTS = 3;
|
|
284
|
+
function checkUsage(check) {
|
|
285
|
+
if (check.rule === "apdex") {
|
|
286
|
+
if (check.limit === 1) return check.actual === 1 ? 0 : null;
|
|
287
|
+
return roundRatio((1 - check.actual) / (1 - check.limit));
|
|
288
|
+
}
|
|
289
|
+
if (check.limit === 0) return check.actual === 0 ? 0 : null;
|
|
290
|
+
return roundRatio(check.actual / check.limit);
|
|
291
|
+
}
|
|
292
|
+
function withUsage(checks) {
|
|
293
|
+
return checks.map((check) => ({ ...check, usage: checkUsage(check) }));
|
|
294
|
+
}
|
|
295
|
+
function keyHeadroom(checks) {
|
|
296
|
+
if (checks.length === 0) return null;
|
|
297
|
+
let max = -Infinity;
|
|
298
|
+
for (const check of checks) max = Math.max(max, check.usage ?? Infinity);
|
|
299
|
+
return max;
|
|
300
|
+
}
|
|
301
|
+
var TIME_RULES = ["median", "percentile", "p99"];
|
|
302
|
+
var RULE_ORDER = [
|
|
303
|
+
"median",
|
|
304
|
+
"percentile",
|
|
305
|
+
"p99",
|
|
306
|
+
"apdex",
|
|
307
|
+
"wilson",
|
|
308
|
+
"errors"
|
|
309
|
+
];
|
|
310
|
+
function compareText2(a, b) {
|
|
311
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
312
|
+
}
|
|
313
|
+
function finding(checks, rule) {
|
|
314
|
+
return checks.find((c) => c.rule === rule);
|
|
315
|
+
}
|
|
316
|
+
function timeChecksPass(checks) {
|
|
317
|
+
return checks.every((c) => !TIME_RULES.includes(c.rule) || c.passed);
|
|
318
|
+
}
|
|
319
|
+
function errorLabels(facts, options) {
|
|
320
|
+
const isError = compileStatusMatcher(options.errorStatuses);
|
|
321
|
+
return Object.entries(facts.statuses).filter(([label]) => isError(label)).sort((a, b) => b[1] - a[1] || compareText2(a[0], b[0]));
|
|
322
|
+
}
|
|
323
|
+
function percentileHint(code) {
|
|
324
|
+
return ({ evaluation: { checks } }) => {
|
|
325
|
+
const percentile = finding(checks, "percentile");
|
|
326
|
+
const median = finding(checks, "median");
|
|
327
|
+
if (percentile === void 0 || percentile.passed || percentile.usage === null) return null;
|
|
328
|
+
if (median === void 0 || !median.passed || median.usage === null) return null;
|
|
329
|
+
const tail = median.usage <= TAIL_MEDIAN_USAGE;
|
|
330
|
+
if (tail !== (code === "HINT_TAIL")) return null;
|
|
331
|
+
return { code, params: { usage: percentile.usage, medianUsage: median.usage } };
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
var RULES = [
|
|
335
|
+
({ evaluation: { checks } }, { hardLimitFactor }) => {
|
|
336
|
+
if (hardLimitFactor === null) return null;
|
|
337
|
+
for (const rule of TIME_RULES) {
|
|
338
|
+
const check = finding(checks, rule);
|
|
339
|
+
if (check?.hardLimitExceeded === true && check.blocking && check.usage !== null) {
|
|
340
|
+
return {
|
|
341
|
+
code: "HINT_HARD_LIMIT",
|
|
342
|
+
params: { rule, usage: check.usage, factor: hardLimitFactor }
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
},
|
|
348
|
+
({ evaluation: { checks } }) => {
|
|
349
|
+
const median = finding(checks, "median");
|
|
350
|
+
if (median === void 0 || median.passed || median.usage === null) return null;
|
|
351
|
+
return { code: "HINT_SLOWDOWN", params: { usage: median.usage } };
|
|
352
|
+
},
|
|
353
|
+
percentileHint("HINT_TAIL"),
|
|
354
|
+
percentileHint("HINT_SHIFT"),
|
|
355
|
+
({ stats, evaluation: { checks } }) => {
|
|
356
|
+
const p99 = finding(checks, "p99");
|
|
357
|
+
const percentile = finding(checks, "percentile");
|
|
358
|
+
if (p99 === void 0 || p99.passed || p99.usage === null || stats === null) return null;
|
|
359
|
+
if (percentile === void 0 || !percentile.passed) return null;
|
|
360
|
+
return { code: "HINT_OUTLIERS", params: { usage: p99.usage, max: stats.max } };
|
|
361
|
+
},
|
|
362
|
+
(facts, options) => {
|
|
363
|
+
const errors = finding(facts.evaluation.checks, "errors");
|
|
364
|
+
if (errors === void 0 || errors.passed || errors.observed === null) return null;
|
|
365
|
+
const [top] = errorLabels(facts, options);
|
|
366
|
+
if (top === void 0 || top[1] * 2 < facts.errorCount) return null;
|
|
367
|
+
return {
|
|
368
|
+
code: "HINT_ERRORS_DOMINANT",
|
|
369
|
+
params: {
|
|
370
|
+
rate: errors.observed,
|
|
371
|
+
limit: errors.limit,
|
|
372
|
+
label: top[0],
|
|
373
|
+
count: top[1],
|
|
374
|
+
errors: facts.errorCount
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
},
|
|
378
|
+
(facts, options) => {
|
|
379
|
+
const errors = finding(facts.evaluation.checks, "errors");
|
|
380
|
+
if (errors === void 0 || errors.passed || errors.observed === null) return null;
|
|
381
|
+
const labels = errorLabels(facts, options);
|
|
382
|
+
const [first, second, third] = labels;
|
|
383
|
+
if (first === void 0 || second === void 0 || third === void 0) return null;
|
|
384
|
+
if (first[1] * 2 >= facts.errorCount) return null;
|
|
385
|
+
return {
|
|
386
|
+
code: "HINT_ERRORS_MIXED",
|
|
387
|
+
params: {
|
|
388
|
+
rate: errors.observed,
|
|
389
|
+
limit: errors.limit,
|
|
390
|
+
label1: first[0],
|
|
391
|
+
count1: first[1],
|
|
392
|
+
label2: second[0],
|
|
393
|
+
count2: second[1],
|
|
394
|
+
label3: third[0],
|
|
395
|
+
count3: third[1]
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
},
|
|
399
|
+
({ evaluation: { checks, limits } }) => {
|
|
400
|
+
const apdex = finding(checks, "apdex");
|
|
401
|
+
if (apdex === void 0 || apdex.passed || apdex.observed === null || limits.t === null) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (!timeChecksPass(checks)) return null;
|
|
405
|
+
return {
|
|
406
|
+
code: "HINT_APDEX",
|
|
407
|
+
params: { apdex: apdex.observed, limit: apdex.limit, t: limits.t }
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
({ evaluation: { checks, limits } }) => {
|
|
411
|
+
const wilson = finding(checks, "wilson");
|
|
412
|
+
if (wilson === void 0 || wilson.passed || wilson.observed === null || limits.t === null) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
if (!timeChecksPass(checks)) return null;
|
|
416
|
+
return {
|
|
417
|
+
code: "HINT_SLOW_SHARE",
|
|
418
|
+
params: { share: wilson.observed, limit: wilson.limit, t: limits.t }
|
|
419
|
+
};
|
|
420
|
+
},
|
|
421
|
+
({ evaluation: { result, checks } }) => {
|
|
422
|
+
const median = finding(checks, "median");
|
|
423
|
+
if (result !== "fail" || median === void 0 || finding(checks, "percentile") !== void 0) {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
return { code: "HINT_MEDIAN_ONLY", params: { n: median.n } };
|
|
427
|
+
},
|
|
428
|
+
({ evaluation: { result, muted } }) => result === "fail" && muted !== null && !muted.expired ? { code: "HINT_MUTED", params: {} } : null,
|
|
429
|
+
({ count, fromFailedTests }) => count > 0 && fromFailedTests * 2 >= count ? { code: "HINT_FAILED_TESTS", params: { share: roundRatio(fromFailedTests / count) } } : null,
|
|
430
|
+
({ evaluation: { result, checks } }) => {
|
|
431
|
+
if (result !== "pass") return null;
|
|
432
|
+
const headroom = keyHeadroom(checks);
|
|
433
|
+
if (headroom === null || headroom === Infinity || headroom < NEAR_LIMIT_USAGE) return null;
|
|
434
|
+
const ordered = [...checks].sort(
|
|
435
|
+
(a, b) => RULE_ORDER.indexOf(a.rule) - RULE_ORDER.indexOf(b.rule)
|
|
436
|
+
);
|
|
437
|
+
const top = ordered.find((c) => c.usage === headroom);
|
|
438
|
+
if (top === void 0 || top.usage === null) return null;
|
|
439
|
+
return { code: "HINT_NEAR_LIMIT", params: { rule: top.rule, usage: top.usage } };
|
|
440
|
+
}
|
|
441
|
+
];
|
|
442
|
+
function keyHints(facts, options) {
|
|
443
|
+
const hints = [];
|
|
444
|
+
for (const rule of RULES) {
|
|
445
|
+
const hint = rule(facts, options);
|
|
446
|
+
if (hint !== null) hints.push(hint);
|
|
447
|
+
if (hints.length === MAX_HINTS) break;
|
|
448
|
+
}
|
|
449
|
+
return hints;
|
|
450
|
+
}
|
|
451
|
+
|
|
259
452
|
// src/core/report/issues.ts
|
|
260
453
|
function collapseIssues(issues) {
|
|
261
454
|
const result = [];
|
|
@@ -275,13 +468,18 @@ function collapseIssues(issues) {
|
|
|
275
468
|
}
|
|
276
469
|
|
|
277
470
|
// src/core/report/build-run-report.ts
|
|
278
|
-
|
|
471
|
+
var MAX_VIOLATED_KEYS = 10;
|
|
472
|
+
function compareText3(a, b) {
|
|
279
473
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
280
474
|
}
|
|
281
475
|
function compareSlowest(a, b) {
|
|
282
|
-
return b.duration - a.duration ||
|
|
476
|
+
return b.duration - a.duration || compareText3(a.test.file, b.test.file) || a.test.line - b.test.line || a.test.repeatEachIndex - b.test.repeatEachIndex;
|
|
283
477
|
}
|
|
284
|
-
function buildAggregate(stats,
|
|
478
|
+
function buildAggregate(stats, evaluated, rawUrls, hintOptions) {
|
|
479
|
+
const evaluation = {
|
|
480
|
+
...structuredClone(evaluated),
|
|
481
|
+
checks: withUsage(evaluated.checks)
|
|
482
|
+
};
|
|
285
483
|
return {
|
|
286
484
|
...stats,
|
|
287
485
|
statuses: { ...stats.statuses },
|
|
@@ -297,7 +495,11 @@ function buildAggregate(stats, evaluation, rawUrls) {
|
|
|
297
495
|
])
|
|
298
496
|
)
|
|
299
497
|
},
|
|
300
|
-
ttfb: stats.ttfb === null ? null : {
|
|
498
|
+
ttfb: stats.ttfb === null ? null : {
|
|
499
|
+
p50: roundMs(stats.ttfb.p50),
|
|
500
|
+
p95: roundMs(stats.ttfb.p95),
|
|
501
|
+
otherP50: stats.ttfb.otherP50 === null ? null : roundMs(stats.ttfb.otherP50)
|
|
502
|
+
},
|
|
301
503
|
// Raw URLs only with report.rawUrls (D-11, 02-REQ-16).
|
|
302
504
|
slowest: stats.slowest.map(({ url, ...sample }) => ({
|
|
303
505
|
...sample,
|
|
@@ -306,16 +508,22 @@ function buildAggregate(stats, evaluation, rawUrls) {
|
|
|
306
508
|
...rawUrls && url !== void 0 ? { url } : {}
|
|
307
509
|
})).sort(compareSlowest),
|
|
308
510
|
topTests: stats.topTests.map((t) => ({ ...t })).sort(
|
|
309
|
-
(a, b) => b.sampleCount - a.sampleCount ||
|
|
511
|
+
(a, b) => b.sampleCount - a.sampleCount || compareText3(a.file, b.file) || a.line - b.line || compareText3(a.title, b.title) || compareText3(a.project, b.project)
|
|
310
512
|
),
|
|
311
513
|
samples: {
|
|
312
514
|
durations: stats.samples.durations.map(roundMs).sort((a, b) => a - b),
|
|
313
515
|
sampled: stats.samples.sampled
|
|
314
516
|
},
|
|
315
|
-
evaluation
|
|
517
|
+
evaluation,
|
|
518
|
+
// Edges are constants of the scale, not rounded (08-REQ-34).
|
|
519
|
+
histogram: stats.histogram === null ? null : {
|
|
520
|
+
edges: [...stats.histogram.edges],
|
|
521
|
+
counts: [...stats.histogram.counts]
|
|
522
|
+
},
|
|
523
|
+
hints: keyHints({ ...stats, evaluation }, hintOptions)
|
|
316
524
|
};
|
|
317
525
|
}
|
|
318
|
-
function buildAggregates(kind, aggregates, perKey, rawUrls) {
|
|
526
|
+
function buildAggregates(kind, aggregates, perKey, rawUrls, hintOptions) {
|
|
319
527
|
for (const key of Object.keys(perKey)) {
|
|
320
528
|
if (!Object.hasOwn(aggregates, key)) {
|
|
321
529
|
throw new Error(`buildRunReport: evaluation for unknown ${kind} key "${key}"`);
|
|
@@ -328,14 +536,55 @@ function buildAggregates(kind, aggregates, perKey, rawUrls) {
|
|
|
328
536
|
if (stats === void 0 || evaluation === void 0) {
|
|
329
537
|
throw new Error(`buildRunReport: no evaluation for ${kind} key "${key}"`);
|
|
330
538
|
}
|
|
331
|
-
result[key] = buildAggregate(stats, evaluation, rawUrls);
|
|
539
|
+
result[key] = buildAggregate(stats, evaluation, rawUrls, hintOptions);
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
function buildStepAggregates(aggregates, perKey, hintOptions) {
|
|
544
|
+
const common = buildAggregates("step", aggregates, perKey, false, hintOptions);
|
|
545
|
+
const result = {};
|
|
546
|
+
for (const [key, aggregate] of Object.entries(common)) {
|
|
547
|
+
const stats = aggregates[key];
|
|
548
|
+
result[key] = {
|
|
549
|
+
...aggregate,
|
|
550
|
+
location: stats?.location == null ? null : { ...stats.location },
|
|
551
|
+
stepErrorsFromFailedTests: stats?.stepErrorsFromFailedTests ?? 0
|
|
552
|
+
};
|
|
332
553
|
}
|
|
333
554
|
return result;
|
|
334
555
|
}
|
|
556
|
+
function buildTestBreakdown(breakdown, endpoints) {
|
|
557
|
+
if (breakdown === null) return null;
|
|
558
|
+
const tests = breakdown.tests.map(({ keys, topKeys, ...test }) => {
|
|
559
|
+
const violated = keys.filter((key) => endpoints[key]?.evaluation.result === "fail").sort(compareText3);
|
|
560
|
+
return {
|
|
561
|
+
...test,
|
|
562
|
+
topKeys: topKeys.map((k) => ({ ...k })),
|
|
563
|
+
violatedKeys: violated.slice(0, MAX_VIOLATED_KEYS),
|
|
564
|
+
violatedKeyCount: violated.length
|
|
565
|
+
};
|
|
566
|
+
});
|
|
567
|
+
return {
|
|
568
|
+
tests,
|
|
569
|
+
omitted: breakdown.omitted,
|
|
570
|
+
waterfalls: structuredClone(breakdown.waterfalls)
|
|
571
|
+
};
|
|
572
|
+
}
|
|
335
573
|
function buildRunReport(input) {
|
|
336
574
|
const { meta, aggregates, evaluation } = input;
|
|
337
575
|
const rawUrls = input.config.report?.rawUrls === true;
|
|
338
|
-
const kindOrder = { api: 0,
|
|
576
|
+
const kindOrder = { api: 0, step: 1 };
|
|
577
|
+
const hintOptions = {
|
|
578
|
+
errorStatuses: input.config.checks?.errors?.statuses ?? perfDefaults.checks.errors.statuses,
|
|
579
|
+
hardLimitFactor: input.config.gate?.hardLimitFactor === void 0 ? perfDefaults.gate.hardLimitFactor : input.config.gate.hardLimitFactor
|
|
580
|
+
};
|
|
581
|
+
const endpoints = buildAggregates(
|
|
582
|
+
"api",
|
|
583
|
+
aggregates.endpoints,
|
|
584
|
+
evaluation.perKey.api,
|
|
585
|
+
rawUrls,
|
|
586
|
+
hintOptions
|
|
587
|
+
);
|
|
339
588
|
return {
|
|
340
589
|
schemaVersion: SCHEMA_VERSIONS.runReport,
|
|
341
590
|
tool: { ...meta.tool },
|
|
@@ -347,9 +596,11 @@ function buildRunReport(input) {
|
|
|
347
596
|
configDir: meta.configDir,
|
|
348
597
|
config: structuredClone(input.config),
|
|
349
598
|
normalization: input.normalization,
|
|
599
|
+
stepNormalization: input.stepNormalization,
|
|
350
600
|
ci: meta.ci === null ? null : { ...meta.ci },
|
|
351
601
|
host: { ...meta.host },
|
|
352
602
|
playwright: { ...meta.playwright },
|
|
603
|
+
passes: input.passes === void 0 ? { planned: 1, completed: 1, failed: [] } : { ...input.passes, failed: [...input.passes.failed].sort((a, b) => a - b) },
|
|
353
604
|
runConditions: structuredClone(input.runConditions),
|
|
354
605
|
tests: { ...input.tests },
|
|
355
606
|
evaluation: {
|
|
@@ -360,23 +611,731 @@ function buildRunReport(input) {
|
|
|
360
611
|
thresholdFiles: evaluation.thresholdFiles.map((file) => ({
|
|
361
612
|
...file,
|
|
362
613
|
generated: file.generated === null ? null : structuredClone(file.generated),
|
|
363
|
-
unseenKeys: [...file.unseenKeys].sort(
|
|
614
|
+
unseenKeys: [...file.unseenKeys].sort(compareText3)
|
|
364
615
|
})).sort((a, b) => kindOrder[a.kind] - kindOrder[b.kind]),
|
|
365
616
|
warnings: collapseIssues(input.warnings),
|
|
366
617
|
toolErrors: collapseIssues(input.toolErrors),
|
|
367
|
-
origins: aggregates.origins.map((o) => ({ ...o })).sort((a, b) =>
|
|
368
|
-
endpoints
|
|
369
|
-
|
|
618
|
+
origins: aggregates.origins.map((o) => ({ ...o })).sort((a, b) => compareText3(a.origin, b.origin)),
|
|
619
|
+
endpoints,
|
|
620
|
+
steps: buildStepAggregates(aggregates.steps, evaluation.perKey.step, hintOptions),
|
|
621
|
+
testBreakdown: buildTestBreakdown(aggregates.testBreakdown, endpoints)
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/core/report/next-hint.ts
|
|
626
|
+
function perfCommand(mode, env, command, platform) {
|
|
627
|
+
const vars = `PW_PERF_MODE=${mode}${env === null ? "" : ` PW_PERF_ENV=${env}`}`;
|
|
628
|
+
return `${platform === "win32" ? "npx cross-env " : ""}${vars} ${command}`;
|
|
629
|
+
}
|
|
630
|
+
function scriptCommand(pm, script) {
|
|
631
|
+
return pm === "yarn" ? `yarn ${script}` : `${pm} run ${script}`;
|
|
632
|
+
}
|
|
633
|
+
function plainCommand(pm) {
|
|
634
|
+
return pm === "pnpm" ? "pnpm exec playwright test" : pm === "yarn" ? "yarn playwright test" : "npx playwright test";
|
|
635
|
+
}
|
|
636
|
+
function packageManager(ctx) {
|
|
637
|
+
const agent = ctx.userAgent ?? "";
|
|
638
|
+
if (agent.startsWith("pnpm/")) return "pnpm";
|
|
639
|
+
if (agent.startsWith("yarn/")) return "yarn";
|
|
640
|
+
if (agent.startsWith("npm/")) return "npm";
|
|
641
|
+
if (ctx.lockFiles.pnpm) return "pnpm";
|
|
642
|
+
if (ctx.lockFiles.yarn) return "yarn";
|
|
643
|
+
return "npm";
|
|
644
|
+
}
|
|
645
|
+
function setsMode(script) {
|
|
646
|
+
return /\bPW_PERF_MODE=/u.test(script) || /\bpw-perf\b/u.test(script) || /\bplaywright-performance-regression\b/u.test(script);
|
|
647
|
+
}
|
|
648
|
+
function modeScript(scripts, mode, env) {
|
|
649
|
+
if (env !== null && Object.hasOwn(scripts, `perf:${mode}:${env}`)) return `perf:${mode}:${env}`;
|
|
650
|
+
if (Object.hasOwn(scripts, `perf:${mode}`)) return `perf:${mode}`;
|
|
651
|
+
const runs = (text) => text.includes(`PW_PERF_MODE=${mode}`) || new RegExp(`\\b(?:pw-perf|playwright-performance-regression) ${mode}\\b`, "u").test(text);
|
|
652
|
+
const hasEnv = (text) => env === null || text.includes(`PW_PERF_ENV=${env}`) || text.includes(`--env ${env}`);
|
|
653
|
+
for (const [name, text] of Object.entries(scripts)) {
|
|
654
|
+
if (runs(text) && hasEnv(text)) return name;
|
|
655
|
+
}
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
function suggestCommand(mode, ctx) {
|
|
659
|
+
if (ctx.viaCli) return `npx pw-perf ${mode}${ctx.env === null ? "" : ` --env ${ctx.env}`}`;
|
|
660
|
+
const pm = packageManager(ctx);
|
|
661
|
+
const event = ctx.lifecycleEvent;
|
|
662
|
+
if (event !== null && event !== "") {
|
|
663
|
+
const script = ctx.lifecycleScript ?? "";
|
|
664
|
+
if (!setsMode(script)) {
|
|
665
|
+
return perfCommand(mode, ctx.env, scriptCommand(pm, event), ctx.platform);
|
|
666
|
+
}
|
|
667
|
+
const own = ctx.scripts === null ? null : modeScript(ctx.scripts, mode, ctx.env);
|
|
668
|
+
if (own !== null) return scriptCommand(pm, own);
|
|
669
|
+
return perfCommand(mode, ctx.env, scriptCommand(pm, event), ctx.platform);
|
|
670
|
+
}
|
|
671
|
+
return perfCommand(mode, ctx.env, plainCommand(pm), ctx.platform);
|
|
672
|
+
}
|
|
673
|
+
function nextHint(input) {
|
|
674
|
+
const { report, commands, written } = input;
|
|
675
|
+
if (report.toolErrors.length > 0) return null;
|
|
676
|
+
const measured = Object.keys(report.endpoints).length > 0 || Object.keys(report.steps).length > 0;
|
|
677
|
+
if (!measured) {
|
|
678
|
+
return `nothing was measured: check use.baseURL and run.projects, then run ${commands.check}`;
|
|
679
|
+
}
|
|
680
|
+
if (report.mode === "thresholds") {
|
|
681
|
+
if (written.length === 0) return null;
|
|
682
|
+
const files = written.map((f) => `${f.name} (${String(f.entries)} ${f.entries === 1 ? "key" : "keys"})`).join(" and ");
|
|
683
|
+
const local = report.ci === null ? "; for CI, derive them on the CI machines (docs/thresholds.md)" : "";
|
|
684
|
+
return `commit ${files}${local}`;
|
|
685
|
+
}
|
|
686
|
+
if (report.warnings.some((w) => w.code === "THRESHOLDS_FILE_MISSING")) {
|
|
687
|
+
return `derive thresholds: ${commands.thresholds}`;
|
|
688
|
+
}
|
|
689
|
+
if (report.evaluation.status === "failed") {
|
|
690
|
+
return `open the report; if the slowdown is intended, derive thresholds again: ${commands.thresholds}`;
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/core/check/estimate.ts
|
|
696
|
+
function formatDuration(ms) {
|
|
697
|
+
if (ms < 6e4) return "< 1 min";
|
|
698
|
+
const minutes = Math.ceil(ms / 6e4);
|
|
699
|
+
if (minutes < 60) return `${String(minutes)} min`;
|
|
700
|
+
return `${String(Math.floor(minutes / 60))} h ${String(minutes % 60)} min`;
|
|
701
|
+
}
|
|
702
|
+
function estimateText(input) {
|
|
703
|
+
const mean = input.meanMs;
|
|
704
|
+
if (mean === null) return "not available (no measured test ran)";
|
|
705
|
+
const run = (passes) => passes * (input.setupMs + input.tests * mean);
|
|
706
|
+
const seconds = (Math.round(mean / 100) / 10).toFixed(1);
|
|
707
|
+
return `measurement run ≈ ${formatDuration(run(input.passesTest))} (${String(input.tests)} tests × ${String(input.passesTest)} passes × ${seconds} s), thresholds run ≈ ${formatDuration(run(input.passesThresholds))} (× ${String(input.passesThresholds)} passes), 1 worker`;
|
|
708
|
+
}
|
|
709
|
+
var DEFAULT_TEST_MS = 3e4;
|
|
710
|
+
function msPerTest(report) {
|
|
711
|
+
const executions = report.tests.expected + report.tests.unexpected + report.tests.flaky;
|
|
712
|
+
const wall = Date.parse(report.finishedAt) - Date.parse(report.startedAt);
|
|
713
|
+
if (executions <= 0 || !Number.isFinite(wall) || wall < 0) return null;
|
|
714
|
+
return wall / executions;
|
|
715
|
+
}
|
|
716
|
+
function startEstimate(input) {
|
|
717
|
+
const ms = input.msPerTest ?? DEFAULT_TEST_MS;
|
|
718
|
+
const note = input.msPerTest === null ? "30 s per test, no earlier run" : "from the last run";
|
|
719
|
+
return `≈ ${formatDuration(input.tests * input.passes * ms)} (${note})`;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/core/check/random-host.ts
|
|
723
|
+
var SHOWN = 5;
|
|
724
|
+
function generatedLabel(label) {
|
|
725
|
+
if (/[0-9]{3,}/u.test(label)) return true;
|
|
726
|
+
const alnum = /^[a-z0-9]{8,}$/u.test(label);
|
|
727
|
+
const digits = (label.match(/[0-9]/gu) ?? []).length;
|
|
728
|
+
const letters = (label.match(/[a-z]/gu) ?? []).length;
|
|
729
|
+
if (alnum && digits >= 2 && letters >= 2) return true;
|
|
730
|
+
return ID_PATTERNS.uuid.test(label) || ID_PATTERNS.hex.test(label);
|
|
731
|
+
}
|
|
732
|
+
function isIp(host) {
|
|
733
|
+
return /^[0-9.]+$/u.test(host) || host.startsWith("[");
|
|
734
|
+
}
|
|
735
|
+
function proposePattern(candidate) {
|
|
736
|
+
let url;
|
|
737
|
+
try {
|
|
738
|
+
url = new URL(candidate.origin);
|
|
739
|
+
} catch {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
const host = url.hostname.toLowerCase();
|
|
743
|
+
if (host === "localhost" || isIp(host)) return null;
|
|
744
|
+
const labels = host.split(".");
|
|
745
|
+
const last = labels.length <= 2 ? 1 : labels.length - 2;
|
|
746
|
+
const at = labels.slice(0, last).findIndex(generatedLabel);
|
|
747
|
+
if (at < 0) return null;
|
|
748
|
+
const label = labels[at] ?? "";
|
|
749
|
+
const digit = label.search(/[0-9]/u);
|
|
750
|
+
const prefix = digit < 0 ? "" : label.slice(0, digit);
|
|
751
|
+
const star = prefix.length >= 2 && /^[a-z-]+$/u.test(prefix) ? `${prefix}*` : "*";
|
|
752
|
+
const parts = labels.map((part, i) => i === at ? star : part);
|
|
753
|
+
const port = url.port === "" ? "" : `:${url.port}`;
|
|
754
|
+
const pattern = `${url.protocol}//${parts.join(".")}${port}`;
|
|
755
|
+
const name = candidate.base ? "" : /[a-z]{2,}/u.exec(host)?.[0] ?? "backend";
|
|
756
|
+
return { pattern, label: name };
|
|
757
|
+
}
|
|
758
|
+
function randomHostIssue(candidates) {
|
|
759
|
+
const proposals = /* @__PURE__ */ new Map();
|
|
760
|
+
for (const candidate of candidates) {
|
|
761
|
+
const proposed = proposePattern(candidate);
|
|
762
|
+
if (proposed === null) continue;
|
|
763
|
+
const entry = proposals.get(proposed.pattern);
|
|
764
|
+
if (entry === void 0) {
|
|
765
|
+
proposals.set(proposed.pattern, { label: proposed.label, origins: [candidate.origin] });
|
|
766
|
+
} else if (!entry.origins.includes(candidate.origin)) {
|
|
767
|
+
entry.origins.push(candidate.origin);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (proposals.size === 0) return null;
|
|
771
|
+
const origins = [...new Set([...proposals.values()].flatMap((p) => p.origins))].sort();
|
|
772
|
+
const shown = origins.slice(0, SHOWN).join(", ") + (origins.length > SHOWN ? ", …" : "");
|
|
773
|
+
const object = [...proposals.keys()].sort().map((pattern) => `'${pattern}': '${proposals.get(pattern)?.label ?? ""}'`).join(", ");
|
|
774
|
+
return {
|
|
775
|
+
code: "CHECK_RANDOM_HOST",
|
|
776
|
+
message: `${String(origins.length)} ${origins.length === 1 ? "origin looks" : "origins look"} generated per environment: ${shown}; their keys or the normalization fingerprint change on every instance.`,
|
|
777
|
+
hint: `Add host patterns to keys.origins, e.g. { ${object} } (docs/dynamic-environments.md).`
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// src/core/steps/sanitize.ts
|
|
782
|
+
var UNTITLED = "(untitled)";
|
|
783
|
+
var MAX_SEGMENT_LENGTH = 200;
|
|
784
|
+
var EDGE = /* @__PURE__ */ new Set([..."\"'`()[]{}<>#,.;:!?"]);
|
|
785
|
+
var URL_TRAILING = /[.,;:!?)\]}]+$/u;
|
|
786
|
+
var URL_RE = /[A-Za-z][A-Za-z0-9+.-]*:\/\/[^\s"'`<>]+|www\.[^\s"'`<>]+/giu;
|
|
787
|
+
var JWT_RE = /eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/gu;
|
|
788
|
+
var AUTH_SCHEMES = /* @__PURE__ */ new Set(["bearer", "basic", "token"]);
|
|
789
|
+
var SECRET_NAMES = [
|
|
790
|
+
"authorization",
|
|
791
|
+
"access_key",
|
|
792
|
+
"api_key",
|
|
793
|
+
"api-key",
|
|
794
|
+
"apikey",
|
|
795
|
+
"password",
|
|
796
|
+
"session",
|
|
797
|
+
"passwd",
|
|
798
|
+
"secret",
|
|
799
|
+
"cookie",
|
|
800
|
+
"token",
|
|
801
|
+
"auth",
|
|
802
|
+
"pass",
|
|
803
|
+
"otp",
|
|
804
|
+
"pin",
|
|
805
|
+
"pwd",
|
|
806
|
+
"sid"
|
|
807
|
+
];
|
|
808
|
+
var SECRET_PAIR_RE = new RegExp(
|
|
809
|
+
`(?<=^|[\\s_-])(?:${SECRET_NAMES.join("|")})\\s*[=:]\\s*(\\S+)`,
|
|
810
|
+
"giu"
|
|
811
|
+
);
|
|
812
|
+
var EMAIL_RE = /[^\s@"'`<>()[\]]+@[^\s@"'`<>()[\]]+\.[A-Za-z]{2,}/gu;
|
|
813
|
+
var PHONE_RE = /\+[0-9][0-9 ().-]{6,}[0-9]/gu;
|
|
814
|
+
var IPV4_RE = /^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/u;
|
|
815
|
+
var LONG_DIGITS_RE = /^[0-9]{9,}$/u;
|
|
816
|
+
var TEMPLATE_RE = /\$\{[^}]*\}|\{\{[^}]*\}\}/gu;
|
|
817
|
+
var DATETIME_RE = /^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:\.[0-9]+)?)?(?:Z|[+-][0-9]{2}:?[0-9]{2})?$/u;
|
|
818
|
+
var DATE_RES = [
|
|
819
|
+
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/u,
|
|
820
|
+
/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/u,
|
|
821
|
+
/^[0-9]{1,2}[./-][0-9]{1,2}[./-][0-9]{2,4}$/u
|
|
822
|
+
];
|
|
823
|
+
var TIME_RE = /^[0-9]{1,2}:[0-9]{2}(?::[0-9]{2})?$/u;
|
|
824
|
+
var MERIDIEM_RE = /^(?:AM|PM)$/iu;
|
|
825
|
+
var NUMBER_RES = [
|
|
826
|
+
/^[+-]?[0-9]+(?:[.,][0-9]+)+[A-Za-zµ%°]{0,4}$/u,
|
|
827
|
+
/^[+-]?[0-9]+[A-Za-zµ%°]{1,4}$/u
|
|
828
|
+
];
|
|
829
|
+
var QUOTES = /* @__PURE__ */ new Map([
|
|
830
|
+
['"', '"'],
|
|
831
|
+
["'", "'"],
|
|
832
|
+
["`", "`"],
|
|
833
|
+
["“", "”"],
|
|
834
|
+
["„", "”"],
|
|
835
|
+
["‘", "’"],
|
|
836
|
+
["«", "»"]
|
|
837
|
+
]);
|
|
838
|
+
var QUOTE_OPEN_AFTER = /* @__PURE__ */ new Set([" ", "(", "[", "{", ":", "="]);
|
|
839
|
+
var QUOTE_CLOSE_BEFORE = /* @__PURE__ */ new Set([" ", ".", ",", ";", ":", "!", "?", ")", "]", "}"]);
|
|
840
|
+
var Masked = class {
|
|
841
|
+
text;
|
|
842
|
+
mask;
|
|
843
|
+
constructor(text) {
|
|
844
|
+
this.text = text;
|
|
845
|
+
this.mask = Array.from({ length: text.length }, () => false);
|
|
846
|
+
}
|
|
847
|
+
/** True when any code unit in [start, end) is protected. */
|
|
848
|
+
protectedIn(start, end) {
|
|
849
|
+
for (let i = start; i < end; i++) if (this.mask[i] === true) return true;
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
/** Applies replacements, given in any order and not overlapping. */
|
|
853
|
+
apply(replacements) {
|
|
854
|
+
for (const r of [...replacements].sort((a, b) => b.start - a.start)) {
|
|
855
|
+
this.text = this.text.slice(0, r.start) + r.text + this.text.slice(r.end);
|
|
856
|
+
const flags = Array.from({ length: r.text.length }, () => r.protect);
|
|
857
|
+
this.mask.splice(r.start, r.end - r.start, ...flags);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/** Maximal runs of unprotected code units. */
|
|
861
|
+
freeRuns() {
|
|
862
|
+
const runs = [];
|
|
863
|
+
let start = -1;
|
|
864
|
+
for (let i = 0; i <= this.text.length; i++) {
|
|
865
|
+
const free = i < this.text.length && this.mask[i] !== true;
|
|
866
|
+
if (free && start < 0) start = i;
|
|
867
|
+
if (!free && start >= 0) {
|
|
868
|
+
runs.push({ start, text: this.text.slice(start, i) });
|
|
869
|
+
start = -1;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return runs;
|
|
873
|
+
}
|
|
874
|
+
/** Words (maximal runs of non-space characters) with their cores (06-REQ-34). */
|
|
875
|
+
words() {
|
|
876
|
+
const result = [];
|
|
877
|
+
const re = /[^ ]+/gu;
|
|
878
|
+
for (const match of this.text.matchAll(re)) {
|
|
879
|
+
const start = match.index;
|
|
880
|
+
const end = start + match[0].length;
|
|
881
|
+
let coreStart = start;
|
|
882
|
+
let coreEnd = end;
|
|
883
|
+
while (coreStart < coreEnd && EDGE.has(this.text[coreStart] ?? "")) coreStart++;
|
|
884
|
+
while (coreEnd > coreStart && EDGE.has(this.text[coreEnd - 1] ?? "")) coreEnd--;
|
|
885
|
+
result.push({ start, end, coreStart, coreEnd });
|
|
886
|
+
}
|
|
887
|
+
return result;
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
function replaceMatches(s, re, placeholder, pick = (m) => ({
|
|
891
|
+
from: 0,
|
|
892
|
+
to: m[0].length
|
|
893
|
+
})) {
|
|
894
|
+
const replacements = [];
|
|
895
|
+
for (const run of s.freeRuns()) {
|
|
896
|
+
for (const match of run.text.matchAll(re)) {
|
|
897
|
+
const span = pick(match);
|
|
898
|
+
if (span === null || span.to <= span.from) continue;
|
|
899
|
+
const start = run.start + match.index + span.from;
|
|
900
|
+
replacements.push({
|
|
901
|
+
start,
|
|
902
|
+
end: run.start + match.index + span.to,
|
|
903
|
+
text: placeholder,
|
|
904
|
+
protect: true
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
s.apply(replacements);
|
|
909
|
+
return replacements.length;
|
|
910
|
+
}
|
|
911
|
+
function replaceCores(s, test) {
|
|
912
|
+
const replacements = [];
|
|
913
|
+
for (const word of s.words()) {
|
|
914
|
+
if (word.coreEnd <= word.coreStart || s.protectedIn(word.coreStart, word.coreEnd)) continue;
|
|
915
|
+
const placeholder = test(s.text.slice(word.coreStart, word.coreEnd));
|
|
916
|
+
if (placeholder === null) continue;
|
|
917
|
+
replacements.push({
|
|
918
|
+
start: word.coreStart,
|
|
919
|
+
end: word.coreEnd,
|
|
920
|
+
text: placeholder,
|
|
921
|
+
protect: true
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
s.apply(replacements);
|
|
925
|
+
return replacements.length;
|
|
926
|
+
}
|
|
927
|
+
function cleanup(title) {
|
|
928
|
+
const text = title.normalize("NFC").replace(new RegExp("\\p{Cf}", "gu"), "").replace(/[\p{Cc}\p{White_Space}]+/gu, " ").trim().replace(/[›»]/gu, ">");
|
|
929
|
+
return text === "" ? null : text;
|
|
930
|
+
}
|
|
931
|
+
function privacy(s) {
|
|
932
|
+
const fired = [];
|
|
933
|
+
const urls = replaceMatches(s, URL_RE, ":url", (m) => {
|
|
934
|
+
const trailing = URL_TRAILING.exec(m[0]);
|
|
935
|
+
return { from: 0, to: m[0].length - (trailing?.[0].length ?? 0) };
|
|
936
|
+
});
|
|
937
|
+
if (urls > 0) fired.push("url");
|
|
938
|
+
if (replaceMatches(s, JWT_RE, ":secret") > 0) fired.push("jwt");
|
|
939
|
+
{
|
|
940
|
+
const words = s.words();
|
|
941
|
+
const replacements = [];
|
|
942
|
+
for (let i = 0; i + 1 < words.length; i++) {
|
|
943
|
+
const word = words[i];
|
|
944
|
+
const next = words[i + 1];
|
|
945
|
+
if (word === void 0 || next === void 0) continue;
|
|
946
|
+
if (s.protectedIn(word.coreStart, word.coreEnd)) continue;
|
|
947
|
+
const core = s.text.slice(word.coreStart, word.coreEnd).toLowerCase();
|
|
948
|
+
if (!AUTH_SCHEMES.has(core) || s.protectedIn(next.start, next.end)) continue;
|
|
949
|
+
replacements.push({ start: next.start, end: next.end, text: ":secret", protect: true });
|
|
950
|
+
i++;
|
|
951
|
+
}
|
|
952
|
+
s.apply(replacements);
|
|
953
|
+
if (replacements.length > 0) fired.push("auth-scheme");
|
|
954
|
+
}
|
|
955
|
+
const pairs = replaceMatches(s, SECRET_PAIR_RE, ":secret", (m) => {
|
|
956
|
+
const value = m[1] ?? "";
|
|
957
|
+
return { from: m[0].length - value.length, to: m[0].length };
|
|
958
|
+
});
|
|
959
|
+
if (pairs > 0) fired.push("secret-pair");
|
|
960
|
+
replaceMatches(s, EMAIL_RE, ":email");
|
|
961
|
+
replaceMatches(s, PHONE_RE, ":phone");
|
|
962
|
+
replaceCores(s, (core) => IPV4_RE.test(core) ? ":ip" : null);
|
|
963
|
+
{
|
|
964
|
+
const replacements = [];
|
|
965
|
+
for (const word of s.words()) {
|
|
966
|
+
const core = s.text.slice(word.coreStart, word.coreEnd);
|
|
967
|
+
if (!core.startsWith("/")) continue;
|
|
968
|
+
const cut = core.search(/[?#]/u);
|
|
969
|
+
if (cut < 0) continue;
|
|
970
|
+
const start = word.coreStart + cut;
|
|
971
|
+
if (s.protectedIn(start, word.coreEnd)) continue;
|
|
972
|
+
replacements.push({ start, end: word.coreEnd, text: "?:query", protect: true });
|
|
973
|
+
}
|
|
974
|
+
s.apply(replacements);
|
|
975
|
+
}
|
|
976
|
+
replaceCores(
|
|
977
|
+
s,
|
|
978
|
+
(core) => ID_PATTERNS.uuid.test(core) || ID_PATTERNS.hex.test(core) || ID_PATTERNS.token.test(core) || ID_PATTERNS.mixed.test(core) || LONG_DIGITS_RE.test(core) ? ":id" : null
|
|
979
|
+
);
|
|
980
|
+
return fired;
|
|
981
|
+
}
|
|
982
|
+
function redactQuotes(s) {
|
|
983
|
+
const text = s.text;
|
|
984
|
+
const replacements = [];
|
|
985
|
+
let i = 0;
|
|
986
|
+
while (i < text.length) {
|
|
987
|
+
const open = text[i] ?? "";
|
|
988
|
+
const close = QUOTES.get(open);
|
|
989
|
+
const opensHere = close !== void 0 && (i === 0 || QUOTE_OPEN_AFTER.has(text[i - 1] ?? ""));
|
|
990
|
+
if (!opensHere) {
|
|
991
|
+
i++;
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
let j = i + 1;
|
|
995
|
+
let found = -1;
|
|
996
|
+
while (j < text.length) {
|
|
997
|
+
if (text[j] === close) {
|
|
998
|
+
const after = text[j + 1];
|
|
999
|
+
if (after === void 0 || QUOTE_CLOSE_BEFORE.has(after)) {
|
|
1000
|
+
found = j;
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
j++;
|
|
1005
|
+
}
|
|
1006
|
+
if (found > i + 1) {
|
|
1007
|
+
replacements.push({ start: i + 1, end: found, text: ":value", protect: true });
|
|
1008
|
+
i = found + 1;
|
|
1009
|
+
} else {
|
|
1010
|
+
i++;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
s.apply(replacements);
|
|
1014
|
+
}
|
|
1015
|
+
function replaceDates(s) {
|
|
1016
|
+
const words = s.words();
|
|
1017
|
+
const replacements = [];
|
|
1018
|
+
const core = (w) => s.text.slice(w.coreStart, w.coreEnd);
|
|
1019
|
+
const free = (w) => w.coreEnd > w.coreStart && !s.protectedIn(w.coreStart, w.coreEnd);
|
|
1020
|
+
for (let i = 0; i < words.length; i++) {
|
|
1021
|
+
const word = words[i];
|
|
1022
|
+
if (word === void 0 || !free(word)) continue;
|
|
1023
|
+
const next = words[i + 1];
|
|
1024
|
+
if (next !== void 0 && free(next) && word.coreEnd === word.end && next.coreStart === next.start) {
|
|
1025
|
+
const pair = `${core(word)} ${core(next)}`;
|
|
1026
|
+
const placeholder2 = DATETIME_RE.test(pair) ? ":datetime" : TIME_RE.test(core(word)) && MERIDIEM_RE.test(core(next)) ? ":time" : null;
|
|
1027
|
+
if (placeholder2 !== null) {
|
|
1028
|
+
replacements.push({
|
|
1029
|
+
start: word.coreStart,
|
|
1030
|
+
end: next.coreEnd,
|
|
1031
|
+
text: placeholder2,
|
|
1032
|
+
protect: true
|
|
1033
|
+
});
|
|
1034
|
+
i++;
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
const one = core(word);
|
|
1039
|
+
const placeholder = DATETIME_RE.test(one) ? ":datetime" : DATE_RES.some((re) => re.test(one)) ? ":date" : TIME_RE.test(one) ? ":time" : null;
|
|
1040
|
+
if (placeholder !== null) {
|
|
1041
|
+
replacements.push({
|
|
1042
|
+
start: word.coreStart,
|
|
1043
|
+
end: word.coreEnd,
|
|
1044
|
+
text: placeholder,
|
|
1045
|
+
protect: true
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
s.apply(replacements);
|
|
1050
|
+
}
|
|
1051
|
+
function replaceIds(s, isId) {
|
|
1052
|
+
const replacements = [];
|
|
1053
|
+
for (const word of s.words()) {
|
|
1054
|
+
const core = s.text.slice(word.coreStart, word.coreEnd);
|
|
1055
|
+
if (core.startsWith("/")) {
|
|
1056
|
+
let offset = word.coreStart;
|
|
1057
|
+
for (const part of core.split("/")) {
|
|
1058
|
+
const end = offset + part.length;
|
|
1059
|
+
if (part !== "" && !s.protectedIn(offset, end)) {
|
|
1060
|
+
const placeholder2 = isId(part);
|
|
1061
|
+
if (placeholder2 !== null) {
|
|
1062
|
+
replacements.push({ start: offset, end, text: placeholder2, protect: true });
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
offset = end + 1;
|
|
1066
|
+
}
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
if (core === "" || s.protectedIn(word.coreStart, word.coreEnd)) continue;
|
|
1070
|
+
const placeholder = isId(core);
|
|
1071
|
+
if (placeholder !== null) {
|
|
1072
|
+
replacements.push({
|
|
1073
|
+
start: word.coreStart,
|
|
1074
|
+
end: word.coreEnd,
|
|
1075
|
+
text: placeholder,
|
|
1076
|
+
protect: true
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
s.apply(replacements);
|
|
1081
|
+
}
|
|
1082
|
+
function stability(s, opts, isId) {
|
|
1083
|
+
replaceMatches(s, TEMPLATE_RE, ":value");
|
|
1084
|
+
if (opts.redactQuotedValues) redactQuotes(s);
|
|
1085
|
+
replaceDates(s);
|
|
1086
|
+
replaceCores(s, (core) => NUMBER_RES.some((re) => re.test(core)) ? ":num" : null);
|
|
1087
|
+
replaceIds(s, isId);
|
|
1088
|
+
}
|
|
1089
|
+
function limitLength(text) {
|
|
1090
|
+
const points = [...text];
|
|
1091
|
+
return points.length > MAX_SEGMENT_LENGTH ? `${points.slice(0, MAX_SEGMENT_LENGTH - 1).join("")}…` : text;
|
|
1092
|
+
}
|
|
1093
|
+
function createStepTitleSanitizer(opts) {
|
|
1094
|
+
const isId = compileIdMatcher({
|
|
1095
|
+
idPatterns: opts.idPatterns,
|
|
1096
|
+
extraIdPatterns: opts.extraIdPatterns
|
|
1097
|
+
});
|
|
1098
|
+
return (title) => {
|
|
1099
|
+
const cleaned = cleanup(title);
|
|
1100
|
+
if (cleaned === null) return { text: UNTITLED, redacted: [] };
|
|
1101
|
+
const s = new Masked(cleaned);
|
|
1102
|
+
const redacted = privacy(s);
|
|
1103
|
+
if (opts.normalizeTitles) stability(s, opts, isId);
|
|
1104
|
+
return { text: limitLength(s.text), redacted };
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/core/steps/collect.ts
|
|
1109
|
+
var STEP_SEPARATOR = " › ";
|
|
1110
|
+
var TEST_SEPARATOR = " » ";
|
|
1111
|
+
function matches(text, pattern) {
|
|
1112
|
+
return typeof pattern === "string" ? text.includes(pattern) : pattern.test(text);
|
|
1113
|
+
}
|
|
1114
|
+
function selected(stepPart, opts) {
|
|
1115
|
+
if (opts.include.length > 0 && !opts.include.some((p) => matches(stepPart, p))) return false;
|
|
1116
|
+
return !opts.exclude.some((p) => matches(stepPart, p));
|
|
1117
|
+
}
|
|
1118
|
+
function collectWith(steps, opts, sanitize) {
|
|
1119
|
+
const categories = new Set(opts.categories);
|
|
1120
|
+
const samples = [];
|
|
1121
|
+
const redactions = [];
|
|
1122
|
+
const walk = (nodes, path, depth) => {
|
|
1123
|
+
for (const node of nodes) {
|
|
1124
|
+
if (node.skipped) continue;
|
|
1125
|
+
if (!categories.has(node.category)) {
|
|
1126
|
+
walk(node.steps, path, depth);
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
const level = depth + 1;
|
|
1130
|
+
if (level > opts.maxDepth) continue;
|
|
1131
|
+
const title = sanitize(node.title);
|
|
1132
|
+
if (title.redacted.length > 0) {
|
|
1133
|
+
redactions.push({ rules: title.redacted, location: node.location });
|
|
1134
|
+
}
|
|
1135
|
+
const own = [...path, title.text];
|
|
1136
|
+
const stepPart = own.join(STEP_SEPARATOR);
|
|
1137
|
+
if (selected(stepPart, opts)) {
|
|
1138
|
+
const key = truncateKey(
|
|
1139
|
+
opts.groupBy === "test" ? `${opts.testPrefix}${TEST_SEPARATOR}${stepPart}` : stepPart
|
|
1140
|
+
);
|
|
1141
|
+
const unfinished = node.duration < 0;
|
|
1142
|
+
samples.push({
|
|
1143
|
+
key,
|
|
1144
|
+
duration: unfinished ? null : node.duration,
|
|
1145
|
+
endTime: unfinished ? null : node.startTime + node.duration,
|
|
1146
|
+
outcome: unfinished ? "unfinished" : node.hasError ? "error" : "ok",
|
|
1147
|
+
location: node.location
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
walk(node.steps, own, level);
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
walk(steps, [], 0);
|
|
1154
|
+
return { samples, redactions };
|
|
1155
|
+
}
|
|
1156
|
+
function stepTestPrefix(file, titles, sanitize) {
|
|
1157
|
+
return [file, ...titles.map((t) => sanitize(t).text)].join(STEP_SEPARATOR);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/core/steps/explosion.ts
|
|
1161
|
+
var EXAMPLES2 = 3;
|
|
1162
|
+
var QUOTE_CHARS = /* @__PURE__ */ new Set([..."\"'`“”„‘’«"]);
|
|
1163
|
+
var LOCATIONS = 5;
|
|
1164
|
+
function detectStepKeyExplosion(stepKeys) {
|
|
1165
|
+
const unique = [...new Set(stepKeys)].sort();
|
|
1166
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1167
|
+
for (const key of unique) {
|
|
1168
|
+
const words = key.split(" ");
|
|
1169
|
+
words.forEach((word, i) => {
|
|
1170
|
+
const template = words.map((w, j) => j === i ? "*" : w).join(" ");
|
|
1171
|
+
const quoted = QUOTE_CHARS.has(word[0] ?? "") || QUOTE_CHARS.has(word.at(-1) ?? "");
|
|
1172
|
+
const group = groups.get(template);
|
|
1173
|
+
if (group === void 0) groups.set(template, { keys: [key], quoted });
|
|
1174
|
+
else {
|
|
1175
|
+
group.keys.push(key);
|
|
1176
|
+
group.quoted ||= quoted;
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
const issues = [];
|
|
1181
|
+
for (const template of [...groups.keys()].sort()) {
|
|
1182
|
+
const group = groups.get(template);
|
|
1183
|
+
if (group === void 0 || group.keys.length < CARDINALITY_MIN_KEYS) continue;
|
|
1184
|
+
const examples = group.keys.slice(0, EXAMPLES2).join(", ");
|
|
1185
|
+
issues.push({
|
|
1186
|
+
code: "STEPS_HIGH_CARDINALITY",
|
|
1187
|
+
message: `${group.keys.length} step keys differ only in one word: ${template} (e.g. ${examples}).`,
|
|
1188
|
+
hint: `If the word is test data, keep it out of the step title, add a pattern to keys.extraIdPatterns or exclude the step with measure.steps.exclude${group.quoted ? "; for quoted values set measure.steps.redactQuotedValues to true" : ""}.`
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
if (unique.length > MAX_KEYS_WARNING) {
|
|
1192
|
+
issues.push({
|
|
1193
|
+
code: "STEPS_TOO_MANY_KEYS",
|
|
1194
|
+
message: `The run has ${unique.length} step keys, more than ${MAX_KEYS_WARNING}.`,
|
|
1195
|
+
hint: 'Measure fewer steps: keep measure.steps.categories at ["test.step"] or lower measure.steps.maxDepth.'
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
return issues;
|
|
1199
|
+
}
|
|
1200
|
+
function secretRedactedIssue(redactions) {
|
|
1201
|
+
if (redactions.length === 0) return null;
|
|
1202
|
+
const rules = new Set(redactions.flatMap((r) => r.rules));
|
|
1203
|
+
const names2 = [...rules].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1204
|
+
const locations = [
|
|
1205
|
+
...new Set(
|
|
1206
|
+
redactions.flatMap(
|
|
1207
|
+
(r) => r.location === null ? [] : [`${r.location.file}:${r.location.line}`]
|
|
1208
|
+
)
|
|
1209
|
+
)
|
|
1210
|
+
].sort((a, b) => {
|
|
1211
|
+
const [fa = "", la = "0"] = a.split(/:(?=[0-9]+$)/u);
|
|
1212
|
+
const [fb = "", lb = "0"] = b.split(/:(?=[0-9]+$)/u);
|
|
1213
|
+
return fa < fb ? -1 : fa > fb ? 1 : Number(la) - Number(lb);
|
|
1214
|
+
});
|
|
1215
|
+
const shown = locations.slice(0, LOCATIONS).join(", ");
|
|
1216
|
+
const n = redactions.length;
|
|
1217
|
+
return {
|
|
1218
|
+
code: "STEPS_SECRET_REDACTED",
|
|
1219
|
+
message: `${n} step ${n === 1 ? "title contains" : "titles contain"} a URL or a secret (rules: ${names2.join(", ")})${shown === "" ? "" : ` at ${shown}`}${locations.length > LOCATIONS ? ", …" : ""}; the keys show placeholders instead.`,
|
|
1220
|
+
hint: "Sensitive data in a step title also reaches Playwright reports and traces; remove it from the title."
|
|
370
1221
|
};
|
|
371
1222
|
}
|
|
1223
|
+
function noStepsIssue() {
|
|
1224
|
+
return {
|
|
1225
|
+
code: "STEPS_NONE_FOUND",
|
|
1226
|
+
message: "measure.steps is enabled, but the measured tests gave no step samples.",
|
|
1227
|
+
hint: "Check that the tests use test.step, and the measure.steps include, exclude and categories settings."
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// src/core/steps/fingerprint.ts
|
|
1232
|
+
var STEP_RULES_VERSION = 1;
|
|
1233
|
+
function stepNormalizationFingerprint(steps, keys) {
|
|
1234
|
+
return hashHex(
|
|
1235
|
+
stringifyStable({
|
|
1236
|
+
rulesVersion: STEP_RULES_VERSION,
|
|
1237
|
+
idPatterns: keys.idPatterns,
|
|
1238
|
+
extraIdPatterns: keys.extraIdPatterns.map(
|
|
1239
|
+
(p) => typeof p === "string" ? p : { regex: p.source, flags: p.flags }
|
|
1240
|
+
),
|
|
1241
|
+
categories: steps.categories,
|
|
1242
|
+
maxDepth: steps.maxDepth,
|
|
1243
|
+
groupBy: steps.groupBy,
|
|
1244
|
+
normalizeTitles: steps.normalizeTitles,
|
|
1245
|
+
redactQuotedValues: steps.redactQuotedValues
|
|
1246
|
+
})
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/reporter/steps.ts
|
|
1251
|
+
function toNodes(steps, relative) {
|
|
1252
|
+
return steps.map((step) => ({
|
|
1253
|
+
category: step.category,
|
|
1254
|
+
title: step.title,
|
|
1255
|
+
startTime: step.startTime.getTime(),
|
|
1256
|
+
duration: step.duration,
|
|
1257
|
+
hasError: step.error !== void 0 && step.error !== null,
|
|
1258
|
+
skipped: (step.annotations ?? []).some((a) => a.type === "skip"),
|
|
1259
|
+
location: step.location === void 0 ? null : { file: relative(step.location.file), line: step.location.line },
|
|
1260
|
+
steps: toNodes(step.steps, relative)
|
|
1261
|
+
}));
|
|
1262
|
+
}
|
|
1263
|
+
function testTitles(test) {
|
|
1264
|
+
const titles = [test.title];
|
|
1265
|
+
for (let s = test.parent; s?.type === "describe"; s = s.parent) {
|
|
1266
|
+
titles.unshift(s.title);
|
|
1267
|
+
}
|
|
1268
|
+
return titles;
|
|
1269
|
+
}
|
|
1270
|
+
var StepRecorder = class {
|
|
1271
|
+
cfg;
|
|
1272
|
+
sanitize;
|
|
1273
|
+
redactions = [];
|
|
1274
|
+
constructor(cfg) {
|
|
1275
|
+
this.cfg = cfg;
|
|
1276
|
+
this.sanitize = createStepTitleSanitizer({
|
|
1277
|
+
normalizeTitles: cfg.measure.steps.normalizeTitles,
|
|
1278
|
+
redactQuotedValues: cfg.measure.steps.redactQuotedValues,
|
|
1279
|
+
idPatterns: cfg.keys.idPatterns,
|
|
1280
|
+
extraIdPatterns: cfg.keys.extraIdPatterns
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
get enabled() {
|
|
1284
|
+
return this.cfg.measure.steps.enabled;
|
|
1285
|
+
}
|
|
1286
|
+
/** Step fingerprint of the run, or null while steps are off (06-REQ-25). */
|
|
1287
|
+
fingerprint() {
|
|
1288
|
+
return this.enabled ? stepNormalizationFingerprint(this.cfg.measure.steps, this.cfg.keys) : null;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Adds the step samples of one result, before endResult (08-REQ-40). Results of projects that
|
|
1292
|
+
* are not measured are counted as outside samples by the aggregator (06-REQ-19).
|
|
1293
|
+
*/
|
|
1294
|
+
record(aggregator, test, steps, meta, relative) {
|
|
1295
|
+
if (!this.enabled || steps === void 0 || steps.length === 0) return;
|
|
1296
|
+
const testPrefix = this.cfg.measure.steps.groupBy === "test" ? stepTestPrefix(meta.file, testTitles(test), this.sanitize) : "";
|
|
1297
|
+
const { samples, redactions } = collectWith(
|
|
1298
|
+
toNodes(steps, relative),
|
|
1299
|
+
{
|
|
1300
|
+
...this.cfg.measure.steps,
|
|
1301
|
+
idPatterns: this.cfg.keys.idPatterns,
|
|
1302
|
+
extraIdPatterns: this.cfg.keys.extraIdPatterns,
|
|
1303
|
+
testPrefix
|
|
1304
|
+
},
|
|
1305
|
+
this.sanitize
|
|
1306
|
+
);
|
|
1307
|
+
this.redactions.push(...redactions);
|
|
1308
|
+
samples.forEach((sample, ordinal) => {
|
|
1309
|
+
aggregator.addStep({ ...sample, test: meta, ordinal });
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
/** STEPS_* warnings of the run (06, chapter 8), after aggregation. */
|
|
1313
|
+
issues(stepKeys) {
|
|
1314
|
+
if (!this.enabled) return [];
|
|
1315
|
+
const issues = [];
|
|
1316
|
+
if (stepKeys.length === 0) issues.push(noStepsIssue());
|
|
1317
|
+
issues.push(...detectStepKeyExplosion(stepKeys));
|
|
1318
|
+
const secret = secretRedactedIssue(this.redactions);
|
|
1319
|
+
if (secret !== null) issues.push(secret);
|
|
1320
|
+
return issues;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
372
1323
|
|
|
373
1324
|
// src/console/summary.ts
|
|
374
1325
|
var MAX_WARNINGS = 10;
|
|
375
1326
|
var MAX_VIOLATION_ROWS = 20;
|
|
376
1327
|
var MAX_SLOWEST_LINES = 5;
|
|
377
1328
|
var MIN_KEY_WIDTH = 30;
|
|
378
|
-
var
|
|
379
|
-
var
|
|
1329
|
+
var KIND_LABEL = { api: "Endpoints", step: "Steps" };
|
|
1330
|
+
var ALWAYS_SHOWN = /* @__PURE__ */ new Set(["api"]);
|
|
1331
|
+
function aggregatesOf(report, kind) {
|
|
1332
|
+
const byKind = {
|
|
1333
|
+
api: report.endpoints,
|
|
1334
|
+
step: report.steps
|
|
1335
|
+
};
|
|
1336
|
+
return byKind[kind];
|
|
1337
|
+
}
|
|
1338
|
+
var RULE_ORDER2 = [
|
|
380
1339
|
"median",
|
|
381
1340
|
"percentile",
|
|
382
1341
|
"p99",
|
|
@@ -384,7 +1343,7 @@ var RULE_ORDER = [
|
|
|
384
1343
|
"wilson",
|
|
385
1344
|
"errors"
|
|
386
1345
|
];
|
|
387
|
-
var
|
|
1346
|
+
var TIME_RULES2 = /* @__PURE__ */ new Set([
|
|
388
1347
|
"median",
|
|
389
1348
|
"percentile",
|
|
390
1349
|
"p99"
|
|
@@ -402,7 +1361,7 @@ function overText(check) {
|
|
|
402
1361
|
function violations(report) {
|
|
403
1362
|
const list2 = [];
|
|
404
1363
|
for (const kind of KINDS) {
|
|
405
|
-
const aggregates =
|
|
1364
|
+
const aggregates = aggregatesOf(report, kind);
|
|
406
1365
|
for (const [key, aggregate] of Object.entries(aggregates)) {
|
|
407
1366
|
for (const check of aggregate.evaluation.checks) {
|
|
408
1367
|
if (!check.passed) {
|
|
@@ -412,13 +1371,13 @@ function violations(report) {
|
|
|
412
1371
|
}
|
|
413
1372
|
}
|
|
414
1373
|
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) ||
|
|
1374
|
+
(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_ORDER2.indexOf(a.check.rule) - RULE_ORDER2.indexOf(b.check.rule)
|
|
416
1375
|
);
|
|
417
1376
|
}
|
|
418
1377
|
function isMuted(evaluation) {
|
|
419
1378
|
return evaluation.muted !== null && !evaluation.muted.expired;
|
|
420
1379
|
}
|
|
421
|
-
function header(report) {
|
|
1380
|
+
function header(report, paint) {
|
|
422
1381
|
const t = report.tests;
|
|
423
1382
|
const executions = t.expected + t.unexpected + t.flaky;
|
|
424
1383
|
const details = [`${t.expected} passed`, `${t.unexpected} failed`];
|
|
@@ -432,62 +1391,77 @@ function header(report) {
|
|
|
432
1391
|
const commit = ci.commit === null ? "" : `@${ci.commit.slice(0, 7)}`;
|
|
433
1392
|
parts.push(`${ci.branch ?? ""}${commit}`);
|
|
434
1393
|
}
|
|
435
|
-
return parts.join(" · ");
|
|
1394
|
+
return paint(parts.join(" · "), "bold");
|
|
436
1395
|
}
|
|
437
|
-
function
|
|
1396
|
+
function issueBox(level, issues, limit, opts) {
|
|
438
1397
|
if (issues.length === 0) return [];
|
|
439
|
-
const
|
|
1398
|
+
const m = marks(opts.ascii);
|
|
1399
|
+
const [mark, style, name, more] = level === "error" ? [m.error, "red", "Errors", "error"] : [m.warn, "yellow", "Warnings", "warning"];
|
|
1400
|
+
const indent = textWidth(mark) + 1;
|
|
1401
|
+
const lines = [];
|
|
440
1402
|
for (const issue of issues.slice(0, limit)) {
|
|
441
1403
|
const times = issue.count !== void 0 && issue.count > 1 ? ` (×${issue.count})` : "";
|
|
442
|
-
lines.push(
|
|
443
|
-
|
|
1404
|
+
lines.push({
|
|
1405
|
+
spans: [{ text: `${mark} ${issue.code}`, style }, { text: `: ${issue.message}${times}` }],
|
|
1406
|
+
indent
|
|
1407
|
+
});
|
|
1408
|
+
if (issue.hint !== void 0) {
|
|
1409
|
+
lines.push({
|
|
1410
|
+
text: `${" ".repeat(indent)}Hint: ${issue.hint}`,
|
|
1411
|
+
style: "dim",
|
|
1412
|
+
indent: indent + "Hint: ".length
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
444
1415
|
}
|
|
445
1416
|
if (issues.length > limit) {
|
|
446
|
-
lines.push(
|
|
1417
|
+
lines.push({
|
|
1418
|
+
text: `… and ${plural(issues.length - limit, `more ${more}`, `more ${more}s`)} (see report)`,
|
|
1419
|
+
style: "dim"
|
|
1420
|
+
});
|
|
447
1421
|
}
|
|
448
|
-
return [
|
|
1422
|
+
return [
|
|
1423
|
+
...boxLines(lines, {
|
|
1424
|
+
...opts,
|
|
1425
|
+
border: style,
|
|
1426
|
+
title: `${opts.ascii ? "" : `${mark} `}${name} (${issues.length})`,
|
|
1427
|
+
wrap: true
|
|
1428
|
+
}),
|
|
1429
|
+
""
|
|
1430
|
+
];
|
|
449
1431
|
}
|
|
450
|
-
|
|
451
|
-
function counterLines(report) {
|
|
1432
|
+
function counterLines(report, opts) {
|
|
452
1433
|
const counts = report.evaluation.counts;
|
|
453
1434
|
const shown = KINDS.filter(
|
|
454
|
-
(kind) => kind
|
|
1435
|
+
(kind) => ALWAYS_SHOWN.has(kind) || counts[kind].keys > 0 || counts[kind].unseenThresholdEntries > 0
|
|
455
1436
|
);
|
|
1437
|
+
const percentileOff = report.config.checks?.time?.percentile?.enabled === false;
|
|
1438
|
+
const medianOnly = `checked by median only (${percentileOff ? "percentile rule off" : "few samples"})`;
|
|
1439
|
+
const counters = [
|
|
1440
|
+
{ text: "keys", value: (k) => counts[k].keys },
|
|
1441
|
+
{ text: "from file", value: (k) => counts[k].fromFile },
|
|
1442
|
+
{ text: "on default thresholds", value: (k) => counts[k].fromDefaults },
|
|
1443
|
+
{ text: "skipped (too few samples)", value: (k) => counts[k].tooFewSamples },
|
|
1444
|
+
{ text: "not evaluated", value: (k) => counts[k].notEvaluated - counts[k].tooFewSamples },
|
|
1445
|
+
{ text: medianOnly, value: (k) => counts[k].medianOnly },
|
|
1446
|
+
{ text: "file entries not seen", value: (k) => counts[k].unseenThresholdEntries }
|
|
1447
|
+
];
|
|
1448
|
+
const rows = counters.filter((c, i) => i === 0 || shown.some((kind) => c.value(kind) !== 0)).map((c) => ({ cells: [c.text, ...shown.map((kind) => String(c.value(kind)))] }));
|
|
456
1449
|
const columns = [
|
|
457
|
-
{
|
|
458
|
-
{
|
|
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
|
-
}
|
|
1450
|
+
{ header: "" },
|
|
1451
|
+
...shown.map((kind) => ({ header: KIND_LABEL[kind], align: "right" }))
|
|
468
1452
|
];
|
|
469
|
-
|
|
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
|
-
});
|
|
1453
|
+
return table(columns, rows, opts);
|
|
481
1454
|
}
|
|
482
|
-
function mutedLines(report) {
|
|
1455
|
+
function mutedLines(report, paint) {
|
|
483
1456
|
const lines = [];
|
|
1457
|
+
const indent = " ".repeat("Muted: ".length);
|
|
484
1458
|
for (const kind of KINDS) {
|
|
485
|
-
const aggregates =
|
|
1459
|
+
const aggregates = aggregatesOf(report, kind);
|
|
486
1460
|
for (const key of Object.keys(aggregates).sort(compareText)) {
|
|
487
1461
|
const muted = aggregates[key]?.evaluation.muted;
|
|
488
1462
|
if (muted === void 0 || muted === null || muted.expired) continue;
|
|
489
|
-
const
|
|
490
|
-
lines.push(`${
|
|
1463
|
+
const head = lines.length === 0 ? `${paint("Muted:", "bold")} ` : indent;
|
|
1464
|
+
lines.push(`${head}${key} until ${muted.until} — "${muted.note}"`);
|
|
491
1465
|
}
|
|
492
1466
|
}
|
|
493
1467
|
return lines;
|
|
@@ -496,72 +1470,47 @@ function formatTime(ms) {
|
|
|
496
1470
|
return `${Math.round(ms)} ms`;
|
|
497
1471
|
}
|
|
498
1472
|
function formatActual(check) {
|
|
499
|
-
if (
|
|
1473
|
+
if (TIME_RULES2.has(check.rule)) return formatTime(check.actual);
|
|
500
1474
|
const observed = check.observed === null ? "" : ` (${check.observed.toFixed(3)})`;
|
|
501
1475
|
return `${check.actual.toFixed(3)}${observed}`;
|
|
502
1476
|
}
|
|
503
1477
|
function formatLimit(check) {
|
|
504
|
-
return
|
|
1478
|
+
return TIME_RULES2.has(check.rule) ? formatTime(check.limit) : check.limit.toFixed(3);
|
|
505
1479
|
}
|
|
506
|
-
function tableLines(report, list2,
|
|
1480
|
+
function tableLines(report, list2, opts, m, paint) {
|
|
507
1481
|
const level = report.config.checks?.time?.percentile?.level ?? "percentile";
|
|
508
1482
|
const shown = list2.slice(0, MAX_VIOLATION_ROWS);
|
|
1483
|
+
const columns = [
|
|
1484
|
+
{ header: "" },
|
|
1485
|
+
{ header: "kind" },
|
|
1486
|
+
{ header: "key", flex: true, minWidth: MIN_KEY_WIDTH },
|
|
1487
|
+
{ header: "rule" },
|
|
1488
|
+
{ header: "actual", align: "right" },
|
|
1489
|
+
{ header: "limit", align: "right" },
|
|
1490
|
+
{ header: "over", align: "right" },
|
|
1491
|
+
{ header: "n", align: "right" },
|
|
1492
|
+
{ header: "src" },
|
|
1493
|
+
{ header: "flag" }
|
|
1494
|
+
];
|
|
509
1495
|
const rows = shown.map((v) => ({
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
1496
|
+
cells: [
|
|
1497
|
+
v.check.blocking ? m.error : m.warn,
|
|
1498
|
+
v.kind,
|
|
1499
|
+
v.key,
|
|
1500
|
+
v.check.rule === "percentile" ? level : v.check.rule,
|
|
1501
|
+
formatActual(v.check),
|
|
1502
|
+
formatLimit(v.check),
|
|
1503
|
+
overText(v.check),
|
|
1504
|
+
String(v.check.n),
|
|
1505
|
+
v.evaluation.thresholdSource,
|
|
1506
|
+
[v.check.hardLimitExceeded ? "HARD" : "", isMuted(v.evaluation) ? "MUTED" : ""].filter((f) => f !== "").join(" ")
|
|
1507
|
+
],
|
|
1508
|
+
style: v.check.blocking ? "red" : "yellow"
|
|
520
1509
|
}));
|
|
521
|
-
const
|
|
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))];
|
|
1510
|
+
const lines = table(columns, rows, opts);
|
|
563
1511
|
if (list2.length > shown.length) {
|
|
564
|
-
|
|
1512
|
+
const more = plural(list2.length - shown.length, "more violation", "more violations");
|
|
1513
|
+
lines.push(paint(` … and ${more} (see report)`, "dim"));
|
|
565
1514
|
}
|
|
566
1515
|
return lines;
|
|
567
1516
|
}
|
|
@@ -573,7 +1522,7 @@ function slowestLines(report, list2) {
|
|
|
573
1522
|
const id = `${v.kind}\0${v.key}`;
|
|
574
1523
|
if (seen.has(id)) continue;
|
|
575
1524
|
seen.add(id);
|
|
576
|
-
const aggregate = (v.kind
|
|
1525
|
+
const aggregate = aggregatesOf(report, v.kind)[v.key];
|
|
577
1526
|
const slowest = aggregate?.slowest[0];
|
|
578
1527
|
if (slowest === void 0) continue;
|
|
579
1528
|
const t = slowest.test;
|
|
@@ -583,34 +1532,60 @@ function slowestLines(report, list2) {
|
|
|
583
1532
|
}
|
|
584
1533
|
return lines;
|
|
585
1534
|
}
|
|
586
|
-
function
|
|
1535
|
+
function errorCauses(report) {
|
|
1536
|
+
const t = report.tests;
|
|
1537
|
+
const named = {
|
|
1538
|
+
TESTS_FAILED_TOO_MANY: `too many failed tests (${t.unexpected} of ${t.expected + t.unexpected + t.flaky} executions)`,
|
|
1539
|
+
RUN_INCOMPLETE: "the run did not complete",
|
|
1540
|
+
RUN_SHARDED: "the run is sharded"
|
|
1541
|
+
};
|
|
1542
|
+
const causes = [];
|
|
1543
|
+
let other = 0;
|
|
1544
|
+
for (const issue of report.toolErrors) {
|
|
1545
|
+
const cause = named[issue.code];
|
|
1546
|
+
if (cause === void 0) other += 1;
|
|
1547
|
+
else if (!causes.includes(cause)) causes.push(cause);
|
|
1548
|
+
}
|
|
1549
|
+
if (other > 0) causes.push(plural(other, "tool error"));
|
|
1550
|
+
return causes;
|
|
1551
|
+
}
|
|
1552
|
+
function resultLines(report, opts, m) {
|
|
587
1553
|
const counts = report.evaluation.counts;
|
|
588
|
-
const sum = (field) =>
|
|
1554
|
+
const sum = (field) => KINDS.reduce((total, kind) => total + counts[kind][field], 0);
|
|
589
1555
|
const gate = report.config.gate;
|
|
590
|
-
const policy = gate?.
|
|
591
|
-
let
|
|
592
|
-
let style;
|
|
1556
|
+
const policy = gate?.tolerance === void 0 ? "" : ` (tolerance: ${gate.tolerance})`;
|
|
1557
|
+
let verdict;
|
|
593
1558
|
let reason;
|
|
594
1559
|
const status = report.evaluation.status;
|
|
595
1560
|
if (report.toolErrors.length > 0 || status === "error") {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
reason = `${
|
|
1561
|
+
verdict = [m.error, "ERROR", "magenta", "badge-magenta"];
|
|
1562
|
+
const causes = errorCauses(report);
|
|
1563
|
+
reason = `${causes.length === 0 ? "" : `${causes.join(", ")}; `}the performance result is not trustworthy`;
|
|
599
1564
|
} else if (status === "failed") {
|
|
600
|
-
|
|
601
|
-
style = "red";
|
|
1565
|
+
verdict = [m.error, "FAILED", "red", "badge-red"];
|
|
602
1566
|
reason = `${plural(sum("blockingViolations"), "blocking violation")}${policy}`;
|
|
603
1567
|
} else if (status === "warned") {
|
|
604
|
-
|
|
605
|
-
style = "yellow";
|
|
1568
|
+
verdict = [m.warn, "PASSED WITH WARNINGS", "yellow", "badge-yellow"];
|
|
606
1569
|
reason = `${plural(sum("violations"), "key")} with violations, none blocking${policy}`;
|
|
607
1570
|
} else {
|
|
608
|
-
|
|
609
|
-
style = "green";
|
|
1571
|
+
verdict = [m.ok, "PASSED", "green", "badge-green"];
|
|
610
1572
|
reason = `no violations in ${plural(sum("keys") - sum("notEvaluated"), "evaluated key")}`;
|
|
611
1573
|
}
|
|
612
1574
|
const informational = report.mode === "thresholds" ? " (informational, gate disabled)" : "";
|
|
613
|
-
|
|
1575
|
+
const [mark, word, color, badge] = verdict;
|
|
1576
|
+
return verdictBox(mark, word, `${reason}${informational}`, color, badge, opts);
|
|
1577
|
+
}
|
|
1578
|
+
function verdictBox(mark, word, reason, color, badge, opts) {
|
|
1579
|
+
const indent = textWidth(mark) + word.length + 4;
|
|
1580
|
+
return boxLines(
|
|
1581
|
+
[
|
|
1582
|
+
{
|
|
1583
|
+
spans: [{ text: `${mark} ` }, { text: ` ${word} `, style: badge }, { text: ` ${reason}` }],
|
|
1584
|
+
indent
|
|
1585
|
+
}
|
|
1586
|
+
],
|
|
1587
|
+
{ ...opts, border: color, wrap: true }
|
|
1588
|
+
);
|
|
614
1589
|
}
|
|
615
1590
|
function toSlash(path) {
|
|
616
1591
|
return path.replace(/\\/gu, "/");
|
|
@@ -629,51 +1604,154 @@ function segments(path) {
|
|
|
629
1604
|
}
|
|
630
1605
|
return result;
|
|
631
1606
|
}
|
|
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
1607
|
function resolvePath2(base, path) {
|
|
644
1608
|
const p = toSlash(path);
|
|
645
1609
|
if (rootOf(p) !== "") return rootOf(p) + segments(p).join("/");
|
|
646
1610
|
const b = toSlash(base);
|
|
647
1611
|
return rootOf(b) + segments(`${b}/${p}`).join("/");
|
|
648
1612
|
}
|
|
649
|
-
function reportLine(report,
|
|
1613
|
+
function reportLine(report, html, paint) {
|
|
650
1614
|
const options = report.config.report;
|
|
651
1615
|
if (options?.dir === void 0) return [];
|
|
652
1616
|
const dir = resolvePath2(report.configDir, options.dir);
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
return [`Report: ${files.map((f) => relativePath(cwd, `${dir}/${f}`)).join(" · ")}`];
|
|
1617
|
+
const file = html ?? options.html !== false ? "report.html" : "report.json";
|
|
1618
|
+
return [`${paint("Report:", "bold")} ${dir}/${file}`];
|
|
656
1619
|
}
|
|
657
1620
|
function formatSummary(report, opts) {
|
|
658
1621
|
const paint = painter(opts.color);
|
|
1622
|
+
const frame = { width: opts.width, color: opts.color, ascii: opts.ascii ?? false };
|
|
1623
|
+
const m = marks(frame.ascii);
|
|
659
1624
|
const list2 = violations(report);
|
|
660
|
-
const lines = [
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
lines.push(...
|
|
1625
|
+
const lines = [
|
|
1626
|
+
paint("─".repeat(Math.max(1, opts.width)), "dim"),
|
|
1627
|
+
header(report, paint),
|
|
1628
|
+
""
|
|
1629
|
+
];
|
|
1630
|
+
lines.push(...issueBox("error", report.toolErrors, Infinity, frame));
|
|
1631
|
+
lines.push(...issueBox("warning", report.warnings, MAX_WARNINGS, frame));
|
|
1632
|
+
lines.push(...counterLines(report, frame), ...mutedLines(report, paint), "");
|
|
666
1633
|
if (list2.length > 0) {
|
|
667
|
-
lines.push(...tableLines(report, list2,
|
|
1634
|
+
lines.push(...tableLines(report, list2, frame, m, paint));
|
|
668
1635
|
const slowest = slowestLines(report, list2);
|
|
669
|
-
if (slowest.length > 0) lines.push(
|
|
1636
|
+
if (slowest.length > 0) lines.push(...slowest);
|
|
670
1637
|
lines.push("");
|
|
671
1638
|
}
|
|
672
|
-
lines.push(
|
|
1639
|
+
lines.push(...resultLines(report, frame, m), ...reportLine(report, opts.html, paint));
|
|
673
1640
|
return `${lines.join("\n")}
|
|
674
1641
|
`;
|
|
675
1642
|
}
|
|
676
1643
|
|
|
1644
|
+
// src/console/check-summary.ts
|
|
1645
|
+
var MAX_WARNINGS2 = 10;
|
|
1646
|
+
var CHECK_REASON = "nothing was evaluated and no files were written";
|
|
1647
|
+
function formatCheckSummary(s, opts) {
|
|
1648
|
+
const paint = painter(opts.color);
|
|
1649
|
+
const lines = [];
|
|
1650
|
+
lines.push("─".repeat(Math.max(20, opts.width)));
|
|
1651
|
+
const failed = s.failed > 0 ? `, ${String(s.failed)} failed` : "";
|
|
1652
|
+
lines.push(
|
|
1653
|
+
paint(
|
|
1654
|
+
`${s.packageName} · check · ${String(s.ran)} of ${String(s.selected)} tests run (${String(s.passed)} passed${failed}) · ${String(s.skippedByCheck)} skipped by check`,
|
|
1655
|
+
"bold"
|
|
1656
|
+
),
|
|
1657
|
+
""
|
|
1658
|
+
);
|
|
1659
|
+
lines.push(paint("Projects:", "bold"));
|
|
1660
|
+
for (const p of s.projects) {
|
|
1661
|
+
if (p.role === "measured") {
|
|
1662
|
+
const browser = p.browserName === null ? "" : ` (${p.browserName})`;
|
|
1663
|
+
lines.push(
|
|
1664
|
+
` measured ${p.name}${browser} · baseURL ${p.baseURL ?? "(not set)"} · ${String(p.requests)} requests in ${String(p.tests)} tests`
|
|
1665
|
+
);
|
|
1666
|
+
} else {
|
|
1667
|
+
lines.push(` dependency ${p.name} · runs once, not measured`);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
if (s.removedProjects.length > 0) {
|
|
1671
|
+
lines.push(` not run ${s.removedProjects.join(", ")} (not in run.projects)`);
|
|
1672
|
+
}
|
|
1673
|
+
const reporterParts = [
|
|
1674
|
+
`kept ${s.reporters.kept.length === 0 ? "none" : s.reporters.kept.join(", ")}${s.reporters.replaced.length > 0 ? ` (${s.reporters.replaced.join(", ")} replaced)` : ""}`,
|
|
1675
|
+
...s.reporters.removed.length > 0 ? [`removed ${s.reporters.removed.join(", ")}`] : []
|
|
1676
|
+
];
|
|
1677
|
+
lines.push(`${paint("Reporters:", "bold")} ${reporterParts.join(" · ")}`);
|
|
1678
|
+
lines.push(
|
|
1679
|
+
`${paint("Requests:", "bold")} ${String(s.requests)} requests · ${String(s.apiKeys)} api keys · ${String(s.stepKeys)} step keys · ${String(s.origins.length)} ${s.origins.length === 1 ? "origin" : "origins"}`
|
|
1680
|
+
);
|
|
1681
|
+
const labelWidth = Math.max(6, ...s.origins.map((o) => o.label === "" ? 6 : o.label.length));
|
|
1682
|
+
const originWidth = Math.max(...s.origins.map((o) => o.origin.length), 0);
|
|
1683
|
+
for (const o of s.origins) {
|
|
1684
|
+
lines.push(
|
|
1685
|
+
` ${padEnd(o.label === "" ? "(main)" : o.label, labelWidth)} ${padEnd(o.origin, originWidth)} ${String(o.requests).padStart(6)} ${o.source}`
|
|
1686
|
+
);
|
|
1687
|
+
}
|
|
1688
|
+
if (s.topKeys.length > 0) {
|
|
1689
|
+
lines.push(paint("Top keys:", "bold"));
|
|
1690
|
+
const keyWidth = Math.max(30, opts.width - 40);
|
|
1691
|
+
s.topKeys.forEach((k, i) => {
|
|
1692
|
+
lines.push(
|
|
1693
|
+
` ${String(i + 1).padStart(2)}. ${padEnd(k.kind, 4)} ${padEnd(truncateMiddle(k.key, keyWidth), Math.min(keyWidth, 50))} ${String(k.samples)} samples · ${String(k.tests)} tests`
|
|
1694
|
+
);
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
lines.push(
|
|
1698
|
+
`${paint("Thresholds files:", "bold")} ${s.thresholdsFiles.map((f) => `${f.kind} ${f.state === "missing" ? `missing (${f.name})` : f.state === "not used" ? "not used" : `${f.state} (${f.name})`}`).join(" · ")}`
|
|
1699
|
+
);
|
|
1700
|
+
const frame = { width: opts.width, color: opts.color, ascii: opts.ascii ?? false };
|
|
1701
|
+
if (s.toolErrors.length > 0 || s.warnings.length > 0) lines.push("");
|
|
1702
|
+
lines.push(...issueBox("error", s.toolErrors, Infinity, frame));
|
|
1703
|
+
lines.push(...issueBox("warning", s.warnings, MAX_WARNINGS2, frame));
|
|
1704
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
1705
|
+
lines.push("", `${paint("Estimate:", "bold")} ${s.estimate}`, "");
|
|
1706
|
+
const m = marks(frame.ascii);
|
|
1707
|
+
lines.push(
|
|
1708
|
+
...s.toolErrors.length === 0 ? verdictBox(m.ok, "CHECKED", CHECK_REASON, "green", "badge-green", frame) : verdictBox(m.error, "ERROR", CHECK_REASON, "magenta", "badge-magenta", frame)
|
|
1709
|
+
);
|
|
1710
|
+
return `${lines.join("\n")}
|
|
1711
|
+
`;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
// src/console/start-banner.ts
|
|
1715
|
+
var TITLES = {
|
|
1716
|
+
test: "measurement run",
|
|
1717
|
+
thresholds: "thresholds run",
|
|
1718
|
+
check: "check (dry run)"
|
|
1719
|
+
};
|
|
1720
|
+
function names(list2) {
|
|
1721
|
+
return list2.map((n) => n === "" ? "(default)" : n).join(", ");
|
|
1722
|
+
}
|
|
1723
|
+
var LABEL = 10;
|
|
1724
|
+
function formatStartBanner(input, opts) {
|
|
1725
|
+
const row = (label, value) => ({
|
|
1726
|
+
text: `${label.padEnd(LABEL)}${value}`
|
|
1727
|
+
});
|
|
1728
|
+
const icon = opts.ascii ? "" : "⏱️ ";
|
|
1729
|
+
const lines = [
|
|
1730
|
+
{ text: `${icon}${input.packageName} · ${TITLES[input.mode]}`, style: "bold" }
|
|
1731
|
+
];
|
|
1732
|
+
const deps = input.dependencies.length > 0 ? ` (setup: ${names(input.dependencies)})` : "";
|
|
1733
|
+
lines.push(row("Projects", `${names(input.measured)}${deps}`));
|
|
1734
|
+
if (input.mode === "check") {
|
|
1735
|
+
lines.push(
|
|
1736
|
+
row(
|
|
1737
|
+
"Tests",
|
|
1738
|
+
`${plural(input.tests, "test")}; the first test of each file runs once, at most ${String(input.maxTests ?? input.tests)}`
|
|
1739
|
+
)
|
|
1740
|
+
);
|
|
1741
|
+
} else {
|
|
1742
|
+
lines.push(
|
|
1743
|
+
row(
|
|
1744
|
+
"Tests",
|
|
1745
|
+
`${plural(input.tests, "test")} × ${plural(input.passes, "pass", "passes")} = ${plural(input.tests * input.passes, "test run")}`
|
|
1746
|
+
)
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
if (input.estimate !== null) lines.push(row("Estimate", input.estimate));
|
|
1750
|
+
lines.push(row("Report", input.report ?? "no files are written"));
|
|
1751
|
+
if (input.tip) lines.push(row("Tip", "measure a subset, e.g. --grep @perf"));
|
|
1752
|
+
return box(lines, { ...opts, border: "cyan" });
|
|
1753
|
+
}
|
|
1754
|
+
|
|
677
1755
|
// src/reporter/begin.ts
|
|
678
1756
|
function browserOf(project) {
|
|
679
1757
|
return project.use.browserName ?? project.use.defaultBrowserType ?? "chromium";
|
|
@@ -695,22 +1773,20 @@ function readRunConditions(config, measured, overridden) {
|
|
|
695
1773
|
overriddenSettings: [...overridden]
|
|
696
1774
|
};
|
|
697
1775
|
}
|
|
698
|
-
function runConditionsWarning(conditions
|
|
1776
|
+
function runConditionsWarning(conditions) {
|
|
699
1777
|
const diffs = [];
|
|
700
1778
|
if (conditions.workers !== 1) diffs.push(`workers ${conditions.workers} (expected 1)`);
|
|
701
1779
|
for (const project of conditions.projects) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
diffs.push(`${name} repeatEach ${project.repeatEach} (expected ${expected})`);
|
|
1780
|
+
if (project.repeatEach !== 1) {
|
|
1781
|
+
const name = `project ${JSON.stringify(project.name)}`;
|
|
1782
|
+
diffs.push(`${name} repeatEach ${project.repeatEach} (expected 1)`);
|
|
706
1783
|
}
|
|
707
|
-
if (project.retries !== 0) diffs.push(`${name} retries ${project.retries} (expected 0)`);
|
|
708
1784
|
}
|
|
709
1785
|
if (diffs.length === 0) return null;
|
|
710
1786
|
return {
|
|
711
1787
|
code: "RUN_CONDITIONS_CHANGED",
|
|
712
1788
|
message: `The run conditions differ from those set for perf mode: ${diffs.join("; ")}.`,
|
|
713
|
-
hint: "Do not pass --workers
|
|
1789
|
+
hint: "Do not pass --workers or --repeat-each to a perf-mode run; set the number of passes with run.passes or PW_PERF_PASSES."
|
|
714
1790
|
};
|
|
715
1791
|
}
|
|
716
1792
|
function duplicateBaseUrlLabels(conditions, config, keys) {
|
|
@@ -735,8 +1811,8 @@ function duplicateBaseUrlLabels(conditions, config, keys) {
|
|
|
735
1811
|
hint: "Give each origin its own label in keys.origins unless merging their keys is intended."
|
|
736
1812
|
};
|
|
737
1813
|
}
|
|
738
|
-
function list(
|
|
739
|
-
return
|
|
1814
|
+
function list(names2) {
|
|
1815
|
+
return names2.map((n) => n === "" ? "(default)" : n).join(", ");
|
|
740
1816
|
}
|
|
741
1817
|
function overriddenLine(conditions) {
|
|
742
1818
|
const parts = [];
|
|
@@ -749,17 +1825,94 @@ function overriddenLine(conditions) {
|
|
|
749
1825
|
if (conditions.removedReporters.length > 0) {
|
|
750
1826
|
parts.push(`removed reporters ${list(conditions.removedReporters)}`);
|
|
751
1827
|
}
|
|
1828
|
+
for (const name of conditions.replacedReporters) {
|
|
1829
|
+
parts.push(`reporter ${name} replaced with dot`);
|
|
1830
|
+
}
|
|
752
1831
|
return parts.length === 0 ? null : `${parts.join("; ")}.`;
|
|
753
1832
|
}
|
|
754
|
-
function
|
|
755
|
-
return
|
|
1833
|
+
function measuredTestCount(tests, measured) {
|
|
1834
|
+
return tests.filter((t) => measured.has(t.parent.project()?.name ?? "")).length;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// src/reporter/pass-file.ts
|
|
1838
|
+
var PASS_FILE_FORMAT = "pw-perf-pass";
|
|
1839
|
+
var PASS_FILE_VERSION = 1;
|
|
1840
|
+
function passFileName(index) {
|
|
1841
|
+
return `pass-${String(index)}.json`;
|
|
1842
|
+
}
|
|
1843
|
+
function isPassFileName(name) {
|
|
1844
|
+
return /^pass-[1-9][0-9]*\.json$/u.test(name);
|
|
1845
|
+
}
|
|
1846
|
+
var JournalAggregator = class extends Aggregator {
|
|
1847
|
+
journal = null;
|
|
1848
|
+
keepUrls;
|
|
1849
|
+
constructor(options) {
|
|
1850
|
+
super(options);
|
|
1851
|
+
this.keepUrls = options.rawUrls;
|
|
1852
|
+
}
|
|
1853
|
+
addRequest(key, sample, origin, label, browserName) {
|
|
1854
|
+
super.addRequest(key, sample, origin, label, browserName);
|
|
1855
|
+
this.journal?.push([
|
|
1856
|
+
"r",
|
|
1857
|
+
key,
|
|
1858
|
+
this.keepUrls ? sample : { ...sample, url: "" },
|
|
1859
|
+
origin,
|
|
1860
|
+
label,
|
|
1861
|
+
browserName
|
|
1862
|
+
]);
|
|
1863
|
+
}
|
|
1864
|
+
addStep(sample) {
|
|
1865
|
+
super.addStep(sample);
|
|
1866
|
+
this.journal?.push(["s", sample]);
|
|
1867
|
+
}
|
|
1868
|
+
endResult(meta) {
|
|
1869
|
+
super.endResult(meta);
|
|
1870
|
+
this.journal?.push(["e", meta]);
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
function replayEntries(aggregator, entries) {
|
|
1874
|
+
for (const entry of entries) {
|
|
1875
|
+
if (entry[0] === "r") aggregator.addRequest(entry[1], entry[2], entry[3], entry[4], entry[5]);
|
|
1876
|
+
else if (entry[0] === "s") aggregator.addStep(entry[1]);
|
|
1877
|
+
else aggregator.endResult(entry[1]);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
function isRecord(value) {
|
|
1881
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1882
|
+
}
|
|
1883
|
+
function parsePassFile(text, expected) {
|
|
1884
|
+
let value;
|
|
1885
|
+
try {
|
|
1886
|
+
value = JSON.parse(text);
|
|
1887
|
+
} catch {
|
|
1888
|
+
return { ok: false, reason: "the file is not valid JSON" };
|
|
1889
|
+
}
|
|
1890
|
+
if (!isRecord(value) || value.format !== PASS_FILE_FORMAT) {
|
|
1891
|
+
return { ok: false, reason: "the file is no pass file" };
|
|
1892
|
+
}
|
|
1893
|
+
if (value.schemaVersion !== PASS_FILE_VERSION || value.toolVersion !== expected.toolVersion) {
|
|
1894
|
+
return { ok: false, reason: "the file was written by another package version" };
|
|
1895
|
+
}
|
|
1896
|
+
if (value.runId !== expected.runId) {
|
|
1897
|
+
return { ok: false, reason: `the file belongs to run ${JSON.stringify(value.runId)}` };
|
|
1898
|
+
}
|
|
1899
|
+
const pass = value.pass;
|
|
1900
|
+
if (!isRecord(pass) || pass.index !== expected.index || pass.total !== expected.total) {
|
|
1901
|
+
return { ok: false, reason: "the file belongs to another pass" };
|
|
1902
|
+
}
|
|
1903
|
+
if (!Array.isArray(value.entries) || !isRecord(value.tests) || !isRecord(value.counters) || !Array.isArray(value.warnings) || !Array.isArray(value.toolErrors)) {
|
|
1904
|
+
return { ok: false, reason: "the file is incomplete" };
|
|
1905
|
+
}
|
|
1906
|
+
return { ok: true, value };
|
|
756
1907
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
1908
|
+
var STATUS_ORDER = [
|
|
1909
|
+
"passed",
|
|
1910
|
+
"failed",
|
|
1911
|
+
"timedout",
|
|
1912
|
+
"interrupted"
|
|
1913
|
+
];
|
|
1914
|
+
function worseStatus(a, b) {
|
|
1915
|
+
return STATUS_ORDER.indexOf(b) > STATUS_ORDER.indexOf(a) ? b : a;
|
|
763
1916
|
}
|
|
764
1917
|
|
|
765
1918
|
// src/reporter/samples.ts
|
|
@@ -784,7 +1937,9 @@ function testMeta(test, result, file) {
|
|
|
784
1937
|
file,
|
|
785
1938
|
line: test.location.line,
|
|
786
1939
|
repeatEachIndex: test.repeatEachIndex,
|
|
787
|
-
|
|
1940
|
+
retry: result.retry,
|
|
1941
|
+
failed: isFailedTest(result.status, test.expectedStatus),
|
|
1942
|
+
startTime: result.startTime.getTime()
|
|
788
1943
|
};
|
|
789
1944
|
}
|
|
790
1945
|
function sampleAttachments(result) {
|
|
@@ -815,8 +1970,8 @@ function runSettings(registered, env, packageVersion) {
|
|
|
815
1970
|
if (read.ok && read.value === null) return null;
|
|
816
1971
|
const mode = read.ok && read.value !== null ? read.value : { mode: "test" };
|
|
817
1972
|
const resolved = resolveConfig(void 0, {
|
|
818
|
-
mode: mode.mode,
|
|
819
|
-
...mode.
|
|
1973
|
+
mode: mode.mode === "check" ? "test" : mode.mode,
|
|
1974
|
+
...mode.mode === "check" ? {} : mode.pass !== void 0 ? { passes: mode.pass.total } : mode.passes === void 0 ? {} : { passes: mode.passes },
|
|
820
1975
|
...mode.env === void 0 ? {} : { env: mode.env }
|
|
821
1976
|
});
|
|
822
1977
|
if (!resolved.ok) throw new Error("the default package config is not valid");
|
|
@@ -826,7 +1981,12 @@ function runSettings(registered, env, packageVersion) {
|
|
|
826
1981
|
mode,
|
|
827
1982
|
packageVersion,
|
|
828
1983
|
measuredProjects: null,
|
|
829
|
-
runConditions: {
|
|
1984
|
+
runConditions: {
|
|
1985
|
+
overridden: [],
|
|
1986
|
+
removedProjects: [],
|
|
1987
|
+
removedReporters: [],
|
|
1988
|
+
replacedReporters: []
|
|
1989
|
+
},
|
|
830
1990
|
registered: false,
|
|
831
1991
|
warnings: [notWrappedWarning()],
|
|
832
1992
|
toolErrors: read.ok ? [] : read.issues
|
|
@@ -840,7 +2000,7 @@ function internalError(where, error) {
|
|
|
840
2000
|
hint: "This is a bug in the package; please report it with the message above."
|
|
841
2001
|
};
|
|
842
2002
|
}
|
|
843
|
-
function
|
|
2003
|
+
function plural2(n, word, many = `${word}s`) {
|
|
844
2004
|
return `${n} ${n === 1 ? word : many}`;
|
|
845
2005
|
}
|
|
846
2006
|
var RunSession = class {
|
|
@@ -858,14 +2018,40 @@ var RunSession = class {
|
|
|
858
2018
|
normalization;
|
|
859
2019
|
aggregator;
|
|
860
2020
|
keyOf;
|
|
2021
|
+
steps;
|
|
861
2022
|
/** onBegin failed: the evaluation is not possible. */
|
|
862
2023
|
fatal = false;
|
|
863
2024
|
testsStarted = 0;
|
|
864
2025
|
testsSeen = /* @__PURE__ */ new Set();
|
|
865
2026
|
notInstrumented = 0;
|
|
866
|
-
retried = 0;
|
|
867
2027
|
withArtifacts = 0;
|
|
2028
|
+
/** Test counts of the passes 2…N merged into this one (04-REQ-64). */
|
|
2029
|
+
mergedTests = { expected: 0, unexpected: 0, flaky: 0, skipped: 0 };
|
|
2030
|
+
/** Passes merged into the report and passes without data (02-REQ-37). */
|
|
2031
|
+
completedPasses = 1;
|
|
2032
|
+
failedPasses = [];
|
|
2033
|
+
/** Warnings and tool errors before onBegin ended: the same in every pass. */
|
|
2034
|
+
beginWarnings = 0;
|
|
2035
|
+
beginToolErrors = 0;
|
|
2036
|
+
/** "n" to the Continue? question (04-REQ-65): the run ends without output. */
|
|
2037
|
+
cancelled = false;
|
|
868
2038
|
pending = /* @__PURE__ */ new Map();
|
|
2039
|
+
/** Check (04, chapter 4.11): counters for the output and the estimate. */
|
|
2040
|
+
checkRun = {
|
|
2041
|
+
selected: 0,
|
|
2042
|
+
ran: 0,
|
|
2043
|
+
passed: 0,
|
|
2044
|
+
failed: 0,
|
|
2045
|
+
skipped: 0,
|
|
2046
|
+
durations: [],
|
|
2047
|
+
setupMs: 0,
|
|
2048
|
+
requests: /* @__PURE__ */ new Map(),
|
|
2049
|
+
tests: /* @__PURE__ */ new Map()
|
|
2050
|
+
};
|
|
2051
|
+
configLike = null;
|
|
2052
|
+
/** Measured projects with a non-skipped test that has a batch, and those with requests. */
|
|
2053
|
+
instrumentedProjects = /* @__PURE__ */ new Set();
|
|
2054
|
+
projectsWithRequests = /* @__PURE__ */ new Set();
|
|
869
2055
|
playwrightVersion = "";
|
|
870
2056
|
constructor(host, settings, options = {}) {
|
|
871
2057
|
this.host = host;
|
|
@@ -881,16 +2067,29 @@ var RunSession = class {
|
|
|
881
2067
|
this.normalization = normalizationFingerprint(keys, { baseOrigins: [] });
|
|
882
2068
|
this.aggregator = this.createAggregator();
|
|
883
2069
|
this.keyOf = createKeyBuilder(keys, { baseOrigins: [] });
|
|
2070
|
+
this.steps = new StepRecorder(settings.config);
|
|
884
2071
|
}
|
|
2072
|
+
/** Mode of the run report; a check aggregates like a measurement run (04-REQ-48). */
|
|
885
2073
|
get mode() {
|
|
886
|
-
|
|
2074
|
+
const mode = this.settings.mode.mode;
|
|
2075
|
+
return mode === "check" ? "test" : mode;
|
|
2076
|
+
}
|
|
2077
|
+
/** A dry run: nothing is evaluated or written (04, chapter 4.11). */
|
|
2078
|
+
get check() {
|
|
2079
|
+
return this.settings.mode.mode === "check";
|
|
2080
|
+
}
|
|
2081
|
+
/** Passes of the run (D-39): one in a check, N of PW_PERF_PASS=k/N in passes 2…N. */
|
|
2082
|
+
get passes() {
|
|
2083
|
+
if (this.check) return 1;
|
|
2084
|
+
return this.settings.mode.pass?.total ?? this.settings.config.run.passes[this.mode];
|
|
887
2085
|
}
|
|
888
|
-
|
|
889
|
-
|
|
2086
|
+
/** Number of this pass, from 1 (04-REQ-64). */
|
|
2087
|
+
get passIndex() {
|
|
2088
|
+
return this.check ? 1 : this.settings.mode.pass?.index ?? 1;
|
|
890
2089
|
}
|
|
891
2090
|
createAggregator() {
|
|
892
2091
|
const cfg = this.settings.config;
|
|
893
|
-
return new
|
|
2092
|
+
return new JournalAggregator({
|
|
894
2093
|
advanced: cfg.advanced,
|
|
895
2094
|
successStatuses: cfg.measure.successStatuses,
|
|
896
2095
|
errors: cfg.checks.errors,
|
|
@@ -910,15 +2109,25 @@ var RunSession = class {
|
|
|
910
2109
|
}
|
|
911
2110
|
begin(config, suite) {
|
|
912
2111
|
this.playwrightVersion = config.version;
|
|
2112
|
+
this.configLike = config;
|
|
913
2113
|
this.startedAt = this.host.now();
|
|
914
2114
|
if (this.settings.mode.runId === void 0) {
|
|
915
2115
|
this.runId = generateRunId(this.startedAt, this.host.random);
|
|
916
2116
|
}
|
|
917
2117
|
const io = this.host.io;
|
|
918
2118
|
this.configDir = config.configFile === void 0 ? config.rootDir : io.directoryOf(config.configFile);
|
|
2119
|
+
const outcomeFile = this.outcomePath();
|
|
2120
|
+
if (this.passIndex === 1 && this.environmentMode && outcomeFile !== null) {
|
|
2121
|
+
try {
|
|
2122
|
+
io.removeFileSync(outcomeFile);
|
|
2123
|
+
} catch {
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
if (this.passIndex === 1 && !this.check) this.removePassFiles();
|
|
919
2127
|
this.maxFailures = config.maxFailures;
|
|
920
|
-
const
|
|
921
|
-
this.measured = new Set(
|
|
2128
|
+
const names2 = this.settings.measuredProjects ?? config.projects.map((p) => p.name);
|
|
2129
|
+
this.measured = new Set(names2);
|
|
2130
|
+
this.checkRun.selected = suite.allTests().filter((t) => this.measured.has(projectName(t))).length;
|
|
922
2131
|
this.conditions = readRunConditions(
|
|
923
2132
|
config,
|
|
924
2133
|
this.measured,
|
|
@@ -935,11 +2144,13 @@ var RunSession = class {
|
|
|
935
2144
|
this.keyOf = createKeyBuilder(keys, { baseOrigins });
|
|
936
2145
|
this.aggregator = this.createAggregator();
|
|
937
2146
|
if (this.settings.registered) {
|
|
938
|
-
const changed = runConditionsWarning(this.conditions
|
|
2147
|
+
const changed = runConditionsWarning(this.conditions);
|
|
939
2148
|
if (changed !== null) this.warnings.push(changed);
|
|
940
2149
|
}
|
|
941
2150
|
const duplicate = duplicateBaseUrlLabels(this.conditions, config, keys);
|
|
942
2151
|
if (duplicate !== null) this.warnings.push(duplicate);
|
|
2152
|
+
const empty = emptyBaseUrlWarning(this.conditions, config);
|
|
2153
|
+
if (empty !== null) this.warnings.push(empty);
|
|
943
2154
|
if (config.shard !== null) {
|
|
944
2155
|
this.toolErrors.push({
|
|
945
2156
|
code: "RUN_SHARDED",
|
|
@@ -947,30 +2158,106 @@ var RunSession = class {
|
|
|
947
2158
|
hint: "Run perf mode on one machine without --shard."
|
|
948
2159
|
});
|
|
949
2160
|
}
|
|
2161
|
+
this.beginWarnings = this.warnings.length;
|
|
2162
|
+
this.beginToolErrors = this.toolErrors.length;
|
|
2163
|
+
if (this.passes > 1) this.aggregator.journal = [];
|
|
2164
|
+
if (this.passIndex > 1) {
|
|
2165
|
+
this.info(`pass ${String(this.passIndex)}/${String(this.passes)} (perf mode "${this.mode}")`);
|
|
2166
|
+
return;
|
|
2167
|
+
}
|
|
950
2168
|
const overridden = overriddenLine(this.settings.runConditions);
|
|
951
2169
|
if (overridden !== null) this.info(overridden);
|
|
952
|
-
this.
|
|
953
|
-
|
|
2170
|
+
this.host.stdout.write(this.startBanner(suite));
|
|
2171
|
+
this.confirm();
|
|
2172
|
+
}
|
|
2173
|
+
/** report.dir as an absolute path. */
|
|
2174
|
+
reportDir() {
|
|
2175
|
+
const io = this.host.io;
|
|
2176
|
+
return io.resolvePath(this.configDir, this.settings.config.report.dir);
|
|
2177
|
+
}
|
|
2178
|
+
/** Removes pass-<k>.json files of an earlier run (02-REQ-36). */
|
|
2179
|
+
removePassFiles() {
|
|
2180
|
+
const io = this.host.io;
|
|
2181
|
+
const dir = this.reportDir();
|
|
2182
|
+
for (const name of io.listDirSync(dir)) {
|
|
2183
|
+
if (!isPassFileName(name)) continue;
|
|
2184
|
+
try {
|
|
2185
|
+
io.removeFileSync(io.resolvePath(dir, name));
|
|
2186
|
+
} catch {
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
/** Time per test execution of the last run report in report.dir (04-REQ-66), or null. */
|
|
2191
|
+
lastMsPerTest() {
|
|
2192
|
+
const path = this.host.io.resolvePath(this.reportDir(), "report.json");
|
|
2193
|
+
const text = this.host.io.readTextFileSync(path);
|
|
2194
|
+
if (text === null) return null;
|
|
2195
|
+
const parsed = parseRunReport(text, path);
|
|
2196
|
+
return parsed.ok ? msPerTest(parsed.value) : null;
|
|
2197
|
+
}
|
|
2198
|
+
/** The start banner (04-REQ-65). */
|
|
2199
|
+
startBanner(suite) {
|
|
2200
|
+
const cfg = this.settings.config;
|
|
2201
|
+
const io = this.host.io;
|
|
2202
|
+
const tests = measuredTestCount(suite.allTests(), this.measured);
|
|
2203
|
+
const file = cfg.report.html ? "report.html" : "report.json";
|
|
2204
|
+
const { width, color } = this.terminal();
|
|
2205
|
+
return formatStartBanner(
|
|
2206
|
+
{
|
|
2207
|
+
packageName: "pw-perf",
|
|
2208
|
+
mode: this.settings.mode.mode,
|
|
2209
|
+
measured: this.conditions.projects.filter((p) => p.role === "measured").map((p) => p.name),
|
|
2210
|
+
dependencies: this.conditions.projects.filter((p) => p.role !== "measured").map((p) => p.name),
|
|
2211
|
+
tests,
|
|
2212
|
+
passes: this.passes,
|
|
2213
|
+
maxTests: this.settings.mode.maxTests ?? DEFAULT_MAX_TESTS,
|
|
2214
|
+
estimate: this.check ? null : startEstimate({ tests, passes: this.passes, msPerTest: this.lastMsPerTest() }),
|
|
2215
|
+
report: this.check ? null : io.relativeSlashPath(this.host.cwd, io.resolvePath(this.reportDir(), file)),
|
|
2216
|
+
tip: testFilters(testArgsFromArgv(this.host.argv)).length === 0
|
|
2217
|
+
},
|
|
2218
|
+
{ width, color, ascii: asciiTerminal(this.host.env) }
|
|
954
2219
|
);
|
|
955
2220
|
}
|
|
2221
|
+
/**
|
|
2222
|
+
* "Continue? (Y/n)" in a terminal outside CI, without PW_PERF_YES=1 (04-REQ-65). "n" ends the
|
|
2223
|
+
* process with 130.
|
|
2224
|
+
*/
|
|
2225
|
+
confirm() {
|
|
2226
|
+
if (this.check || this.settings.mode.yes === true) return;
|
|
2227
|
+
if (this.host.stdout.isTTY !== true || this.host.ci !== null || isCiEnv(this.host.env)) return;
|
|
2228
|
+
for (; ; ) {
|
|
2229
|
+
const answer = this.host.ask("Continue? (Y/n) ");
|
|
2230
|
+
if (answer === null) return;
|
|
2231
|
+
const text = answer.trim().toLowerCase();
|
|
2232
|
+
if (text === "" || text === "y" || text === "yes") return;
|
|
2233
|
+
if (text === "n" || text === "no") {
|
|
2234
|
+
this.cancelled = true;
|
|
2235
|
+
this.info("cancelled");
|
|
2236
|
+
this.host.exit(130);
|
|
2237
|
+
return;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
956
2241
|
testBegin() {
|
|
957
2242
|
this.testsStarted += 1;
|
|
958
2243
|
}
|
|
959
2244
|
testEnd(test, result) {
|
|
960
2245
|
this.testsSeen.add(test);
|
|
961
|
-
if (result.retry > 0) this.retried += 1;
|
|
962
2246
|
if (hasTraceOrVideo(result)) this.withArtifacts += 1;
|
|
963
2247
|
const bodies = sampleAttachments(result);
|
|
964
2248
|
const measured = this.measured.has(projectName(test));
|
|
2249
|
+
if (this.check) this.countCheck(test, result, measured);
|
|
2250
|
+
const relative = (file) => this.host.io.relativeSlashPath(this.configDir, file);
|
|
2251
|
+
const meta = this.passMeta(testMeta(test, result, relative(test.location.file)), test);
|
|
2252
|
+
this.steps.record(this.aggregator, test, result.steps, meta, relative);
|
|
965
2253
|
if (bodies.length === 0) {
|
|
966
2254
|
if (measured && result.status !== "skipped") this.notInstrumented += 1;
|
|
967
2255
|
return;
|
|
968
2256
|
}
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
);
|
|
2257
|
+
const project = projectName(test);
|
|
2258
|
+
if (measured && result.status !== "skipped") {
|
|
2259
|
+
this.instrumentedProjects.add(project);
|
|
2260
|
+
}
|
|
974
2261
|
if (bodies.length > 1) {
|
|
975
2262
|
this.warnings.push({
|
|
976
2263
|
code: "ATTACHMENT_DUPLICATE",
|
|
@@ -986,6 +2273,11 @@ var RunSession = class {
|
|
|
986
2273
|
}
|
|
987
2274
|
const batch = parsed.value;
|
|
988
2275
|
this.warnings.push(...batch.diagnostics);
|
|
2276
|
+
if (measured && batch.requests.length > 0) this.projectsWithRequests.add(project);
|
|
2277
|
+
if (measured) {
|
|
2278
|
+
const n = this.checkRun.requests.get(project) ?? 0;
|
|
2279
|
+
this.checkRun.requests.set(project, n + batch.requests.length);
|
|
2280
|
+
}
|
|
989
2281
|
batch.requests.forEach((sample, ordinal) => {
|
|
990
2282
|
const keyed = addKeyedRequest(
|
|
991
2283
|
this.aggregator,
|
|
@@ -998,32 +2290,41 @@ var RunSession = class {
|
|
|
998
2290
|
this.pending.set(keyed.key, (this.pending.get(keyed.key) ?? 0) + 1);
|
|
999
2291
|
}
|
|
1000
2292
|
});
|
|
1001
|
-
batch.custom.forEach((sample, ordinal) => {
|
|
1002
|
-
this.aggregator.addCustom(sample.name, { ...sample, test: meta, ordinal });
|
|
1003
|
-
});
|
|
1004
2293
|
}
|
|
2294
|
+
this.aggregator.endResult(meta);
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* In pass k the repetition index moves by (k − 1) × repeatEach of the test's project, so the
|
|
2298
|
+
* results of one test in different passes have different resultIds (08-REQ-08, D-39).
|
|
2299
|
+
*/
|
|
2300
|
+
passMeta(meta, test) {
|
|
2301
|
+
if (this.passIndex === 1) return meta;
|
|
2302
|
+
const project = this.conditions.projects.find((p) => p.name === meta.project);
|
|
2303
|
+
const index = (this.passIndex - 1) * (project?.repeatEach ?? 1) + test.repeatEachIndex;
|
|
2304
|
+
return { ...meta, repeatEachIndex: index, resultId: resultId(test.id, index, meta.retry) };
|
|
1005
2305
|
}
|
|
1006
2306
|
/** Warnings known only at the end of the run (09, chapter 12.1). */
|
|
1007
2307
|
runWarnings() {
|
|
1008
2308
|
const issues = [];
|
|
1009
|
-
|
|
2309
|
+
const silent = [...this.instrumentedProjects].filter((p) => !this.projectsWithRequests.has(p)).sort();
|
|
2310
|
+
if (silent.length > 0) {
|
|
1010
2311
|
issues.push({
|
|
1011
|
-
code: "
|
|
1012
|
-
message:
|
|
1013
|
-
hint:
|
|
2312
|
+
code: "RUN_PROJECT_NO_REQUESTS",
|
|
2313
|
+
message: `Measured ${silent.length === 1 ? "project" : "projects"} ${silent.join(", ")} recorded no request sample.`,
|
|
2314
|
+
hint: "Tests that only use the request fixture (API tests) are not measured: requests made outside the browser are out of scope; remove such projects from run.projects. Otherwise check use.baseURL, withPerfFixtures and measure.include/exclude."
|
|
1014
2315
|
});
|
|
1015
2316
|
}
|
|
1016
|
-
if (this.
|
|
2317
|
+
if (this.notInstrumented > 0) {
|
|
1017
2318
|
issues.push({
|
|
1018
|
-
code: "
|
|
1019
|
-
message: `${
|
|
1020
|
-
hint:
|
|
2319
|
+
code: "TESTS_NOT_INSTRUMENTED",
|
|
2320
|
+
message: `${plural2(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.`,
|
|
2321
|
+
hint: 'Import test from a test object wrapped with withPerfFixtures() (or from "playwright-performance-regression/test"); a crashed worker also loses the attachment.'
|
|
1021
2322
|
});
|
|
1022
2323
|
}
|
|
1023
2324
|
if (this.withArtifacts > 0) {
|
|
1024
2325
|
issues.push({
|
|
1025
2326
|
code: "RUN_CONDITIONS_CHANGED",
|
|
1026
|
-
message: `${
|
|
2327
|
+
message: `${plural2(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
2328
|
hint: "Remove test.use({ trace, video }) from test files for perf-mode runs."
|
|
1028
2329
|
});
|
|
1029
2330
|
}
|
|
@@ -1036,15 +2337,28 @@ var RunSession = class {
|
|
|
1036
2337
|
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
2338
|
return {
|
|
1038
2339
|
code: "COLLECTOR_REQUESTS_PENDING",
|
|
1039
|
-
message: `${
|
|
2340
|
+
message: `${plural2(total, "request was", "requests were")} still pending at the end of a test; most in: ${top.join(", ")}.`,
|
|
1040
2341
|
hint: "Exclude long polling and streaming with measure.exclude, or raise measure.pendingTimeoutMs."
|
|
1041
2342
|
};
|
|
1042
2343
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
2344
|
+
/** Test counts of this pass only. */
|
|
2345
|
+
ownTests() {
|
|
2346
|
+
const tests = { expected: 0, unexpected: 0, flaky: 0, skipped: 0 };
|
|
1045
2347
|
for (const test of this.testsSeen) tests[test.outcome()] += 1;
|
|
1046
2348
|
return tests;
|
|
1047
2349
|
}
|
|
2350
|
+
/** Test counts of the run: the sum over the merged passes (02-REQ-37). */
|
|
2351
|
+
testsResult(status) {
|
|
2352
|
+
const own = this.ownTests();
|
|
2353
|
+
const merged = this.mergedTests;
|
|
2354
|
+
return {
|
|
2355
|
+
status,
|
|
2356
|
+
expected: own.expected + merged.expected,
|
|
2357
|
+
unexpected: own.unexpected + merged.unexpected,
|
|
2358
|
+
flaky: own.flaky + merged.flaky,
|
|
2359
|
+
skipped: own.skipped + merged.skipped
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
1048
2362
|
source() {
|
|
1049
2363
|
const browsers = this.conditions.projects.filter((p) => p.role === "measured" && p.browserName !== null).map((p) => p.browserName);
|
|
1050
2364
|
const { nodeVersion: _, ...host } = this.host.host;
|
|
@@ -1052,7 +2366,8 @@ var RunSession = class {
|
|
|
1052
2366
|
browsers: [...new Set(browsers)].sort(),
|
|
1053
2367
|
playwrightVersion: this.playwrightVersion,
|
|
1054
2368
|
host,
|
|
1055
|
-
normalization: this.normalization
|
|
2369
|
+
normalization: this.normalization,
|
|
2370
|
+
stepNormalization: this.steps.fingerprint()
|
|
1056
2371
|
};
|
|
1057
2372
|
}
|
|
1058
2373
|
reportInput(status, finishedAt, aggregates, evaluation, warnings, toolErrors) {
|
|
@@ -1071,6 +2386,12 @@ var RunSession = class {
|
|
|
1071
2386
|
},
|
|
1072
2387
|
config: this.settings.snapshot,
|
|
1073
2388
|
normalization: this.normalization,
|
|
2389
|
+
stepNormalization: this.steps.fingerprint(),
|
|
2390
|
+
passes: {
|
|
2391
|
+
planned: this.passes,
|
|
2392
|
+
completed: this.completedPasses,
|
|
2393
|
+
failed: [...this.failedPasses]
|
|
2394
|
+
},
|
|
1074
2395
|
runConditions: this.conditions,
|
|
1075
2396
|
tests: this.testsResult(status),
|
|
1076
2397
|
aggregates,
|
|
@@ -1091,20 +2412,170 @@ var RunSession = class {
|
|
|
1091
2412
|
* outcome exit code is not 0, otherwise nothing, so Playwright keeps its own (01-REQ-17).
|
|
1092
2413
|
*/
|
|
1093
2414
|
async end(result) {
|
|
2415
|
+
if (this.cancelled) return void 0;
|
|
2416
|
+
if (this.passIndex > 1) return this.endLaterPass(result);
|
|
1094
2417
|
if (this.testsStarted === 0) return void 0;
|
|
2418
|
+
if (this.check) return this.endCheck(result);
|
|
2419
|
+
let status = result.status;
|
|
1095
2420
|
let outcome;
|
|
1096
2421
|
try {
|
|
1097
|
-
|
|
2422
|
+
if (this.passes > 1) status = await this.runPasses(result);
|
|
2423
|
+
outcome = await this.finish({ status });
|
|
1098
2424
|
} catch (error) {
|
|
1099
2425
|
this.recordInternalError("onEnd", error);
|
|
1100
|
-
outcome = this.fallbackOutcome(
|
|
2426
|
+
outcome = this.fallbackOutcome({ status });
|
|
1101
2427
|
for (const issue of outcome.toolErrors) {
|
|
1102
2428
|
this.host.stderr.write(`${PACKAGE_NAME}: ${issue.code}: ${issue.message}
|
|
1103
2429
|
`);
|
|
1104
2430
|
}
|
|
1105
2431
|
}
|
|
1106
|
-
await this.writeOutcome(outcome);
|
|
1107
|
-
|
|
2432
|
+
const written = await this.writeOutcome(outcome);
|
|
2433
|
+
if (this.environmentMode && written !== null) {
|
|
2434
|
+
this.host.stdout.write(outcomeLine(outcome, written));
|
|
2435
|
+
}
|
|
2436
|
+
if (this.next !== null) {
|
|
2437
|
+
this.host.stdout.write(nextLine(this.next, this.terminal().color));
|
|
2438
|
+
}
|
|
2439
|
+
const testsFailed = status === "failed" && result.status === "passed" && this.environmentMode;
|
|
2440
|
+
return outcome.exitCode === 0 && !testsFailed ? void 0 : { status: "failed" };
|
|
2441
|
+
}
|
|
2442
|
+
/** Data of this pass for the first pass (02-REQ-36). */
|
|
2443
|
+
passFile(status, finishedAt) {
|
|
2444
|
+
return {
|
|
2445
|
+
format: "pw-perf-pass",
|
|
2446
|
+
schemaVersion: 1,
|
|
2447
|
+
toolVersion: this.settings.packageVersion,
|
|
2448
|
+
runId: this.runId,
|
|
2449
|
+
pass: { index: this.passIndex, total: this.passes },
|
|
2450
|
+
startedAt: this.startedAt.toISOString(),
|
|
2451
|
+
finishedAt: finishedAt.toISOString(),
|
|
2452
|
+
status,
|
|
2453
|
+
tests: this.ownTests(),
|
|
2454
|
+
counters: {
|
|
2455
|
+
testsStarted: this.testsStarted,
|
|
2456
|
+
notInstrumented: this.notInstrumented,
|
|
2457
|
+
withArtifacts: this.withArtifacts,
|
|
2458
|
+
instrumentedProjects: [...this.instrumentedProjects].sort(),
|
|
2459
|
+
projectsWithRequests: [...this.projectsWithRequests].sort(),
|
|
2460
|
+
pending: Object.fromEntries([...this.pending].sort((a, b) => a[0] < b[0] ? -1 : 1))
|
|
2461
|
+
},
|
|
2462
|
+
warnings: this.warnings.slice(this.beginWarnings),
|
|
2463
|
+
toolErrors: this.toolErrors.slice(this.beginToolErrors),
|
|
2464
|
+
entries: this.aggregator.journal ?? []
|
|
2465
|
+
};
|
|
2466
|
+
}
|
|
2467
|
+
passPath(index) {
|
|
2468
|
+
return this.host.io.resolvePath(this.reportDir(), passFileName(index));
|
|
2469
|
+
}
|
|
2470
|
+
/** onEnd of pass k > 1 (04-REQ-64): the pass file and one line, no evaluation. */
|
|
2471
|
+
async endLaterPass(result) {
|
|
2472
|
+
const label = `pass ${String(this.passIndex)}/${String(this.passes)}`;
|
|
2473
|
+
const file = this.passFile(result.status, this.host.now());
|
|
2474
|
+
const path = this.passPath(this.passIndex);
|
|
2475
|
+
try {
|
|
2476
|
+
await this.host.io.writeJsonStable(path, file);
|
|
2477
|
+
} catch (error) {
|
|
2478
|
+
this.host.stderr.write(
|
|
2479
|
+
`${PACKAGE_NAME}: ${label}: the pass file could not be written to ${path}: ${error instanceof Error ? error.message : String(error)}
|
|
2480
|
+
`
|
|
2481
|
+
);
|
|
2482
|
+
return void 0;
|
|
2483
|
+
}
|
|
2484
|
+
const samples = file.entries.filter((e) => e[0] !== "e").length;
|
|
2485
|
+
this.info(`${label} done: ${plural2(this.testsStarted, "test")}, ${plural2(samples, "sample")}.`);
|
|
2486
|
+
return void 0;
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* Passes 2…N of the first pass (04-REQ-63, 04-REQ-64): writes pass-1.json, runs every further
|
|
2490
|
+
* pass with the same command and merges its pass file. Returns the status of the run.
|
|
2491
|
+
*/
|
|
2492
|
+
async runPasses(result) {
|
|
2493
|
+
let status = result.status;
|
|
2494
|
+
if (status !== "passed" && status !== "failed") return status;
|
|
2495
|
+
const io = this.host.io;
|
|
2496
|
+
try {
|
|
2497
|
+
await io.writeJsonStable(this.passPath(1), this.passFile(status, this.host.now()));
|
|
2498
|
+
} catch {
|
|
2499
|
+
}
|
|
2500
|
+
this.aggregator.journal = null;
|
|
2501
|
+
const total = this.passes;
|
|
2502
|
+
const command = passCommand({
|
|
2503
|
+
execPath: this.host.execPath,
|
|
2504
|
+
argv: this.host.argv,
|
|
2505
|
+
env: this.host.env,
|
|
2506
|
+
scripts: io.readPackageInfo(this.host.cwd).scripts ?? {}
|
|
2507
|
+
});
|
|
2508
|
+
const shown = [command.file, ...command.args].join(" ");
|
|
2509
|
+
for (let index = 2; index <= total; index += 1) {
|
|
2510
|
+
const label = `pass ${String(index)}/${String(total)}`;
|
|
2511
|
+
this.info(`${label}: starting ${shown}`);
|
|
2512
|
+
const env = {
|
|
2513
|
+
...this.host.env,
|
|
2514
|
+
...writeModeState({ ...this.settings.mode, runId: this.runId, pass: { index, total } })
|
|
2515
|
+
};
|
|
2516
|
+
const exit = await this.host.runPass(command, env);
|
|
2517
|
+
if (exit.error !== void 0) {
|
|
2518
|
+
this.toolErrors.push({
|
|
2519
|
+
code: "RUN_PASS_SPAWN_FAILED",
|
|
2520
|
+
message: `${label} could not be started (${shown}): ${exit.error}`,
|
|
2521
|
+
hint: "Check that the test command runs on its own; set run.passes to 1 to measure in one pass."
|
|
2522
|
+
});
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
if (exit.signal !== null || exit.code === 130 || exit.code === 143) {
|
|
2526
|
+
const rest = index < total ? `passes ${String(index + 1)}–${String(total)} did not run` : "it was the last pass";
|
|
2527
|
+
this.toolErrors.push({
|
|
2528
|
+
code: "RUN_PASS_INTERRUPTED",
|
|
2529
|
+
message: `${label} was interrupted (${exit.signal ?? `exit code ${String(exit.code)}`}); ${rest}.`,
|
|
2530
|
+
hint: "Run the measurement again; the evaluation of the completed passes is in the report."
|
|
2531
|
+
});
|
|
2532
|
+
break;
|
|
2533
|
+
}
|
|
2534
|
+
const path = this.passPath(index);
|
|
2535
|
+
let text;
|
|
2536
|
+
try {
|
|
2537
|
+
text = await io.readTextFile(path);
|
|
2538
|
+
} catch {
|
|
2539
|
+
text = null;
|
|
2540
|
+
}
|
|
2541
|
+
const parsed = text === null ? { ok: false, reason: "no pass file was written" } : parsePassFile(text, {
|
|
2542
|
+
toolVersion: this.settings.packageVersion,
|
|
2543
|
+
runId: this.runId,
|
|
2544
|
+
index,
|
|
2545
|
+
total
|
|
2546
|
+
});
|
|
2547
|
+
if (!parsed.ok) {
|
|
2548
|
+
this.failedPasses.push(index);
|
|
2549
|
+
this.warnings.push({
|
|
2550
|
+
code: "RUN_PASS_FAILED",
|
|
2551
|
+
message: `${label} produced no results (exit code ${String(exit.code)}: ${parsed.reason}), e.g. a setup step of the test script failed.`,
|
|
2552
|
+
hint: "The evaluation uses the other passes; check the output of that pass above."
|
|
2553
|
+
});
|
|
2554
|
+
continue;
|
|
2555
|
+
}
|
|
2556
|
+
this.mergePass(parsed.value);
|
|
2557
|
+
status = worseStatus(status, parsed.value.status);
|
|
2558
|
+
}
|
|
2559
|
+
return status;
|
|
2560
|
+
}
|
|
2561
|
+
/** Adds the data of a later pass to this run (04-REQ-64). */
|
|
2562
|
+
mergePass(file) {
|
|
2563
|
+
replayEntries(this.aggregator, file.entries);
|
|
2564
|
+
for (const name of ["expected", "unexpected", "flaky", "skipped"]) {
|
|
2565
|
+
this.mergedTests[name] += file.tests[name];
|
|
2566
|
+
}
|
|
2567
|
+
const c = file.counters;
|
|
2568
|
+
this.testsStarted += c.testsStarted;
|
|
2569
|
+
this.notInstrumented += c.notInstrumented;
|
|
2570
|
+
this.withArtifacts += c.withArtifacts;
|
|
2571
|
+
for (const p of c.instrumentedProjects) this.instrumentedProjects.add(p);
|
|
2572
|
+
for (const p of c.projectsWithRequests) this.projectsWithRequests.add(p);
|
|
2573
|
+
for (const [key, n] of Object.entries(c.pending)) {
|
|
2574
|
+
this.pending.set(key, (this.pending.get(key) ?? 0) + n);
|
|
2575
|
+
}
|
|
2576
|
+
this.warnings.push(...file.warnings);
|
|
2577
|
+
this.toolErrors.push(...file.toolErrors);
|
|
2578
|
+
this.completedPasses += 1;
|
|
1108
2579
|
}
|
|
1109
2580
|
async finish(result) {
|
|
1110
2581
|
const cfg = this.settings.config;
|
|
@@ -1113,7 +2584,11 @@ var RunSession = class {
|
|
|
1113
2584
|
const warnings = [...this.warnings, ...this.runWarnings()];
|
|
1114
2585
|
const toolErrors = [...this.toolErrors];
|
|
1115
2586
|
const aggregates = this.aggregator.finalize();
|
|
1116
|
-
warnings.push(
|
|
2587
|
+
warnings.push(
|
|
2588
|
+
...aggregates.issues,
|
|
2589
|
+
...detectKeyExplosion(Object.keys(aggregates.endpoints)),
|
|
2590
|
+
...this.steps.issues(Object.keys(aggregates.steps))
|
|
2591
|
+
);
|
|
1117
2592
|
const pending = this.pendingWarning();
|
|
1118
2593
|
if (pending !== null) warnings.push(pending);
|
|
1119
2594
|
const tests = this.testsResult(result.status);
|
|
@@ -1127,7 +2602,8 @@ var RunSession = class {
|
|
|
1127
2602
|
configDir: this.configDir,
|
|
1128
2603
|
dir: cfg.thresholds.dir,
|
|
1129
2604
|
filePrefix: cfg.thresholds.filePrefix,
|
|
1130
|
-
env: cfg.run.env
|
|
2605
|
+
env: cfg.run.env,
|
|
2606
|
+
steps: cfg.measure.steps.enabled
|
|
1131
2607
|
};
|
|
1132
2608
|
const loaded = await io.loadThresholds(location);
|
|
1133
2609
|
const evaluation = evaluate(aggregates, loaded, cfg, {
|
|
@@ -1192,7 +2668,12 @@ var RunSession = class {
|
|
|
1192
2668
|
}
|
|
1193
2669
|
const { width, color } = this.terminal();
|
|
1194
2670
|
this.host.stdout.write(
|
|
1195
|
-
formatSummary(report, {
|
|
2671
|
+
formatSummary(report, {
|
|
2672
|
+
width,
|
|
2673
|
+
color,
|
|
2674
|
+
ascii: asciiTerminal(this.host.env),
|
|
2675
|
+
html: paths.reportHtml !== null
|
|
2676
|
+
})
|
|
1196
2677
|
);
|
|
1197
2678
|
if (diffs.length > 0) {
|
|
1198
2679
|
this.host.stdout.write(
|
|
@@ -1200,13 +2681,239 @@ var RunSession = class {
|
|
|
1200
2681
|
paths: diffPaths.map((p) => io.relativeSlashPath(this.host.cwd, p)),
|
|
1201
2682
|
width,
|
|
1202
2683
|
color,
|
|
1203
|
-
prune: this.
|
|
1204
|
-
|
|
2684
|
+
prune: this.pruned,
|
|
2685
|
+
// Absolute, like the Report line of the summary (10, chapter 9.1; 09-REQ-30).
|
|
2686
|
+
diffPath: paths.thresholdsDiff
|
|
1205
2687
|
})
|
|
1206
2688
|
);
|
|
1207
2689
|
}
|
|
2690
|
+
this.next = nextHint({ report, commands: this.commands(), written: this.written });
|
|
1208
2691
|
return buildOutcome(report, paths);
|
|
1209
2692
|
}
|
|
2693
|
+
countCheck(test, result, measured) {
|
|
2694
|
+
const c = this.checkRun;
|
|
2695
|
+
const duration = result.duration ?? 0;
|
|
2696
|
+
if (!measured) {
|
|
2697
|
+
c.setupMs += duration;
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
if (result.status === "skipped") {
|
|
2701
|
+
c.skipped += 1;
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
c.ran += 1;
|
|
2705
|
+
if (result.status === "passed" || result.status === test.expectedStatus) c.passed += 1;
|
|
2706
|
+
else c.failed += 1;
|
|
2707
|
+
c.durations.push(duration);
|
|
2708
|
+
const project = projectName(test);
|
|
2709
|
+
c.tests.set(project, (c.tests.get(project) ?? 0) + 1);
|
|
2710
|
+
}
|
|
2711
|
+
/** onEnd of a check (04-REQ-50, 04-REQ-53): output, no report, no files; outcome only via the CLI. */
|
|
2712
|
+
async endCheck(result) {
|
|
2713
|
+
let outcome;
|
|
2714
|
+
try {
|
|
2715
|
+
outcome = await this.finishCheck(result);
|
|
2716
|
+
} catch (error) {
|
|
2717
|
+
this.recordInternalError("onEnd", error);
|
|
2718
|
+
outcome = {
|
|
2719
|
+
...this.fallbackOutcome(result),
|
|
2720
|
+
mode: "check",
|
|
2721
|
+
evaluation: { status: "error", gateEnabled: false }
|
|
2722
|
+
};
|
|
2723
|
+
}
|
|
2724
|
+
if (!this.environmentMode) await this.writeOutcome(outcome);
|
|
2725
|
+
if (this.settings.mode.runId !== void 0) {
|
|
2726
|
+
try {
|
|
2727
|
+
this.host.io.removeFileSync(
|
|
2728
|
+
this.host.io.tempPath(checkStateFileName(this.settings.mode.runId))
|
|
2729
|
+
);
|
|
2730
|
+
} catch {
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
if (this.next !== null) this.host.stdout.write(nextLine(this.next, this.terminal().color));
|
|
2734
|
+
return outcome.exitCode === 0 ? void 0 : { status: "failed" };
|
|
2735
|
+
}
|
|
2736
|
+
async finishCheck(result) {
|
|
2737
|
+
const cfg = this.settings.config;
|
|
2738
|
+
const config = this.configLike;
|
|
2739
|
+
const c = this.checkRun;
|
|
2740
|
+
const aggregates = this.aggregator.finalize();
|
|
2741
|
+
const tests = this.testsResult(result.status);
|
|
2742
|
+
const assessment = assessRun(
|
|
2743
|
+
{ tests, maxFailures: this.maxFailures, sharded: false },
|
|
2744
|
+
{ maxFailedTestShare: 1 }
|
|
2745
|
+
);
|
|
2746
|
+
const toolErrors = [...this.toolErrors, ...assessment.toolErrors];
|
|
2747
|
+
const baseUrls = this.conditions.projects.map((p, i) => ({
|
|
2748
|
+
project: p,
|
|
2749
|
+
baseURL: config?.projects[i]?.use.baseURL ?? null
|
|
2750
|
+
}));
|
|
2751
|
+
const warnings = [
|
|
2752
|
+
...this.warnings,
|
|
2753
|
+
...this.runWarnings(),
|
|
2754
|
+
...assessment.warnings,
|
|
2755
|
+
...aggregates.issues,
|
|
2756
|
+
...detectKeyExplosion(Object.keys(aggregates.endpoints)),
|
|
2757
|
+
...this.steps.issues(Object.keys(aggregates.steps))
|
|
2758
|
+
];
|
|
2759
|
+
const unset = baseUrls.filter(
|
|
2760
|
+
(b) => b.project.role === "measured" && (b.baseURL === null || b.baseURL === void 0)
|
|
2761
|
+
).map((b) => b.project.name);
|
|
2762
|
+
if (unset.length > 0) {
|
|
2763
|
+
warnings.push({
|
|
2764
|
+
code: "CONFIG_BASEURL_EMPTY",
|
|
2765
|
+
message: `Measured ${unset.length === 1 ? "project" : "projects"} ${unset.join(", ")} ${unset.length === 1 ? "has" : "have"} no use.baseURL.`,
|
|
2766
|
+
hint: "If baseURL comes from environment variables, run the tests through the script that sets them (e.g. PW_PERF_MODE=check npm run e2e:qa, see docs/dynamic-environments.md)."
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
const keys = cfg.keys;
|
|
2770
|
+
const baseOrigins = baseUrls.flatMap(
|
|
2771
|
+
(b) => b.project.role === "measured" && typeof b.baseURL === "string" ? [b.baseURL] : []
|
|
2772
|
+
);
|
|
2773
|
+
const candidates = [
|
|
2774
|
+
...aggregates.origins.map((o) => o.origin),
|
|
2775
|
+
...baseOrigins.flatMap((u) => {
|
|
2776
|
+
try {
|
|
2777
|
+
return [new URL(u).origin];
|
|
2778
|
+
} catch {
|
|
2779
|
+
return [];
|
|
2780
|
+
}
|
|
2781
|
+
})
|
|
2782
|
+
];
|
|
2783
|
+
const baseSet = new Set(
|
|
2784
|
+
baseOrigins.flatMap((u) => URL.canParse(u) ? [new URL(u).origin] : [])
|
|
2785
|
+
);
|
|
2786
|
+
const random = randomHostIssue(
|
|
2787
|
+
[...new Set(candidates)].filter((o) => !coveredByOrigins(keys.origins, o)).map((origin) => ({ origin, base: baseSet.has(origin) }))
|
|
2788
|
+
);
|
|
2789
|
+
if (random !== null) warnings.push(random);
|
|
2790
|
+
const patterns = compileHostPatterns(keys.origins);
|
|
2791
|
+
const exact = new Set(
|
|
2792
|
+
Object.keys(keys.origins).filter((k) => !isHostPattern(k)).flatMap((k) => URL.canParse(k) ? [new URL(k).origin] : [])
|
|
2793
|
+
);
|
|
2794
|
+
const origins = [...aggregates.origins].sort((a, b) => b.requestCount - a.requestCount || (a.origin < b.origin ? -1 : 1)).map((o) => {
|
|
2795
|
+
const pattern = URL.canParse(o.origin) ? matchingPattern(patterns, new URL(o.origin)) : null;
|
|
2796
|
+
const source = exact.has(o.origin) ? "keys.origins" : pattern !== null ? `keys.origins pattern ${pattern.canonical}` : baseSet.has(o.origin) ? "baseURL" : "host";
|
|
2797
|
+
return { origin: o.origin, label: o.label, requests: o.requestCount, source };
|
|
2798
|
+
});
|
|
2799
|
+
const topKeys = [
|
|
2800
|
+
...Object.entries(aggregates.endpoints).map(([key, a]) => ({
|
|
2801
|
+
kind: "api",
|
|
2802
|
+
key,
|
|
2803
|
+
samples: a.count,
|
|
2804
|
+
tests: a.testCount
|
|
2805
|
+
})),
|
|
2806
|
+
...Object.entries(aggregates.steps).map(([key, a]) => ({
|
|
2807
|
+
kind: "step",
|
|
2808
|
+
key,
|
|
2809
|
+
samples: a.count,
|
|
2810
|
+
tests: a.testCount
|
|
2811
|
+
}))
|
|
2812
|
+
].sort(
|
|
2813
|
+
(a, b) => b.samples - a.samples || (a.kind === b.kind ? 0 : a.kind === "api" ? -1 : 1) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
|
|
2814
|
+
).slice(0, 10);
|
|
2815
|
+
const location = {
|
|
2816
|
+
configDir: this.configDir,
|
|
2817
|
+
dir: cfg.thresholds.dir,
|
|
2818
|
+
filePrefix: cfg.thresholds.filePrefix,
|
|
2819
|
+
env: cfg.run.env,
|
|
2820
|
+
steps: cfg.measure.steps.enabled
|
|
2821
|
+
};
|
|
2822
|
+
const loaded = await this.host.io.loadThresholds(location);
|
|
2823
|
+
const kindsWithKeys = {
|
|
2824
|
+
api: Object.keys(aggregates.endpoints).length > 0,
|
|
2825
|
+
step: Object.keys(aggregates.steps).length > 0
|
|
2826
|
+
};
|
|
2827
|
+
const thresholdsFiles = ["api", "step"].filter((kind) => kind === "api" || kindsWithKeys.step || !cfg.measure.steps.enabled).map((kind) => {
|
|
2828
|
+
const file = loaded[kind];
|
|
2829
|
+
if (kind === "step" && !cfg.measure.steps.enabled)
|
|
2830
|
+
return { kind, name: file.path, state: "not used" };
|
|
2831
|
+
const state = file.status === "loaded" ? `${String(Object.keys(file.file.entries).length)} entries` : file.status === "missing" ? "missing" : `invalid (${file.issues[0]?.code ?? "SCHEMA_VALIDATION_FAILED"})`;
|
|
2832
|
+
return { kind, name: file.path, state };
|
|
2833
|
+
});
|
|
2834
|
+
const missingFile = ["api", "step"].some(
|
|
2835
|
+
(kind) => kindsWithKeys[kind] && loaded[kind].status !== "loaded"
|
|
2836
|
+
);
|
|
2837
|
+
const meanMs = c.durations.length === 0 ? null : c.durations.reduce((a, b) => a + b, 0) / c.durations.length;
|
|
2838
|
+
const reporters = (config?.reporter ?? []).map(
|
|
2839
|
+
([name]) => /playwright-performance-regression|[\\/]dist[\\/]reporter\.c?js$/u.test(name) ? "pw-perf" : name
|
|
2840
|
+
);
|
|
2841
|
+
const { width, color } = this.terminal();
|
|
2842
|
+
this.host.stdout.write(
|
|
2843
|
+
formatCheckSummary(
|
|
2844
|
+
{
|
|
2845
|
+
packageName: "pw-perf",
|
|
2846
|
+
ran: c.ran,
|
|
2847
|
+
selected: c.selected,
|
|
2848
|
+
passed: c.passed,
|
|
2849
|
+
failed: c.failed,
|
|
2850
|
+
skippedByCheck: c.skipped,
|
|
2851
|
+
projects: this.conditions.projects.map((p, i) => ({
|
|
2852
|
+
name: p.name,
|
|
2853
|
+
role: p.role,
|
|
2854
|
+
browserName: p.browserName,
|
|
2855
|
+
baseURL: config?.projects[i]?.use.baseURL ?? null,
|
|
2856
|
+
requests: c.requests.get(p.name) ?? 0,
|
|
2857
|
+
tests: c.tests.get(p.name) ?? 0
|
|
2858
|
+
})),
|
|
2859
|
+
removedProjects: this.settings.runConditions.removedProjects,
|
|
2860
|
+
reporters: {
|
|
2861
|
+
kept: reporters,
|
|
2862
|
+
replaced: this.settings.runConditions.replacedReporters,
|
|
2863
|
+
removed: this.settings.runConditions.removedReporters
|
|
2864
|
+
},
|
|
2865
|
+
requests: aggregates.origins.reduce((n, o) => n + o.requestCount, 0),
|
|
2866
|
+
apiKeys: Object.keys(aggregates.endpoints).length,
|
|
2867
|
+
stepKeys: Object.keys(aggregates.steps).length,
|
|
2868
|
+
origins,
|
|
2869
|
+
topKeys,
|
|
2870
|
+
thresholdsFiles,
|
|
2871
|
+
warnings: collapseIssues(warnings),
|
|
2872
|
+
toolErrors: collapseIssues(toolErrors),
|
|
2873
|
+
estimate: estimateText({
|
|
2874
|
+
tests: c.selected,
|
|
2875
|
+
passesTest: this.settings.mode.passes ?? cfg.run.passes.test,
|
|
2876
|
+
passesThresholds: cfg.run.passes.thresholds,
|
|
2877
|
+
meanMs,
|
|
2878
|
+
setupMs: c.setupMs
|
|
2879
|
+
})
|
|
2880
|
+
},
|
|
2881
|
+
{ width, color, ascii: asciiTerminal(this.host.env) }
|
|
2882
|
+
)
|
|
2883
|
+
);
|
|
2884
|
+
const commands = this.commands();
|
|
2885
|
+
this.next = toolErrors.length > 0 ? null : !kindsWithKeys.api && !kindsWithKeys.step ? `nothing was measured: check use.baseURL and run.projects, then run ${commands.check}` : missingFile ? `derive thresholds on the CI machines: ${commands.thresholds}` : `run the measurement: ${commands.test}`;
|
|
2886
|
+
return {
|
|
2887
|
+
schemaVersion: SCHEMA_VERSIONS.outcome,
|
|
2888
|
+
runId: this.runId,
|
|
2889
|
+
mode: "check",
|
|
2890
|
+
exitCode: toolErrors.length > 0 ? 3 : 0,
|
|
2891
|
+
tests: { status: result.status },
|
|
2892
|
+
evaluation: { status: toolErrors.length > 0 ? "error" : "passed", gateEnabled: false },
|
|
2893
|
+
toolErrors: collapseIssues(toolErrors),
|
|
2894
|
+
paths: { reportJson: null, reportHtml: null, thresholds: [], thresholdsDiff: null }
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
/** Commands of the project for each mode, for the Next: hint (09-REQ-32). */
|
|
2898
|
+
commands() {
|
|
2899
|
+
const env = this.host.env;
|
|
2900
|
+
const info = this.host.io.readPackageInfo(this.configDir);
|
|
2901
|
+
const ctx = {
|
|
2902
|
+
viaCli: !this.environmentMode,
|
|
2903
|
+
env: this.settings.config.run.env,
|
|
2904
|
+
lifecycleEvent: env["npm_lifecycle_event"] ?? null,
|
|
2905
|
+
lifecycleScript: env["npm_lifecycle_script"] ?? null,
|
|
2906
|
+
userAgent: env["npm_config_user_agent"] ?? null,
|
|
2907
|
+
lockFiles: info.lockFiles,
|
|
2908
|
+
scripts: info.scripts,
|
|
2909
|
+
platform: this.host.host.platform
|
|
2910
|
+
};
|
|
2911
|
+
return {
|
|
2912
|
+
test: suggestCommand("test", ctx),
|
|
2913
|
+
thresholds: suggestCommand("thresholds", ctx),
|
|
2914
|
+
check: suggestCommand("check", ctx)
|
|
2915
|
+
};
|
|
2916
|
+
}
|
|
1210
2917
|
/**
|
|
1211
2918
|
* Writes report.html next to report.json (11-REQ-04). The page is rendered from the report as
|
|
1212
2919
|
* written to JSON, so `report` renders the same HTML from report.json (11-AC-10). Returns the
|
|
@@ -1246,7 +2953,7 @@ var RunSession = class {
|
|
|
1246
2953
|
const io = this.host.io;
|
|
1247
2954
|
const derived = deriveThresholds(report, cfg, loaded, {
|
|
1248
2955
|
env: cfg.run.env,
|
|
1249
|
-
prune: this.
|
|
2956
|
+
prune: this.prune(warnings),
|
|
1250
2957
|
toolVersion: this.settings.packageVersion
|
|
1251
2958
|
});
|
|
1252
2959
|
if (!derived.ok) {
|
|
@@ -1260,6 +2967,10 @@ var RunSession = class {
|
|
|
1260
2967
|
try {
|
|
1261
2968
|
await io.writeJsonStable(absolute[file.kind], file.content);
|
|
1262
2969
|
paths.thresholds.push(absolute[file.kind]);
|
|
2970
|
+
this.written.push({
|
|
2971
|
+
name: loaded[file.kind].path,
|
|
2972
|
+
entries: Object.keys(file.content.entries).length
|
|
2973
|
+
});
|
|
1263
2974
|
} catch (error) {
|
|
1264
2975
|
toolErrors.push({
|
|
1265
2976
|
code: "THRESHOLDS_WRITE_FAILED",
|
|
@@ -1307,20 +3018,82 @@ var RunSession = class {
|
|
|
1307
3018
|
paths: { reportJson: null, reportHtml: null, thresholds: [], thresholdsDiff: null }
|
|
1308
3019
|
};
|
|
1309
3020
|
}
|
|
1310
|
-
/**
|
|
1311
|
-
|
|
3021
|
+
/** Thresholds files written in this run, for the Next: hint (09-REQ-32). */
|
|
3022
|
+
written = [];
|
|
3023
|
+
/** Text of the Next: hint, set by finish(). */
|
|
3024
|
+
next = null;
|
|
3025
|
+
/** Whether entries not seen were removed in this run (04-REQ-35). */
|
|
3026
|
+
pruned = false;
|
|
3027
|
+
/**
|
|
3028
|
+
* PW_PERF_PRUNE in the environment mode with a test filter in the arguments: the files are
|
|
3029
|
+
* written without removing entries, with RUN_PRUNE_SKIPPED (04-REQ-35). The CLI rejects the
|
|
3030
|
+
* same case before the run.
|
|
3031
|
+
*/
|
|
3032
|
+
prune(warnings) {
|
|
3033
|
+
if (this.settings.mode.prune !== true) return false;
|
|
3034
|
+
const filters = this.environmentMode ? testFilters(testArgsFromArgv(this.host.argv)) : [];
|
|
3035
|
+
if (filters.length > 0) {
|
|
3036
|
+
warnings.push({
|
|
3037
|
+
code: "RUN_PRUNE_SKIPPED",
|
|
3038
|
+
message: `PW_PERF_PRUNE was ignored: the run selects a subset of the tests (${filters.join(" ")}), so entries not seen were kept.`,
|
|
3039
|
+
hint: "Prune in a run of all tests, without --grep, --project or file filters."
|
|
3040
|
+
});
|
|
3041
|
+
return false;
|
|
3042
|
+
}
|
|
3043
|
+
this.pruned = true;
|
|
3044
|
+
return true;
|
|
3045
|
+
}
|
|
3046
|
+
/** Run without the CLI: the CLI sets PW_PERF_OUTCOME_FILE (04-REQ-62, D-35). */
|
|
3047
|
+
get environmentMode() {
|
|
3048
|
+
return this.settings.mode.outcomeFile === void 0;
|
|
3049
|
+
}
|
|
3050
|
+
/** PW_PERF_OUTCOME_FILE, else <report.dir>/outcome.json (02-REQ-27, 04-REQ-62). */
|
|
3051
|
+
outcomePath() {
|
|
1312
3052
|
const file = this.settings.mode.outcomeFile;
|
|
1313
|
-
if (file
|
|
3053
|
+
if (file !== void 0) return file;
|
|
3054
|
+
const io = this.host.io;
|
|
3055
|
+
return io.resolvePath(
|
|
3056
|
+
io.resolvePath(this.configDir, this.settings.config.report.dir),
|
|
3057
|
+
"outcome.json"
|
|
3058
|
+
);
|
|
3059
|
+
}
|
|
3060
|
+
/** Last step of onEnd (02-REQ-27); returns the path written, or null. */
|
|
3061
|
+
async writeOutcome(outcome) {
|
|
3062
|
+
const file = this.outcomePath();
|
|
3063
|
+
if (file === null) return null;
|
|
1314
3064
|
try {
|
|
1315
3065
|
await this.host.io.writeJsonStable(file, outcome);
|
|
3066
|
+
return file;
|
|
1316
3067
|
} catch (error) {
|
|
1317
3068
|
this.host.stderr.write(
|
|
1318
3069
|
`${PACKAGE_NAME}: OUTCOME_WRITE_FAILED: the outcome file could not be written to ${file}: ${error instanceof Error ? error.message : String(error)}
|
|
1319
3070
|
`
|
|
1320
3071
|
);
|
|
3072
|
+
return null;
|
|
1321
3073
|
}
|
|
1322
3074
|
}
|
|
1323
3075
|
};
|
|
3076
|
+
function emptyBaseUrlWarning(conditions, config) {
|
|
3077
|
+
const names2 = conditions.projects.flatMap((p, i) => {
|
|
3078
|
+
if (p.role !== "measured") return [];
|
|
3079
|
+
const baseURL = config.projects[i]?.use.baseURL;
|
|
3080
|
+
if (typeof baseURL !== "string") return [];
|
|
3081
|
+
if (baseURL.trim() === "") return [p.name];
|
|
3082
|
+
let host;
|
|
3083
|
+
try {
|
|
3084
|
+
host = new URL(baseURL).hostname;
|
|
3085
|
+
} catch {
|
|
3086
|
+
return [];
|
|
3087
|
+
}
|
|
3088
|
+
return host.split(".").some((label) => label === "undefined" || label === "null") ? [p.name] : [];
|
|
3089
|
+
});
|
|
3090
|
+
if (names2.length === 0) return null;
|
|
3091
|
+
return {
|
|
3092
|
+
code: "CONFIG_BASEURL_EMPTY",
|
|
3093
|
+
message: `Measured ${names2.length === 1 ? "project" : "projects"} ${names2.join(", ")} ${names2.length === 1 ? "has" : "have"} an empty use.baseURL.`,
|
|
3094
|
+
hint: "If baseURL comes from environment variables, run the tests through the script that sets them (e.g. PW_PERF_MODE=test npm run e2e:qa, see docs/dynamic-environments.md)."
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
1324
3097
|
|
|
1325
3098
|
// src/reporter/perf-reporter.ts
|
|
1326
3099
|
function processHost() {
|
|
@@ -1334,15 +3107,26 @@ function processHost() {
|
|
|
1334
3107
|
writeTextAtomic,
|
|
1335
3108
|
resolvePath,
|
|
1336
3109
|
directoryOf,
|
|
1337
|
-
relativeSlashPath
|
|
3110
|
+
relativeSlashPath,
|
|
3111
|
+
removeFileSync,
|
|
3112
|
+
readPackageInfo,
|
|
3113
|
+
tempPath,
|
|
3114
|
+
readTextFile,
|
|
3115
|
+
readTextFileSync,
|
|
3116
|
+
listDirSync
|
|
1338
3117
|
},
|
|
1339
3118
|
stdout: process.stdout,
|
|
1340
3119
|
stderr: process.stderr,
|
|
1341
3120
|
cwd: process.cwd(),
|
|
3121
|
+
argv: process.argv,
|
|
1342
3122
|
now: () => /* @__PURE__ */ new Date(),
|
|
1343
3123
|
random: Math.random,
|
|
1344
3124
|
ci: readCiInfo(env),
|
|
1345
|
-
host: readHostInfo(env)
|
|
3125
|
+
host: readHostInfo(env),
|
|
3126
|
+
execPath: process.execPath,
|
|
3127
|
+
runPass: (command, passEnv) => runPass(command, passEnv, process.cwd()),
|
|
3128
|
+
ask: (question) => askTerminal(question),
|
|
3129
|
+
exit: (code) => process.exit(code)
|
|
1346
3130
|
};
|
|
1347
3131
|
}
|
|
1348
3132
|
var PerfReporter = class {
|