playwright-performance-regression 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -0
- package/README.md +11 -4
- package/dist/chunk-JS7SBYOF.js +11226 -0
- package/dist/{chunk-4WX3Z5MJ.js → chunk-PTQWKPHU.js} +276 -11
- package/dist/{chunk-5Y34Q4DR.js → chunk-Q73KMM6D.js} +95 -30
- package/dist/{chunk-PWK5XSP2.cjs → chunk-VBNIFMNE.cjs} +298 -32
- package/dist/{chunk-VREOANPX.cjs → chunk-VXGTC6DB.cjs} +78 -6
- package/dist/{chunk-W7NEFS5V.cjs → chunk-VYODYUEL.cjs} +95 -29
- package/dist/{chunk-YKBX6SAT.js → chunk-ZEQ2IGDC.js} +160 -11
- package/dist/cli.js +380 -15
- package/dist/config.cjs +16 -16
- package/dist/config.js +3 -4
- package/dist/fixture.cjs +6 -6
- package/dist/fixture.js +3 -4
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +85 -1
- package/dist/index.d.ts +85 -1
- package/dist/index.js +1 -1
- package/dist/reporter.cjs +1864 -622
- package/dist/reporter.js +7 -8137
- package/dist/test.cjs +4 -4
- package/dist/test.js +3 -4
- package/package.json +3 -3
- package/schemas/config.schema.json +91 -0
- package/schemas/run-report.schema.json +162 -7
- package/schemas/samples.schema.json +12 -3
- package/schemas/thresholds.schema.json +29 -1
- package/dist/chunk-B4XTLSRN.js +0 -1788
- package/dist/chunk-S6UH6QPK.js +0 -68
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkVXGTC6DB_cjs = require('./chunk-VXGTC6DB.cjs');
|
|
4
|
+
var chunkVYODYUEL_cjs = require('./chunk-VYODYUEL.cjs');
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var os = require('os');
|
|
7
7
|
var path = require('path');
|
|
8
8
|
|
|
9
9
|
var memory = { files: [], ran: 0 };
|
|
10
10
|
function checkStatePath(runId) {
|
|
11
|
-
return path.join(os.tmpdir(),
|
|
11
|
+
return path.join(os.tmpdir(), chunkVXGTC6DB_cjs.checkStateFileName(runId));
|
|
12
12
|
}
|
|
13
13
|
function load(path) {
|
|
14
14
|
if (path === null) return memory;
|
|
@@ -78,7 +78,7 @@ function isPromise(value) {
|
|
|
78
78
|
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
79
79
|
}
|
|
80
80
|
function wrapRequestContext(context, source, baseURL, recorder) {
|
|
81
|
-
const wrapped =
|
|
81
|
+
const wrapped = chunkVXGTC6DB_cjs.wrappedRequestContexts();
|
|
82
82
|
if (wrapped.has(context)) return false;
|
|
83
83
|
wrapped.add(context);
|
|
84
84
|
const target = context;
|
|
@@ -103,7 +103,7 @@ function wrapRequestContext(context, source, baseURL, recorder) {
|
|
|
103
103
|
depth -= 1;
|
|
104
104
|
}
|
|
105
105
|
if (described === void 0 || !isPromise(result)) return result;
|
|
106
|
-
return active.observeApiCall(described, source, result);
|
|
106
|
+
return active.observeApiCall(described, source, result, args[1]);
|
|
107
107
|
};
|
|
108
108
|
Object.defineProperty(target, name, {
|
|
109
109
|
value: wrapper,
|
|
@@ -114,6 +114,29 @@ function wrapRequestContext(context, source, baseURL, recorder) {
|
|
|
114
114
|
}
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
|
+
function isPlainRecord(value) {
|
|
118
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
119
|
+
}
|
|
120
|
+
function urlWithParams(url, options) {
|
|
121
|
+
const params = isPlainRecord(options) ? options.params : void 0;
|
|
122
|
+
if (params === void 0 || params === null) return url;
|
|
123
|
+
try {
|
|
124
|
+
const out = new URL(url);
|
|
125
|
+
const extra = typeof params === "string" || params instanceof URLSearchParams ? new URLSearchParams(params) : isPlainRecord(params) ? Object.entries(params).map(([name, value]) => [name, String(value)]) : [];
|
|
126
|
+
for (const [name, value] of extra) out.searchParams.set(name, value);
|
|
127
|
+
return out.toString();
|
|
128
|
+
} catch {
|
|
129
|
+
return url;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function apiOperationBody(options) {
|
|
133
|
+
if (!isPlainRecord(options)) return null;
|
|
134
|
+
const { data, multipart } = options;
|
|
135
|
+
if (typeof data === "string") return { text: data };
|
|
136
|
+
if (isPlainRecord(data) || Array.isArray(data)) return { value: data };
|
|
137
|
+
if (isPlainRecord(multipart)) return { multipartOperations: multipart.operations };
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
117
140
|
|
|
118
141
|
// src/collector/perf-api.ts
|
|
119
142
|
function createPerfApi(track, trackRequestContext2 = () => {
|
|
@@ -157,6 +180,7 @@ var KNOWN_THIRD_PARTY_HOSTS = Object.freeze([
|
|
|
157
180
|
var PENDING_RESERVE_MS = 1e3;
|
|
158
181
|
var SAMPLE_LIMIT_PER_TEST = 2e4;
|
|
159
182
|
var COLLECTOR_NAME = "playwright-js";
|
|
183
|
+
var OPERATION_BODY_LIMIT = 65536;
|
|
160
184
|
|
|
161
185
|
// src/collector/diagnostics.ts
|
|
162
186
|
function createDiagnostics() {
|
|
@@ -180,6 +204,185 @@ function errorText(error) {
|
|
|
180
204
|
if (error instanceof Error) return error.message;
|
|
181
205
|
return String(error);
|
|
182
206
|
}
|
|
207
|
+
function operationUnknown(method, pattern, reason) {
|
|
208
|
+
const entry = pattern === null ? "keys.operations" : `the keys.operations entry ${patternText(pattern)}`;
|
|
209
|
+
return {
|
|
210
|
+
code: "COLLECTOR_OPERATION_UNKNOWN",
|
|
211
|
+
message: `collector: a ${method} request matching ${entry} has no readable operation name, so it keeps the key without an operation${reason === void 0 ? "" : ` (${reason})`}`,
|
|
212
|
+
hint: "GraphQL clients send operationName or a named operation in a JSON body (read up to 64 KB) or in the query parameters; tRPC clients put procedure names in the path. If the endpoint is neither, narrow the match of the entry."
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function patternText(pattern) {
|
|
216
|
+
return typeof pattern === "string" ? JSON.stringify(pattern) : String(pattern);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/collector/operations.ts
|
|
220
|
+
var GRAPHQL_NAME = /^[_A-Za-z][_0-9A-Za-z]{0,99}$/u;
|
|
221
|
+
var PROCEDURE_NAME = /^[A-Za-z0-9_.-]{1,100}$/u;
|
|
222
|
+
var NAMED_OPERATION = /\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/u;
|
|
223
|
+
var OPERATION_NAME_FIELD = /"operationName"\s*:\s*"([^"\\]*)"/u;
|
|
224
|
+
var ANONYMOUS_OPERATION = "anonymous";
|
|
225
|
+
var PERSISTED_OPERATION = "persisted";
|
|
226
|
+
function isRecord(value) {
|
|
227
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
228
|
+
}
|
|
229
|
+
function stripGraphqlNoise(query) {
|
|
230
|
+
let out = "";
|
|
231
|
+
let i = 0;
|
|
232
|
+
while (i < query.length) {
|
|
233
|
+
const c = query[i];
|
|
234
|
+
if (c === "#") {
|
|
235
|
+
while (i < query.length && query[i] !== "\n" && query[i] !== "\r") i++;
|
|
236
|
+
out += " ";
|
|
237
|
+
} else if (query.startsWith('"""', i)) {
|
|
238
|
+
i += 3;
|
|
239
|
+
while (i < query.length && !query.startsWith('"""', i)) {
|
|
240
|
+
i += query.startsWith('\\"""', i) ? 4 : 1;
|
|
241
|
+
}
|
|
242
|
+
i += 3;
|
|
243
|
+
out += " ";
|
|
244
|
+
} else if (c === '"') {
|
|
245
|
+
i++;
|
|
246
|
+
while (i < query.length && query[i] !== '"' && query[i] !== "\n") {
|
|
247
|
+
i += query[i] === "\\" ? 2 : 1;
|
|
248
|
+
}
|
|
249
|
+
i++;
|
|
250
|
+
out += " ";
|
|
251
|
+
} else {
|
|
252
|
+
out += c;
|
|
253
|
+
i++;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
function firstNamedOperation(query) {
|
|
259
|
+
const found = NAMED_OPERATION.exec(stripGraphqlNoise(query));
|
|
260
|
+
if (found === null) return ANONYMOUS_OPERATION;
|
|
261
|
+
const name = found[1] ?? "";
|
|
262
|
+
return GRAPHQL_NAME.test(name) ? name : null;
|
|
263
|
+
}
|
|
264
|
+
function operationName(operation) {
|
|
265
|
+
if (!isRecord(operation)) return null;
|
|
266
|
+
const given = operation.operationName;
|
|
267
|
+
if (typeof given === "string" && GRAPHQL_NAME.test(given)) return given;
|
|
268
|
+
const rejected = typeof given === "string" && given !== "";
|
|
269
|
+
if (typeof operation.query === "string") return firstNamedOperation(operation.query);
|
|
270
|
+
const extensions = operation.extensions;
|
|
271
|
+
if (isRecord(extensions) && isRecord(extensions.persistedQuery)) {
|
|
272
|
+
return rejected ? null : PERSISTED_OPERATION;
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
function graphqlNamesFromValue(value) {
|
|
277
|
+
if (Array.isArray(value)) {
|
|
278
|
+
if (value.length === 0) return null;
|
|
279
|
+
const names = [];
|
|
280
|
+
for (const item of value) {
|
|
281
|
+
const name2 = operationName(item);
|
|
282
|
+
if (name2 === null) return null;
|
|
283
|
+
names.push(name2);
|
|
284
|
+
}
|
|
285
|
+
return names;
|
|
286
|
+
}
|
|
287
|
+
const name = operationName(value);
|
|
288
|
+
return name === null ? null : [name];
|
|
289
|
+
}
|
|
290
|
+
function parseJson(text) {
|
|
291
|
+
try {
|
|
292
|
+
return { ok: true, value: JSON.parse(text) };
|
|
293
|
+
} catch {
|
|
294
|
+
return { ok: false };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function multipartOperations(text) {
|
|
298
|
+
const header = /content-disposition:[^\r\n]*\bname="operations"[^\r\n]*\r?\n/iu.exec(text);
|
|
299
|
+
if (header === null) return null;
|
|
300
|
+
let start = header.index + header[0].length;
|
|
301
|
+
const blank = /\r?\n\r?\n/u.exec(text.slice(header.index));
|
|
302
|
+
if (blank === null) return null;
|
|
303
|
+
start = Math.max(start, header.index + blank.index + blank[0].length);
|
|
304
|
+
const end = text.indexOf("\n--", start);
|
|
305
|
+
if (end < 0) return null;
|
|
306
|
+
return text.slice(start, text[end - 1] === "\r" ? end - 1 : end);
|
|
307
|
+
}
|
|
308
|
+
function graphqlNamesFromText(text) {
|
|
309
|
+
const truncated = text.length > OPERATION_BODY_LIMIT;
|
|
310
|
+
const head = truncated ? text.slice(0, OPERATION_BODY_LIMIT) : text;
|
|
311
|
+
if (!truncated) {
|
|
312
|
+
const parsed = parseJson(head);
|
|
313
|
+
if (parsed.ok) return graphqlNamesFromValue(parsed.value);
|
|
314
|
+
}
|
|
315
|
+
const part = multipartOperations(head);
|
|
316
|
+
if (part !== null) {
|
|
317
|
+
const parsed = parseJson(part);
|
|
318
|
+
return parsed.ok ? graphqlNamesFromValue(parsed.value) : null;
|
|
319
|
+
}
|
|
320
|
+
if (truncated && head.trimStart().startsWith("{")) {
|
|
321
|
+
const name = OPERATION_NAME_FIELD.exec(head)?.[1];
|
|
322
|
+
return name !== void 0 && GRAPHQL_NAME.test(name) ? [name] : null;
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
function graphqlNamesFromParams(params) {
|
|
327
|
+
const query = params.get("query");
|
|
328
|
+
const name = params.get("operationName");
|
|
329
|
+
const extensionsText = params.get("extensions");
|
|
330
|
+
if (query === null && name === null && extensionsText === null) return null;
|
|
331
|
+
let extensions;
|
|
332
|
+
if (extensionsText !== null) {
|
|
333
|
+
const parsed = parseJson(extensionsText);
|
|
334
|
+
extensions = parsed.ok ? parsed.value : void 0;
|
|
335
|
+
}
|
|
336
|
+
return graphqlNamesFromValue({
|
|
337
|
+
...query === null ? {} : { query },
|
|
338
|
+
...name === null ? {} : { operationName: name },
|
|
339
|
+
...extensions === void 0 ? {} : { extensions }
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function graphqlNamesFromBody(body) {
|
|
343
|
+
if (body === null) return null;
|
|
344
|
+
if ("text" in body) return graphqlNamesFromText(body.text);
|
|
345
|
+
if ("value" in body) {
|
|
346
|
+
return typeof body.value === "string" ? graphqlNamesFromText(body.value) : graphqlNamesFromValue(body.value);
|
|
347
|
+
}
|
|
348
|
+
const operations = body.multipartOperations;
|
|
349
|
+
if (typeof operations !== "string") return null;
|
|
350
|
+
const parsed = parseJson(operations.slice(0, OPERATION_BODY_LIMIT));
|
|
351
|
+
return parsed.ok ? graphqlNamesFromValue(parsed.value) : null;
|
|
352
|
+
}
|
|
353
|
+
function trpcNamesFromPath(path, end) {
|
|
354
|
+
let rest = path.slice(end);
|
|
355
|
+
if (rest.startsWith("/")) rest = rest.slice(1);
|
|
356
|
+
const segment = rest.split("/", 1)[0] ?? "";
|
|
357
|
+
let decoded;
|
|
358
|
+
try {
|
|
359
|
+
decoded = decodeURIComponent(segment);
|
|
360
|
+
} catch {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
const names = decoded.split(",");
|
|
364
|
+
return names.every((name) => PROCEDURE_NAME.test(name)) ? names : null;
|
|
365
|
+
}
|
|
366
|
+
function readOperation(entries, request) {
|
|
367
|
+
if (entries.length === 0) return { matched: false };
|
|
368
|
+
let url;
|
|
369
|
+
try {
|
|
370
|
+
url = new URL(request.url);
|
|
371
|
+
} catch {
|
|
372
|
+
return { matched: false };
|
|
373
|
+
}
|
|
374
|
+
const found = chunkVYODYUEL_cjs.matchOperationEntry(entries, url.pathname);
|
|
375
|
+
if (found === null) return { matched: false };
|
|
376
|
+
const { entry } = found;
|
|
377
|
+
let names = null;
|
|
378
|
+
if (entry.type === "trpc") names = trpcNamesFromPath(url.pathname, found.end);
|
|
379
|
+
else if (request.method === "GET") names = graphqlNamesFromParams(url.searchParams);
|
|
380
|
+
else if (request.method === "POST") names = graphqlNamesFromBody(request.body());
|
|
381
|
+
return { matched: true, entry, names: isNonEmpty(names) ? names : null };
|
|
382
|
+
}
|
|
383
|
+
function isNonEmpty(names) {
|
|
384
|
+
return names !== null && names.length > 0;
|
|
385
|
+
}
|
|
183
386
|
|
|
184
387
|
// src/collector/filters.ts
|
|
185
388
|
function isKnownThirdPartyHost(host, hosts = KNOWN_THIRD_PARTY_HOSTS) {
|
|
@@ -266,7 +469,7 @@ var NO_TIMING = {
|
|
|
266
469
|
};
|
|
267
470
|
var BODYLESS = /* @__PURE__ */ new Set([204, 205, 304]);
|
|
268
471
|
var ABORTED_AFTER_RESPONSE = new Set(
|
|
269
|
-
|
|
472
|
+
chunkVXGTC6DB_cjs.ABORT_FAILURE_TEXTS.filter((text) => text !== chunkVXGTC6DB_cjs.CONTEXT_CLOSED_FAILURE_TEXT)
|
|
270
473
|
);
|
|
271
474
|
var RequestTracker = class {
|
|
272
475
|
context;
|
|
@@ -350,9 +553,36 @@ var RequestTracker = class {
|
|
|
350
553
|
startedAtWall: this.#opts.wallNow(),
|
|
351
554
|
page: pageOf(request),
|
|
352
555
|
response: null,
|
|
353
|
-
settling: false
|
|
556
|
+
settling: false,
|
|
557
|
+
operation: this.#operationOf(request)
|
|
354
558
|
});
|
|
355
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Operation names of a request (05-REQ-40, 18-REQ-07): the body is read, synchronously, only
|
|
562
|
+
* for a POST request matching a graphql entry, and dropped right after the names are taken.
|
|
563
|
+
*/
|
|
564
|
+
#operationOf(request) {
|
|
565
|
+
const entries = this.#opts.operations ?? [];
|
|
566
|
+
if (entries.length === 0) return {};
|
|
567
|
+
const method = request.method().toUpperCase();
|
|
568
|
+
let result;
|
|
569
|
+
try {
|
|
570
|
+
result = readOperation(entries, {
|
|
571
|
+
method,
|
|
572
|
+
url: request.url(),
|
|
573
|
+
body: () => {
|
|
574
|
+
const text = request.postData();
|
|
575
|
+
return text === null ? null : { text };
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
} catch (error) {
|
|
579
|
+
this.#diag.add(operationUnknown(method, null, errorText(error)));
|
|
580
|
+
return { operation: null };
|
|
581
|
+
}
|
|
582
|
+
if (!result.matched) return { operation: null };
|
|
583
|
+
if (result.names === null) this.#diag.add(operationUnknown(method, result.entry.match));
|
|
584
|
+
return { operation: result.names };
|
|
585
|
+
}
|
|
356
586
|
#onResponse(response) {
|
|
357
587
|
const entry = this.#inflight.get(response.request());
|
|
358
588
|
if (entry !== void 0) entry.response = response;
|
|
@@ -384,6 +614,7 @@ var RequestTracker = class {
|
|
|
384
614
|
this.#settle(request);
|
|
385
615
|
this.#sink.finished({
|
|
386
616
|
...base(request),
|
|
617
|
+
...entry.operation,
|
|
387
618
|
status: response.status(),
|
|
388
619
|
...timing,
|
|
389
620
|
startTime: startTimeOf(timing.startTime, entry),
|
|
@@ -436,7 +667,7 @@ var RequestTracker = class {
|
|
|
436
667
|
}
|
|
437
668
|
#closedByClient(request, entry) {
|
|
438
669
|
this.#settle(request);
|
|
439
|
-
this.#sink.finished(failed(request, entry,
|
|
670
|
+
this.#sink.finished(failed(request, entry, chunkVXGTC6DB_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
|
|
440
671
|
}
|
|
441
672
|
/** A request still in flight after the wait (05-REQ-13 step 4, 05-REQ-31). */
|
|
442
673
|
#leftover(request, entry) {
|
|
@@ -445,6 +676,7 @@ var RequestTracker = class {
|
|
|
445
676
|
if (entry.response !== null) {
|
|
446
677
|
this.#sink.finished({
|
|
447
678
|
...base(request),
|
|
679
|
+
...entry.operation,
|
|
448
680
|
status: entry.response.status(),
|
|
449
681
|
startTime,
|
|
450
682
|
duration: null,
|
|
@@ -456,6 +688,7 @@ var RequestTracker = class {
|
|
|
456
688
|
}
|
|
457
689
|
this.#sink.pending({
|
|
458
690
|
...base(request),
|
|
691
|
+
...entry.operation,
|
|
459
692
|
status: "PENDING",
|
|
460
693
|
startTime,
|
|
461
694
|
duration: null,
|
|
@@ -499,6 +732,7 @@ function base(request) {
|
|
|
499
732
|
function failed(request, entry, failureText, timing) {
|
|
500
733
|
return {
|
|
501
734
|
...base(request),
|
|
735
|
+
...entry.operation,
|
|
502
736
|
status: "FAILED",
|
|
503
737
|
failureText,
|
|
504
738
|
startTime: startTimeOf(Math.round(timing.startTime), entry),
|
|
@@ -529,7 +763,7 @@ function pageOf(request) {
|
|
|
529
763
|
|
|
530
764
|
// src/collector/test-collector.ts
|
|
531
765
|
function currentRecorder() {
|
|
532
|
-
return
|
|
766
|
+
return chunkVXGTC6DB_cjs.activeCollector();
|
|
533
767
|
}
|
|
534
768
|
function firstLine(error) {
|
|
535
769
|
const line = errorText(error).split("\n", 1)[0]?.trim() ?? "";
|
|
@@ -613,7 +847,7 @@ var TestCollector = class {
|
|
|
613
847
|
* Records one APIRequestContext call (15-REQ-05): the returned promise settles like `result`
|
|
614
848
|
* (same value, same error); the sample is made when it settles or at the end-of-test wait.
|
|
615
849
|
*/
|
|
616
|
-
observeApiCall(call2, source, result) {
|
|
850
|
+
observeApiCall(call2, source, result, options) {
|
|
617
851
|
if (this.#draining !== void 0) return result;
|
|
618
852
|
const startedAt = this.#opts.now();
|
|
619
853
|
const entry = {
|
|
@@ -621,7 +855,8 @@ var TestCollector = class {
|
|
|
621
855
|
source,
|
|
622
856
|
startTime: Math.round(this.#opts.wallNow()),
|
|
623
857
|
settled: Promise.resolve(),
|
|
624
|
-
done: false
|
|
858
|
+
done: false,
|
|
859
|
+
operation: this.#apiOperation(call2, options)
|
|
625
860
|
};
|
|
626
861
|
const finish = (status, extra, responseUrl) => {
|
|
627
862
|
try {
|
|
@@ -668,6 +903,29 @@ var TestCollector = class {
|
|
|
668
903
|
this.#apiInFlight.add(entry);
|
|
669
904
|
return out;
|
|
670
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Operation names of an API call (15-REQ-20): options.data or options.multipart for a GraphQL
|
|
908
|
+
* POST, the URL and options.params for GET, the path for tRPC. Only the names are kept.
|
|
909
|
+
*/
|
|
910
|
+
#apiOperation(call2, options) {
|
|
911
|
+
const entries = this.#opts.operations ?? [];
|
|
912
|
+
if (entries.length === 0) return {};
|
|
913
|
+
if (call2.url !== null && !shouldTrackApiCall(call2.url, this.#opts.measure)) return {};
|
|
914
|
+
try {
|
|
915
|
+
const url = call2.url ?? call2.rawUrl;
|
|
916
|
+
const result = readOperation(entries, {
|
|
917
|
+
method: call2.method,
|
|
918
|
+
url: call2.method === "GET" ? urlWithParams(url, options) : url,
|
|
919
|
+
body: () => apiOperationBody(options)
|
|
920
|
+
});
|
|
921
|
+
if (!result.matched) return { operation: null };
|
|
922
|
+
if (result.names === null) this.#diag.add(operationUnknown(call2.method, result.entry.match));
|
|
923
|
+
return { operation: result.names };
|
|
924
|
+
} catch (error) {
|
|
925
|
+
this.#diag.add(operationUnknown(call2.method, null, errorText(error)));
|
|
926
|
+
return { operation: null };
|
|
927
|
+
}
|
|
928
|
+
}
|
|
671
929
|
/** The sample of a call, or null when the filters skip its URL (15-REQ-06). */
|
|
672
930
|
#apiSample(entry, status, responseUrl, extra) {
|
|
673
931
|
const url = entry.call.url ?? responseUrl ?? entry.call.rawUrl;
|
|
@@ -679,7 +937,8 @@ var TestCollector = class {
|
|
|
679
937
|
...status === "FAILED" ? { failureText: extra.failureText ?? "unknown" } : {},
|
|
680
938
|
startTime: entry.startTime,
|
|
681
939
|
duration: extra.duration ?? null,
|
|
682
|
-
source: entry.source
|
|
940
|
+
source: entry.source,
|
|
941
|
+
...entry.operation
|
|
683
942
|
};
|
|
684
943
|
}
|
|
685
944
|
/**
|
|
@@ -703,7 +962,12 @@ var TestCollector = class {
|
|
|
703
962
|
context,
|
|
704
963
|
new RequestTracker(
|
|
705
964
|
context,
|
|
706
|
-
{
|
|
965
|
+
{
|
|
966
|
+
measure: this.#opts.measure,
|
|
967
|
+
operations: this.#opts.operations ?? [],
|
|
968
|
+
now: this.#opts.now,
|
|
969
|
+
wallNow: this.#opts.wallNow
|
|
970
|
+
},
|
|
707
971
|
this.#diag,
|
|
708
972
|
this.#sink
|
|
709
973
|
)
|
|
@@ -806,7 +1070,7 @@ var TestCollector = class {
|
|
|
806
1070
|
this.#dropped = 0;
|
|
807
1071
|
}
|
|
808
1072
|
return {
|
|
809
|
-
schemaVersion:
|
|
1073
|
+
schemaVersion: 4,
|
|
810
1074
|
collector: {
|
|
811
1075
|
name: COLLECTOR_NAME,
|
|
812
1076
|
version: this.#opts.version,
|
|
@@ -822,10 +1086,10 @@ var TestCollector = class {
|
|
|
822
1086
|
try {
|
|
823
1087
|
await this.drain();
|
|
824
1088
|
const body = JSON.stringify(this.batch());
|
|
825
|
-
await testInfo.attach(
|
|
1089
|
+
await testInfo.attach(chunkVXGTC6DB_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
|
|
826
1090
|
} catch (error) {
|
|
827
1091
|
process.stderr.write(
|
|
828
|
-
`COLLECTOR_ATTACH_FAILED: ${
|
|
1092
|
+
`COLLECTOR_ATTACH_FAILED: ${chunkVXGTC6DB_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
|
|
829
1093
|
`
|
|
830
1094
|
);
|
|
831
1095
|
}
|
|
@@ -843,34 +1107,36 @@ function engineOf(context) {
|
|
|
843
1107
|
var now = () => performance.now();
|
|
844
1108
|
var wallNow = () => Date.now();
|
|
845
1109
|
function perfModeOn() {
|
|
846
|
-
const mode =
|
|
847
|
-
if (!mode.ok) throw new
|
|
1110
|
+
const mode = chunkVXGTC6DB_cjs.readModeState(process.env);
|
|
1111
|
+
if (!mode.ok) throw new chunkVXGTC6DB_cjs.ConfigError(mode.issues);
|
|
848
1112
|
return mode.value !== null;
|
|
849
1113
|
}
|
|
850
1114
|
var PASSIVE_API = createPerfApi(() => {
|
|
851
1115
|
});
|
|
852
1116
|
function openBuffer(browserName, baseURL, testInfo) {
|
|
853
|
-
const state =
|
|
1117
|
+
const state = chunkVXGTC6DB_cjs.getRegistered();
|
|
854
1118
|
if (state !== void 0 && (!state.config.measure.api || !state.measuredProjects.includes(testInfo.project.name))) {
|
|
855
1119
|
return { collector: null, api: PASSIVE_API };
|
|
856
1120
|
}
|
|
1121
|
+
const config = state?.config ?? chunkVYODYUEL_cjs.perfDefaults;
|
|
857
1122
|
const collector = new TestCollector({
|
|
858
|
-
measure:
|
|
859
|
-
|
|
1123
|
+
measure: config.measure,
|
|
1124
|
+
operations: config.keys.operations,
|
|
1125
|
+
version: chunkVXGTC6DB_cjs.version,
|
|
860
1126
|
browserName,
|
|
861
1127
|
testTimeout: () => testInfo.timeout,
|
|
862
1128
|
baseURL,
|
|
863
1129
|
now,
|
|
864
1130
|
wallNow
|
|
865
1131
|
});
|
|
866
|
-
for (const context of
|
|
1132
|
+
for (const context of chunkVXGTC6DB_cjs.trackedContexts()) collector.track(context);
|
|
867
1133
|
return { collector, api: collector.api };
|
|
868
1134
|
}
|
|
869
1135
|
function skipInCheck(testInfo) {
|
|
870
|
-
const state =
|
|
1136
|
+
const state = chunkVXGTC6DB_cjs.getRegistered();
|
|
871
1137
|
if (state === void 0 || state.mode.mode !== "check") return;
|
|
872
1138
|
if (!state.measuredProjects.includes(testInfo.project.name)) return;
|
|
873
|
-
const max = state.mode.maxTests ??
|
|
1139
|
+
const max = state.mode.maxTests ?? chunkVXGTC6DB_cjs.DEFAULT_MAX_TESTS;
|
|
874
1140
|
if (!checkRunsTest(state.mode.runId, max, testInfo.project.name, testInfo.file)) {
|
|
875
1141
|
testInfo.skip(true, "PW_PERF_MODE=check: only the first test of each file runs");
|
|
876
1142
|
}
|
|
@@ -886,10 +1152,10 @@ var perfFixtures = {
|
|
|
886
1152
|
skipInCheck(testInfo);
|
|
887
1153
|
const buffer = openBuffer(browserName ?? null, baseURL, testInfo);
|
|
888
1154
|
const { collector } = buffer;
|
|
889
|
-
if (collector !== null)
|
|
1155
|
+
if (collector !== null) chunkVXGTC6DB_cjs.setActiveCollector(collector);
|
|
890
1156
|
await use(buffer);
|
|
891
1157
|
if (collector === null) return;
|
|
892
|
-
if (
|
|
1158
|
+
if (chunkVXGTC6DB_cjs.activeCollector() === collector) chunkVXGTC6DB_cjs.setActiveCollector(void 0);
|
|
893
1159
|
collector.markTeardownStart();
|
|
894
1160
|
await collector.attach(testInfo);
|
|
895
1161
|
},
|
|
@@ -916,7 +1182,7 @@ var perfFixtures = {
|
|
|
916
1182
|
}
|
|
917
1183
|
};
|
|
918
1184
|
function withPerfFixtures(base2) {
|
|
919
|
-
const wrapped =
|
|
1185
|
+
const wrapped = chunkVXGTC6DB_cjs.wrappedTests();
|
|
920
1186
|
if (wrapped.has(base2)) return base2;
|
|
921
1187
|
const extend = base2.extend;
|
|
922
1188
|
const result = extend.call(base2, perfModeOn() ? perfFixtures : passiveFixtures);
|
|
@@ -925,22 +1191,22 @@ function withPerfFixtures(base2) {
|
|
|
925
1191
|
}
|
|
926
1192
|
function trackContext(context) {
|
|
927
1193
|
if (!perfModeOn()) return;
|
|
928
|
-
const contexts =
|
|
1194
|
+
const contexts = chunkVXGTC6DB_cjs.trackedContexts();
|
|
929
1195
|
if (!contexts.has(context)) {
|
|
930
1196
|
contexts.add(context);
|
|
931
1197
|
context.once("close", () => contexts.delete(context));
|
|
932
1198
|
}
|
|
933
|
-
|
|
1199
|
+
chunkVXGTC6DB_cjs.activeCollector()?.track(context);
|
|
934
1200
|
}
|
|
935
1201
|
function trackRequestContext(requestContext) {
|
|
936
1202
|
if (!perfModeOn()) return;
|
|
937
|
-
const state =
|
|
1203
|
+
const state = chunkVXGTC6DB_cjs.getRegistered();
|
|
938
1204
|
if (state !== void 0 && !state.config.measure.api) return;
|
|
939
1205
|
if (!isApiRequestContext(requestContext)) {
|
|
940
|
-
|
|
1206
|
+
chunkVXGTC6DB_cjs.activeCollector()?.requestContextNotTracked();
|
|
941
1207
|
return;
|
|
942
1208
|
}
|
|
943
|
-
wrapRequestContext(requestContext, "tracked", void 0,
|
|
1209
|
+
wrapRequestContext(requestContext, "tracked", void 0, chunkVXGTC6DB_cjs.activeCollector);
|
|
944
1210
|
}
|
|
945
1211
|
|
|
946
1212
|
exports.trackContext = trackContext;
|
|
@@ -28,6 +28,7 @@ var CONFIG_FILE_EXTENSIONS = [
|
|
|
28
28
|
".cjs",
|
|
29
29
|
".json"
|
|
30
30
|
];
|
|
31
|
+
var COLD_WARN_RATIO = 3;
|
|
31
32
|
|
|
32
33
|
// src/core/types/common.ts
|
|
33
34
|
var ConfigError = class extends Error {
|
|
@@ -59,6 +60,7 @@ var LIMIT_NAMES = [
|
|
|
59
60
|
"maxWilson",
|
|
60
61
|
"maxErrorRate"
|
|
61
62
|
];
|
|
63
|
+
var DIFF_LIMIT_NAMES = [...LIMIT_NAMES, "maxNonSuccessRate"];
|
|
62
64
|
var DIFF_CATEGORIES = [
|
|
63
65
|
"added",
|
|
64
66
|
"removed",
|
|
@@ -92,6 +94,8 @@ function limitLabel(limit, level) {
|
|
|
92
94
|
return "wilson";
|
|
93
95
|
case "maxErrorRate":
|
|
94
96
|
return "errors";
|
|
97
|
+
case "maxNonSuccessRate":
|
|
98
|
+
return "nonSuccess";
|
|
95
99
|
default:
|
|
96
100
|
return limit;
|
|
97
101
|
}
|
|
@@ -131,7 +135,12 @@ function diffCountsText(diff) {
|
|
|
131
135
|
let extra = "";
|
|
132
136
|
if (category === "unchanged") {
|
|
133
137
|
const kept = diff.keys.filter((k) => k.withinHysteresis === true).length;
|
|
134
|
-
|
|
138
|
+
const added = diff.keys.filter((k) => k.newFields === true).length;
|
|
139
|
+
const notes = [
|
|
140
|
+
...kept > 0 ? [`${kept} within hysteresis`] : [],
|
|
141
|
+
...added > 0 ? [`${added} +new fields`] : []
|
|
142
|
+
];
|
|
143
|
+
if (notes.length > 0) extra = ` (${notes.join(", ")})`;
|
|
135
144
|
} else if (category === "locked") {
|
|
136
145
|
const incomplete = diff.keys.filter((k) => k.incomplete === true).length;
|
|
137
146
|
if (incomplete > 0)
|
|
@@ -146,9 +155,7 @@ function diffValuesText(diff, side, level, separator) {
|
|
|
146
155
|
const shown = diff.category === "added" === (side === "after");
|
|
147
156
|
if (!shown) return "";
|
|
148
157
|
const limits = diff.limits;
|
|
149
|
-
return
|
|
150
|
-
(name) => `${limitLabel(name, level)} ${limitValueText(name, limits[name])}`
|
|
151
|
-
).join(separator);
|
|
158
|
+
return DIFF_LIMIT_NAMES.filter((name) => name !== "maxNonSuccessRate" || limits[name] !== null).map((name) => `${limitLabel(name, level)} ${limitValueText(name, limits[name])}`).join(separator);
|
|
152
159
|
}
|
|
153
160
|
return diff.changes.map((c) => `${limitLabel(c.limit, level)} ${limitValueText(c.limit, c[side])}`).join(separator);
|
|
154
161
|
}
|
|
@@ -374,6 +381,58 @@ function passCommand(input) {
|
|
|
374
381
|
}
|
|
375
382
|
return { file: input.execPath, args: input.argv.slice(1) };
|
|
376
383
|
}
|
|
384
|
+
function parseProcessTable(text) {
|
|
385
|
+
const rows = [];
|
|
386
|
+
for (const line of text.split(/\r?\n/u)) {
|
|
387
|
+
const match = /^\s*(\d+)\s+(\d+)\s+(.*)$/u.exec(line);
|
|
388
|
+
if (match === null) continue;
|
|
389
|
+
rows.push({ pid: Number(match[1]), ppid: Number(match[2]), args: match[3] ?? "" });
|
|
390
|
+
}
|
|
391
|
+
return rows;
|
|
392
|
+
}
|
|
393
|
+
var MANAGER = /^(npm|pnpm|yarn|bun)(-cli)?(\.[cm]?js)?$/iu;
|
|
394
|
+
var MAX_DEPTH = 16;
|
|
395
|
+
function runScriptName(args) {
|
|
396
|
+
const w = args.split(/\s+/u).filter((word) => word !== "");
|
|
397
|
+
let i = 0;
|
|
398
|
+
if (!MANAGER.test(baseName(w[0] ?? ""))) {
|
|
399
|
+
if (!/^node(\.exe)?$/iu.test(baseName(w[0] ?? ""))) return null;
|
|
400
|
+
i = 1;
|
|
401
|
+
if (!MANAGER.test(baseName(w[1] ?? ""))) return null;
|
|
402
|
+
}
|
|
403
|
+
i += 1;
|
|
404
|
+
while ((w[i] ?? "").startsWith("-")) i += 1;
|
|
405
|
+
if (w[i] !== "run" && w[i] !== "run-script") return null;
|
|
406
|
+
return w[i + 1] ?? null;
|
|
407
|
+
}
|
|
408
|
+
function ancestorScript(input) {
|
|
409
|
+
const byPid = new Map(input.rows.map((row) => [row.pid, row]));
|
|
410
|
+
let current = byPid.get(input.pid)?.ppid;
|
|
411
|
+
for (let depth = 0; depth < MAX_DEPTH && current !== void 0 && current > 0; depth += 1) {
|
|
412
|
+
const row = byPid.get(current);
|
|
413
|
+
if (row === void 0) return null;
|
|
414
|
+
const name = runScriptName(row.args);
|
|
415
|
+
if (name !== null && Object.hasOwn(input.scripts, name) && /playwright/u.test(input.scripts[name] ?? "")) {
|
|
416
|
+
return name;
|
|
417
|
+
}
|
|
418
|
+
if (row.ppid === row.pid) return null;
|
|
419
|
+
current = row.ppid;
|
|
420
|
+
}
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
function scriptEnv(input) {
|
|
424
|
+
const { env, scripts } = input;
|
|
425
|
+
const event = env["npm_lifecycle_event"];
|
|
426
|
+
const manager = env["npm_execpath"];
|
|
427
|
+
if (event === void 0 || event === "" || manager === void 0 || manager === "" || scripts === null || scripts === void 0 || Object.hasOwn(scripts, event) || input.pid === void 0 || input.processTable === void 0) {
|
|
428
|
+
return env;
|
|
429
|
+
}
|
|
430
|
+
const text = input.processTable();
|
|
431
|
+
if (text === null) return env;
|
|
432
|
+
const name = ancestorScript({ rows: parseProcessTable(text), pid: input.pid, scripts });
|
|
433
|
+
if (name === null) return env;
|
|
434
|
+
return { ...env, npm_lifecycle_event: name, npm_lifecycle_script: scripts[name] ?? "" };
|
|
435
|
+
}
|
|
377
436
|
|
|
378
437
|
// src/mode/index.ts
|
|
379
438
|
var MODE = "PW_PERF_MODE";
|
|
@@ -386,6 +445,7 @@ var THRESHOLDS_DIR = "PW_PERF_THRESHOLDS_DIR";
|
|
|
386
445
|
var MIN_SAMPLES = "PW_PERF_MIN_SAMPLES";
|
|
387
446
|
var PRUNE = "PW_PERF_PRUNE";
|
|
388
447
|
var MAX_TESTS = "PW_PERF_MAX_TESTS";
|
|
448
|
+
var MERGE_MODE = "merge";
|
|
389
449
|
function checkStateFileName(runId) {
|
|
390
450
|
return `playwright-performance-regression-${runId}.check.json`;
|
|
391
451
|
}
|
|
@@ -427,7 +487,16 @@ function readModeState(env) {
|
|
|
427
487
|
const mode = read(env, MODE);
|
|
428
488
|
if (mode === void 0) return { ok: true, value: null };
|
|
429
489
|
const issues = [];
|
|
430
|
-
if (mode
|
|
490
|
+
if (mode === MERGE_MODE) {
|
|
491
|
+
issues.push(
|
|
492
|
+
invalid(
|
|
493
|
+
MODE,
|
|
494
|
+
'"test", "thresholds" or "check"',
|
|
495
|
+
mode,
|
|
496
|
+
"merge runs without tests: PW_PERF_MODE=merge npx pw-perf"
|
|
497
|
+
)
|
|
498
|
+
);
|
|
499
|
+
} else if (mode !== "test" && mode !== "thresholds" && mode !== "check") {
|
|
431
500
|
issues.push(
|
|
432
501
|
invalid(
|
|
433
502
|
MODE,
|
|
@@ -613,15 +682,17 @@ function setActiveCollector(collector) {
|
|
|
613
682
|
}
|
|
614
683
|
|
|
615
684
|
// package.json
|
|
616
|
-
var version = "1.
|
|
685
|
+
var version = "1.1.0";
|
|
617
686
|
|
|
618
687
|
exports.ABORT_FAILURE_TEXTS = ABORT_FAILURE_TEXTS;
|
|
688
|
+
exports.COLD_WARN_RATIO = COLD_WARN_RATIO;
|
|
619
689
|
exports.CONFIG_FILE_BASENAME = CONFIG_FILE_BASENAME;
|
|
620
690
|
exports.CONFIG_FILE_EXTENSIONS = CONFIG_FILE_EXTENSIONS;
|
|
621
691
|
exports.CONTEXT_CLOSED_FAILURE_TEXT = CONTEXT_CLOSED_FAILURE_TEXT;
|
|
622
692
|
exports.ConfigError = ConfigError;
|
|
623
693
|
exports.DEFAULT_MAX_TESTS = DEFAULT_MAX_TESTS;
|
|
624
694
|
exports.DIFF_CATEGORIES = DIFF_CATEGORIES;
|
|
695
|
+
exports.DIFF_LIMIT_NAMES = DIFF_LIMIT_NAMES;
|
|
625
696
|
exports.KINDS = KINDS;
|
|
626
697
|
exports.LIMIT_NAMES = LIMIT_NAMES;
|
|
627
698
|
exports.LISTED_CATEGORIES = LISTED_CATEGORIES;
|
|
@@ -646,6 +717,7 @@ exports.notWrappedWarning = notWrappedWarning;
|
|
|
646
717
|
exports.passCommand = passCommand;
|
|
647
718
|
exports.readModeState = readModeState;
|
|
648
719
|
exports.runShape = runShape;
|
|
720
|
+
exports.scriptEnv = scriptEnv;
|
|
649
721
|
exports.setActiveCollector = setActiveCollector;
|
|
650
722
|
exports.setRegistered = setRegistered;
|
|
651
723
|
exports.skippedReasonText = skippedReasonText;
|