playwright-performance-regression 0.1.0-next.3 → 0.1.0-next.4
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 +250 -0
- package/README.md +45 -32
- package/dist/{chunk-AQ2XKYNV.js → chunk-CISGJCFW.js} +35 -7
- package/dist/chunk-CXE5IWZY.js +1648 -0
- package/dist/{chunk-MUZFQKGQ.js → chunk-E2IX265O.js} +321 -30
- package/dist/{chunk-BAOTUUTV.cjs → chunk-IUI4AFE5.cjs} +75 -28
- package/dist/{chunk-44ASXVQN.cjs → chunk-KELMALEG.cjs} +337 -45
- package/dist/{chunk-2JO5HVPC.cjs → chunk-LUA4WRIQ.cjs} +35 -7
- package/dist/{chunk-DX36GFOZ.js → chunk-RL27E3AB.js} +94 -57
- package/dist/{chunk-DYLCGMI2.js → chunk-S6UH6QPK.js} +6 -1
- package/dist/cli.js +1802 -2799
- package/dist/config.cjs +58 -120
- package/dist/config.d.cts +2 -3
- package/dist/config.d.ts +2 -3
- package/dist/config.js +48 -110
- package/dist/fixture.cjs +9 -5
- package/dist/fixture.d.cts +10 -4
- package/dist/fixture.d.ts +10 -4
- package/dist/fixture.js +4 -4
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +17 -9
- package/dist/index.d.ts +17 -9
- package/dist/index.js +1 -1
- package/dist/perf-api-2DH_keLh.d.cts +17 -0
- package/dist/perf-api-2DH_keLh.d.ts +17 -0
- package/dist/reporter.cjs +1131 -632
- package/dist/reporter.js +6153 -1725
- package/dist/test.cjs +4 -4
- package/dist/test.js +4 -4
- package/package.json +17 -1
- package/schemas/config.schema.json +22 -12
- package/schemas/outcome.schema.json +1 -1
- package/schemas/run-report.schema.json +16 -2
- package/schemas/samples.schema.json +48 -2
- package/dist/chunk-LTRHMBVY.js +0 -5592
- package/dist/perf-api-Rm1h1O_-.d.cts +0 -12
- package/dist/perf-api-Rm1h1O_-.d.ts +0 -12
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkIUI4AFE5_cjs = require('./chunk-IUI4AFE5.cjs');
|
|
4
|
+
var chunkLUA4WRIQ_cjs = require('./chunk-LUA4WRIQ.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(), chunkIUI4AFE5_cjs.checkStateFileName(runId));
|
|
12
12
|
}
|
|
13
13
|
function load(path) {
|
|
14
14
|
if (path === null) return memory;
|
|
@@ -32,9 +32,93 @@ function checkRunsTest(runId, maxTests, project, file) {
|
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// src/collector/api-requests.ts
|
|
36
|
+
var API_METHODS = ["fetch", "get", "post", "put", "patch", "delete", "head"];
|
|
37
|
+
var METHOD = /^[A-Z]+$/u;
|
|
38
|
+
var depth = 0;
|
|
39
|
+
function call(target, name) {
|
|
40
|
+
if (typeof target !== "object" || target === null) return void 0;
|
|
41
|
+
const fn = target[name];
|
|
42
|
+
if (typeof fn !== "function") return void 0;
|
|
43
|
+
const value = fn.call(target);
|
|
44
|
+
return typeof value === "string" ? value : void 0;
|
|
45
|
+
}
|
|
46
|
+
function resolveUrl(raw, baseURL) {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(raw).toString();
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
if (baseURL === void 0 || baseURL === "") return null;
|
|
52
|
+
try {
|
|
53
|
+
return new URL(raw, baseURL).toString();
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function describeCall(name, args, baseURL) {
|
|
59
|
+
const [target, options] = args;
|
|
60
|
+
const rawUrl = typeof target === "string" ? target : call(target, "url") ?? String(target);
|
|
61
|
+
let method = name;
|
|
62
|
+
if (name === "fetch") {
|
|
63
|
+
const fromOptions = typeof options === "object" && options !== null ? options.method : void 0;
|
|
64
|
+
method = (typeof fromOptions === "string" ? fromOptions : void 0) ?? call(target, "method") ?? "GET";
|
|
65
|
+
}
|
|
66
|
+
method = method.toUpperCase();
|
|
67
|
+
if (!METHOD.test(method)) return void 0;
|
|
68
|
+
return { method, rawUrl, url: resolveUrl(rawUrl, baseURL) };
|
|
69
|
+
}
|
|
70
|
+
function isApiRequestContext(value) {
|
|
71
|
+
if (typeof value !== "object" || value === null) return false;
|
|
72
|
+
const target = value;
|
|
73
|
+
return ["fetch", "get", "post", "dispose", "storageState"].every(
|
|
74
|
+
(name) => typeof target[name] === "function"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function isPromise(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
79
|
+
}
|
|
80
|
+
function wrapRequestContext(context, source, baseURL, recorder) {
|
|
81
|
+
const wrapped = chunkIUI4AFE5_cjs.wrappedRequestContexts();
|
|
82
|
+
if (wrapped.has(context)) return false;
|
|
83
|
+
wrapped.add(context);
|
|
84
|
+
const target = context;
|
|
85
|
+
for (const name of API_METHODS) {
|
|
86
|
+
const original = target[name];
|
|
87
|
+
if (typeof original !== "function") continue;
|
|
88
|
+
const fn = original;
|
|
89
|
+
const wrapper = function(...args) {
|
|
90
|
+
const active = depth === 0 ? recorder() : void 0;
|
|
91
|
+
if (active === void 0) return fn.apply(this, args);
|
|
92
|
+
let described;
|
|
93
|
+
try {
|
|
94
|
+
described = describeCall(name, args, baseURL);
|
|
95
|
+
} catch {
|
|
96
|
+
described = void 0;
|
|
97
|
+
}
|
|
98
|
+
depth += 1;
|
|
99
|
+
let result;
|
|
100
|
+
try {
|
|
101
|
+
result = fn.apply(this, args);
|
|
102
|
+
} finally {
|
|
103
|
+
depth -= 1;
|
|
104
|
+
}
|
|
105
|
+
if (described === void 0 || !isPromise(result)) return result;
|
|
106
|
+
return active.observeApiCall(described, source, result);
|
|
107
|
+
};
|
|
108
|
+
Object.defineProperty(target, name, {
|
|
109
|
+
value: wrapper,
|
|
110
|
+
configurable: true,
|
|
111
|
+
enumerable: false,
|
|
112
|
+
writable: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
35
118
|
// src/collector/perf-api.ts
|
|
36
|
-
function createPerfApi(track) {
|
|
37
|
-
|
|
119
|
+
function createPerfApi(track, trackRequestContext2 = () => {
|
|
120
|
+
}) {
|
|
121
|
+
return Object.freeze({ track, trackRequestContext: trackRequestContext2 });
|
|
38
122
|
}
|
|
39
123
|
|
|
40
124
|
// src/collector/constants.ts
|
|
@@ -122,13 +206,26 @@ function shouldTrack(req, measure) {
|
|
|
122
206
|
if (req.resourceType !== "document" && hasIgnoredExtension(url, measure.ignoreExtensions)) {
|
|
123
207
|
return false;
|
|
124
208
|
}
|
|
125
|
-
|
|
209
|
+
return passesUrlFilters(req.url, url, measure);
|
|
210
|
+
}
|
|
211
|
+
function passesUrlFilters(text, url, measure) {
|
|
212
|
+
if (measure.include.length > 0 && !measure.include.some((pattern) => matchesUrlPattern(text, pattern))) {
|
|
126
213
|
return false;
|
|
127
214
|
}
|
|
128
|
-
if (measure.exclude.some((pattern) => matchesUrlPattern(
|
|
215
|
+
if (measure.exclude.some((pattern) => matchesUrlPattern(text, pattern))) return false;
|
|
129
216
|
if (measure.excludeKnownThirdParty && isKnownThirdPartyHost(url.hostname)) return false;
|
|
130
217
|
return true;
|
|
131
218
|
}
|
|
219
|
+
function shouldTrackApiCall(text, measure) {
|
|
220
|
+
let url;
|
|
221
|
+
try {
|
|
222
|
+
url = new URL(text);
|
|
223
|
+
} catch {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
227
|
+
return passesUrlFilters(text, url, measure);
|
|
228
|
+
}
|
|
132
229
|
|
|
133
230
|
// src/collector/timing.ts
|
|
134
231
|
function roundMs(x) {
|
|
@@ -167,6 +264,10 @@ var NO_TIMING = {
|
|
|
167
264
|
responseStart: -1,
|
|
168
265
|
responseEnd: -1
|
|
169
266
|
};
|
|
267
|
+
var BODYLESS = /* @__PURE__ */ new Set([204, 205, 304]);
|
|
268
|
+
var ABORTED_AFTER_RESPONSE = new Set(
|
|
269
|
+
chunkIUI4AFE5_cjs.ABORT_FAILURE_TEXTS.filter((text) => text !== chunkIUI4AFE5_cjs.CONTEXT_CLOSED_FAILURE_TEXT)
|
|
270
|
+
);
|
|
170
271
|
var RequestTracker = class {
|
|
171
272
|
context;
|
|
172
273
|
#opts;
|
|
@@ -270,11 +371,13 @@ var RequestTracker = class {
|
|
|
270
371
|
(error) => this.#timingFailed(request, entry, error)
|
|
271
372
|
);
|
|
272
373
|
}
|
|
273
|
-
#complete(request, entry, response, finishedAtNode) {
|
|
374
|
+
#complete(request, entry, response, finishedAtNode, headersEnd = false) {
|
|
274
375
|
if (this.#inflight.get(request) !== entry) return;
|
|
275
376
|
try {
|
|
276
377
|
if (response === null) throw new Error("the request finished without a response");
|
|
277
|
-
const
|
|
378
|
+
const raw = request.timing();
|
|
379
|
+
const ended = headersEnd && raw.responseEnd < 0 ? { ...raw, responseEnd: raw.responseStart } : raw;
|
|
380
|
+
const timing = computeTiming(ended, {
|
|
278
381
|
startedAtNode: entry.startedAtNode,
|
|
279
382
|
finishedAtNode
|
|
280
383
|
});
|
|
@@ -303,6 +406,11 @@ var RequestTracker = class {
|
|
|
303
406
|
const entry = this.#inflight.get(request);
|
|
304
407
|
if (entry === void 0) return;
|
|
305
408
|
const text = request.failure()?.errorText ?? "";
|
|
409
|
+
if (entry.response !== null && !entry.settling && (BODYLESS.has(entry.response.status()) || ABORTED_AFTER_RESPONSE.has(text))) {
|
|
410
|
+
entry.settling = true;
|
|
411
|
+
this.#complete(request, entry, entry.response, this.#opts.now(), true);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
306
414
|
this.#settle(request);
|
|
307
415
|
this.#sink.finished(
|
|
308
416
|
failed(request, entry, text === "" ? "unknown" : text, safeTiming(request))
|
|
@@ -328,7 +436,7 @@ var RequestTracker = class {
|
|
|
328
436
|
}
|
|
329
437
|
#closedByClient(request, entry) {
|
|
330
438
|
this.#settle(request);
|
|
331
|
-
this.#sink.finished(failed(request, entry,
|
|
439
|
+
this.#sink.finished(failed(request, entry, chunkIUI4AFE5_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
|
|
332
440
|
}
|
|
333
441
|
/** A request still in flight after the wait (05-REQ-13 step 4, 05-REQ-31). */
|
|
334
442
|
#leftover(request, entry) {
|
|
@@ -420,6 +528,13 @@ function pageOf(request) {
|
|
|
420
528
|
}
|
|
421
529
|
|
|
422
530
|
// src/collector/test-collector.ts
|
|
531
|
+
function currentRecorder() {
|
|
532
|
+
return chunkIUI4AFE5_cjs.activeCollector();
|
|
533
|
+
}
|
|
534
|
+
function firstLine(error) {
|
|
535
|
+
const line = errorText(error).split("\n", 1)[0]?.trim() ?? "";
|
|
536
|
+
return line === "" ? "unknown" : line;
|
|
537
|
+
}
|
|
423
538
|
var TestCollector = class {
|
|
424
539
|
api;
|
|
425
540
|
#opts;
|
|
@@ -427,6 +542,9 @@ var TestCollector = class {
|
|
|
427
542
|
#trackers = /* @__PURE__ */ new Map();
|
|
428
543
|
#requests = [];
|
|
429
544
|
#pending = [];
|
|
545
|
+
#apiRequests = [];
|
|
546
|
+
#apiPending = [];
|
|
547
|
+
#apiInFlight = /* @__PURE__ */ new Set();
|
|
430
548
|
#sink;
|
|
431
549
|
#dropped = 0;
|
|
432
550
|
#browserName;
|
|
@@ -435,24 +553,151 @@ var TestCollector = class {
|
|
|
435
553
|
#draining;
|
|
436
554
|
constructor(opts) {
|
|
437
555
|
this.#opts = opts;
|
|
438
|
-
this.api = createPerfApi(
|
|
439
|
-
|
|
556
|
+
this.api = createPerfApi(
|
|
557
|
+
(context) => {
|
|
558
|
+
this.track(context);
|
|
559
|
+
},
|
|
560
|
+
(requestContext) => {
|
|
561
|
+
this.trackRequestContext(requestContext);
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
this.#sink = {
|
|
565
|
+
finished: (sample) => this.#keep(this.#requests, sample),
|
|
566
|
+
pending: (sample) => this.#keep(this.#pending, sample)
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/** The sample limit counts browser samples and API calls together (05-REQ-16, 15-REQ-09). */
|
|
570
|
+
#keep(list, sample) {
|
|
571
|
+
const count = this.#requests.length + this.#pending.length + this.#apiRequests.length + this.#apiPending.length;
|
|
572
|
+
if (count < SAMPLE_LIMIT_PER_TEST) list.push(sample);
|
|
573
|
+
else this.#dropped += 1;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Wraps an APIRequestContext of this test (15-REQ-03): the request fixture or context.request.
|
|
577
|
+
* Relative URLs resolve against the test's baseURL only for the request fixture and the context
|
|
578
|
+
* of the context fixture, which Playwright creates with that baseURL; any other context may have
|
|
579
|
+
* its own baseURL, so its calls take response.url() (15-REQ-05).
|
|
580
|
+
*/
|
|
581
|
+
wrapRequest(requestContext, source, testBaseURL = source === "request") {
|
|
582
|
+
try {
|
|
583
|
+
wrapRequestContext(
|
|
584
|
+
requestContext,
|
|
585
|
+
source,
|
|
586
|
+
testBaseURL ? this.#opts.baseURL : void 0,
|
|
587
|
+
currentRecorder
|
|
588
|
+
);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
this.#diag.add({
|
|
591
|
+
code: "COLLECTOR_LISTENER_ERROR",
|
|
592
|
+
message: `collector: wrapping an APIRequestContext failed, so its calls are not measured: ${errorText(error)}`,
|
|
593
|
+
hint: "Report this as a bug of the package; the test result is not affected."
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
/** perf.trackRequestContext() (15-REQ-03, 15-AC-07). */
|
|
598
|
+
trackRequestContext(requestContext) {
|
|
599
|
+
if (!isApiRequestContext(requestContext)) {
|
|
600
|
+
this.requestContextNotTracked();
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
this.wrapRequest(requestContext, "tracked");
|
|
604
|
+
}
|
|
605
|
+
requestContextNotTracked() {
|
|
606
|
+
this.#diag.add({
|
|
607
|
+
code: "COLLECTOR_REQUEST_CONTEXT_NOT_TRACKED",
|
|
608
|
+
message: "collector: trackRequestContext() got an object that is not an APIRequestContext, so it is not measured",
|
|
609
|
+
hint: "Pass the object returned by playwright.request.newContext()."
|
|
440
610
|
});
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Records one APIRequestContext call (15-REQ-05): the returned promise settles like `result`
|
|
614
|
+
* (same value, same error); the sample is made when it settles or at the end-of-test wait.
|
|
615
|
+
*/
|
|
616
|
+
observeApiCall(call2, source, result) {
|
|
617
|
+
if (this.#draining !== void 0) return result;
|
|
618
|
+
const startedAt = this.#opts.now();
|
|
619
|
+
const entry = {
|
|
620
|
+
call: call2,
|
|
621
|
+
source,
|
|
622
|
+
startTime: Math.round(this.#opts.wallNow()),
|
|
623
|
+
settled: Promise.resolve(),
|
|
624
|
+
done: false
|
|
444
625
|
};
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
626
|
+
const finish = (status, extra, responseUrl) => {
|
|
627
|
+
try {
|
|
628
|
+
if (entry.done) return;
|
|
629
|
+
entry.done = true;
|
|
630
|
+
this.#apiInFlight.delete(entry);
|
|
631
|
+
const sample = this.#apiSample(entry, status, responseUrl, extra);
|
|
632
|
+
if (sample !== null) this.#keep(this.#apiRequests, sample);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
this.#diag.add({
|
|
635
|
+
code: "COLLECTOR_LISTENER_ERROR",
|
|
636
|
+
message: `collector: recording an APIRequestContext call failed: ${errorText(error)}`,
|
|
637
|
+
hint: "Report this as a bug of the package; the test result is not affected."
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
const out = result.then(
|
|
642
|
+
(response) => {
|
|
643
|
+
const duration = roundMs(this.#opts.now() - startedAt);
|
|
644
|
+
let status;
|
|
645
|
+
let url;
|
|
646
|
+
try {
|
|
647
|
+
const r = response;
|
|
648
|
+
const s = typeof r.status === "function" ? r.status() : void 0;
|
|
649
|
+
status = typeof s === "number" && Number.isInteger(s) && s >= 100 && s <= 599 ? s : void 0;
|
|
650
|
+
const u = typeof r.url === "function" ? r.url() : void 0;
|
|
651
|
+
url = typeof u === "string" && u !== "" ? u : void 0;
|
|
652
|
+
} catch {
|
|
653
|
+
status = void 0;
|
|
654
|
+
}
|
|
655
|
+
if (status === void 0) finish("FAILED", { failureText: "unknown", duration: null }, url);
|
|
656
|
+
else finish(status, { duration }, url);
|
|
657
|
+
return response;
|
|
658
|
+
},
|
|
659
|
+
(error) => {
|
|
660
|
+
finish("FAILED", { failureText: firstLine(error), duration: null });
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
entry.settled = out.then(
|
|
665
|
+
() => void 0,
|
|
666
|
+
() => void 0
|
|
667
|
+
);
|
|
668
|
+
this.#apiInFlight.add(entry);
|
|
669
|
+
return out;
|
|
670
|
+
}
|
|
671
|
+
/** The sample of a call, or null when the filters skip its URL (15-REQ-06). */
|
|
672
|
+
#apiSample(entry, status, responseUrl, extra) {
|
|
673
|
+
const url = entry.call.url ?? responseUrl ?? entry.call.rawUrl;
|
|
674
|
+
if (url === "" || !shouldTrackApiCall(url, this.#opts.measure)) return null;
|
|
675
|
+
return {
|
|
676
|
+
method: entry.call.method,
|
|
677
|
+
url,
|
|
678
|
+
status,
|
|
679
|
+
...status === "FAILED" ? { failureText: extra.failureText ?? "unknown" } : {},
|
|
680
|
+
startTime: entry.startTime,
|
|
681
|
+
duration: extra.duration ?? null,
|
|
682
|
+
source: entry.source
|
|
448
683
|
};
|
|
449
684
|
}
|
|
450
685
|
/**
|
|
451
686
|
* Attaches a tracker to `context` unless it already has one in this test (05-REQ-04) or the
|
|
452
|
-
* test is draining. Returns true when a tracker was attached.
|
|
687
|
+
* test is draining. Returns true when a tracker was attached. `contextFixture`: the context of
|
|
688
|
+
* the context fixture, whose request calls resolve against the test's baseURL (15-REQ-05).
|
|
453
689
|
*/
|
|
454
|
-
track(context) {
|
|
690
|
+
track(context, contextFixture = false) {
|
|
455
691
|
if (this.#draining !== void 0 || this.#trackers.has(context)) return false;
|
|
692
|
+
let requestContext;
|
|
693
|
+
try {
|
|
694
|
+
requestContext = context.request;
|
|
695
|
+
} catch {
|
|
696
|
+
requestContext = void 0;
|
|
697
|
+
}
|
|
698
|
+
if (typeof requestContext === "object" && requestContext !== null) {
|
|
699
|
+
this.wrapRequest(requestContext, "context", contextFixture);
|
|
700
|
+
}
|
|
456
701
|
try {
|
|
457
702
|
this.#trackers.set(
|
|
458
703
|
context,
|
|
@@ -506,8 +751,9 @@ var TestCollector = class {
|
|
|
506
751
|
testTimeoutMs: this.#opts.testTimeout(),
|
|
507
752
|
sinceTeardownStartMs: this.#opts.now() - (this.#teardownStart ?? this.#opts.now())
|
|
508
753
|
});
|
|
509
|
-
await Promise.all(
|
|
510
|
-
|
|
754
|
+
await Promise.all([
|
|
755
|
+
this.#drainApiCalls(budget),
|
|
756
|
+
...[...this.#trackers.values()].map(async (tracker) => {
|
|
511
757
|
try {
|
|
512
758
|
await tracker.drain(budget);
|
|
513
759
|
} catch (error) {
|
|
@@ -518,7 +764,35 @@ var TestCollector = class {
|
|
|
518
764
|
});
|
|
519
765
|
}
|
|
520
766
|
})
|
|
521
|
-
);
|
|
767
|
+
]);
|
|
768
|
+
}
|
|
769
|
+
/** Waits for running API calls within the budget; the rest become PENDING (15-REQ-08). */
|
|
770
|
+
async #drainApiCalls(budget) {
|
|
771
|
+
if (this.#apiInFlight.size > 0) {
|
|
772
|
+
let timer;
|
|
773
|
+
const timeout = new Promise((resolve) => {
|
|
774
|
+
timer = setTimeout(resolve, Math.max(0, budget));
|
|
775
|
+
});
|
|
776
|
+
await Promise.race([
|
|
777
|
+
Promise.all([...this.#apiInFlight].map((entry) => entry.settled)),
|
|
778
|
+
timeout
|
|
779
|
+
]);
|
|
780
|
+
clearTimeout(timer);
|
|
781
|
+
}
|
|
782
|
+
for (const entry of [...this.#apiInFlight]) {
|
|
783
|
+
entry.done = true;
|
|
784
|
+
this.#apiInFlight.delete(entry);
|
|
785
|
+
try {
|
|
786
|
+
const sample = this.#apiSample(entry, "PENDING", void 0, { duration: null });
|
|
787
|
+
if (sample !== null) this.#keep(this.#apiPending, sample);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
this.#diag.add({
|
|
790
|
+
code: "COLLECTOR_LISTENER_ERROR",
|
|
791
|
+
message: `collector: recording an APIRequestContext call failed: ${errorText(error)}`,
|
|
792
|
+
hint: "Report this as a bug of the package; the test result is not affected."
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
522
796
|
}
|
|
523
797
|
/** The sample batch of the test (05-REQ-15); call after drain(). */
|
|
524
798
|
batch() {
|
|
@@ -532,13 +806,14 @@ var TestCollector = class {
|
|
|
532
806
|
this.#dropped = 0;
|
|
533
807
|
}
|
|
534
808
|
return {
|
|
535
|
-
schemaVersion:
|
|
809
|
+
schemaVersion: 3,
|
|
536
810
|
collector: {
|
|
537
811
|
name: COLLECTOR_NAME,
|
|
538
812
|
version: this.#opts.version,
|
|
539
813
|
browserName: this.#browserName ?? null
|
|
540
814
|
},
|
|
541
815
|
requests: [...this.#requests, ...this.#pending],
|
|
816
|
+
apiRequests: [...this.#apiRequests, ...this.#apiPending],
|
|
542
817
|
diagnostics: this.#diag.list()
|
|
543
818
|
};
|
|
544
819
|
}
|
|
@@ -547,10 +822,10 @@ var TestCollector = class {
|
|
|
547
822
|
try {
|
|
548
823
|
await this.drain();
|
|
549
824
|
const body = JSON.stringify(this.batch());
|
|
550
|
-
await testInfo.attach(
|
|
825
|
+
await testInfo.attach(chunkIUI4AFE5_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
|
|
551
826
|
} catch (error) {
|
|
552
827
|
process.stderr.write(
|
|
553
|
-
`COLLECTOR_ATTACH_FAILED: ${
|
|
828
|
+
`COLLECTOR_ATTACH_FAILED: ${chunkIUI4AFE5_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
|
|
554
829
|
`
|
|
555
830
|
);
|
|
556
831
|
}
|
|
@@ -568,35 +843,36 @@ function engineOf(context) {
|
|
|
568
843
|
var now = () => performance.now();
|
|
569
844
|
var wallNow = () => Date.now();
|
|
570
845
|
function perfModeOn() {
|
|
571
|
-
const mode =
|
|
572
|
-
if (!mode.ok) throw new
|
|
846
|
+
const mode = chunkIUI4AFE5_cjs.readModeState(process.env);
|
|
847
|
+
if (!mode.ok) throw new chunkIUI4AFE5_cjs.ConfigError(mode.issues);
|
|
573
848
|
return mode.value !== null;
|
|
574
849
|
}
|
|
575
850
|
var PASSIVE_API = createPerfApi(() => {
|
|
576
851
|
});
|
|
577
|
-
function openBuffer(browserName, testInfo) {
|
|
578
|
-
const state =
|
|
579
|
-
if (state !== void 0 && !state.measuredProjects.includes(testInfo.project.name)) {
|
|
852
|
+
function openBuffer(browserName, baseURL, testInfo) {
|
|
853
|
+
const state = chunkIUI4AFE5_cjs.getRegistered();
|
|
854
|
+
if (state !== void 0 && (!state.config.measure.api || !state.measuredProjects.includes(testInfo.project.name))) {
|
|
580
855
|
return { collector: null, api: PASSIVE_API };
|
|
581
856
|
}
|
|
582
857
|
const collector = new TestCollector({
|
|
583
|
-
measure: (state?.config ??
|
|
584
|
-
version:
|
|
858
|
+
measure: (state?.config ?? chunkLUA4WRIQ_cjs.perfDefaults).measure,
|
|
859
|
+
version: chunkIUI4AFE5_cjs.version,
|
|
585
860
|
browserName,
|
|
586
861
|
testTimeout: () => testInfo.timeout,
|
|
862
|
+
baseURL,
|
|
587
863
|
now,
|
|
588
864
|
wallNow
|
|
589
865
|
});
|
|
590
|
-
for (const context of
|
|
866
|
+
for (const context of chunkIUI4AFE5_cjs.trackedContexts()) collector.track(context);
|
|
591
867
|
return { collector, api: collector.api };
|
|
592
868
|
}
|
|
593
869
|
function skipInCheck(testInfo) {
|
|
594
|
-
const state =
|
|
870
|
+
const state = chunkIUI4AFE5_cjs.getRegistered();
|
|
595
871
|
if (state === void 0 || state.mode.mode !== "check") return;
|
|
596
872
|
if (!state.measuredProjects.includes(testInfo.project.name)) return;
|
|
597
|
-
const max = state.mode.maxTests ??
|
|
873
|
+
const max = state.mode.maxTests ?? chunkIUI4AFE5_cjs.DEFAULT_MAX_TESTS;
|
|
598
874
|
if (!checkRunsTest(state.mode.runId, max, testInfo.project.name, testInfo.file)) {
|
|
599
|
-
testInfo.skip(true, "
|
|
875
|
+
testInfo.skip(true, "PW_PERF_MODE=check: only the first test of each file runs");
|
|
600
876
|
}
|
|
601
877
|
}
|
|
602
878
|
var passiveFixtures = {
|
|
@@ -606,21 +882,21 @@ var passiveFixtures = {
|
|
|
606
882
|
};
|
|
607
883
|
var perfFixtures = {
|
|
608
884
|
_perfBuffer: [
|
|
609
|
-
async ({ browserName }, use, testInfo) => {
|
|
885
|
+
async ({ browserName, baseURL }, use, testInfo) => {
|
|
610
886
|
skipInCheck(testInfo);
|
|
611
|
-
const buffer = openBuffer(browserName ?? null, testInfo);
|
|
887
|
+
const buffer = openBuffer(browserName ?? null, baseURL, testInfo);
|
|
612
888
|
const { collector } = buffer;
|
|
613
|
-
if (collector !== null)
|
|
889
|
+
if (collector !== null) chunkIUI4AFE5_cjs.setActiveCollector(collector);
|
|
614
890
|
await use(buffer);
|
|
615
891
|
if (collector === null) return;
|
|
616
|
-
if (
|
|
892
|
+
if (chunkIUI4AFE5_cjs.activeCollector() === collector) chunkIUI4AFE5_cjs.setActiveCollector(void 0);
|
|
617
893
|
collector.markTeardownStart();
|
|
618
894
|
await collector.attach(testInfo);
|
|
619
895
|
},
|
|
620
896
|
{ auto: true, box: true }
|
|
621
897
|
],
|
|
622
898
|
context: async ({ context, _perfBuffer }, use) => {
|
|
623
|
-
_perfBuffer.collector?.track(context);
|
|
899
|
+
_perfBuffer.collector?.track(context, true);
|
|
624
900
|
await use(context);
|
|
625
901
|
await _perfBuffer.collector?.drain();
|
|
626
902
|
},
|
|
@@ -629,13 +905,18 @@ var perfFixtures = {
|
|
|
629
905
|
await use(page);
|
|
630
906
|
await _perfBuffer.collector?.drain();
|
|
631
907
|
},
|
|
908
|
+
// The same object with its request methods measured (15-REQ-03); untouched without a collector.
|
|
909
|
+
request: async ({ request, _perfBuffer }, use) => {
|
|
910
|
+
_perfBuffer.collector?.wrapRequest(request, "request");
|
|
911
|
+
await use(request);
|
|
912
|
+
},
|
|
632
913
|
perf: async ({ _perfBuffer }, use) => {
|
|
633
914
|
await use(_perfBuffer.api);
|
|
634
915
|
_perfBuffer.collector?.markTeardownStart();
|
|
635
916
|
}
|
|
636
917
|
};
|
|
637
918
|
function withPerfFixtures(base2) {
|
|
638
|
-
const wrapped =
|
|
919
|
+
const wrapped = chunkIUI4AFE5_cjs.wrappedTests();
|
|
639
920
|
if (wrapped.has(base2)) return base2;
|
|
640
921
|
const extend = base2.extend;
|
|
641
922
|
const result = extend.call(base2, perfModeOn() ? perfFixtures : passiveFixtures);
|
|
@@ -644,13 +925,24 @@ function withPerfFixtures(base2) {
|
|
|
644
925
|
}
|
|
645
926
|
function trackContext(context) {
|
|
646
927
|
if (!perfModeOn()) return;
|
|
647
|
-
const contexts =
|
|
928
|
+
const contexts = chunkIUI4AFE5_cjs.trackedContexts();
|
|
648
929
|
if (!contexts.has(context)) {
|
|
649
930
|
contexts.add(context);
|
|
650
931
|
context.once("close", () => contexts.delete(context));
|
|
651
932
|
}
|
|
652
|
-
|
|
933
|
+
chunkIUI4AFE5_cjs.activeCollector()?.track(context);
|
|
934
|
+
}
|
|
935
|
+
function trackRequestContext(requestContext) {
|
|
936
|
+
if (!perfModeOn()) return;
|
|
937
|
+
const state = chunkIUI4AFE5_cjs.getRegistered();
|
|
938
|
+
if (state !== void 0 && !state.config.measure.api) return;
|
|
939
|
+
if (!isApiRequestContext(requestContext)) {
|
|
940
|
+
chunkIUI4AFE5_cjs.activeCollector()?.requestContextNotTracked();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
wrapRequestContext(requestContext, "tracked", void 0, chunkIUI4AFE5_cjs.activeCollector);
|
|
653
944
|
}
|
|
654
945
|
|
|
655
946
|
exports.trackContext = trackContext;
|
|
947
|
+
exports.trackRequestContext = trackRequestContext;
|
|
656
948
|
exports.withPerfFixtures = withPerfFixtures;
|
|
@@ -275,11 +275,12 @@ var DEFAULT_CONFIG = {
|
|
|
275
275
|
run: {
|
|
276
276
|
env: null,
|
|
277
277
|
passes: { test: 5, thresholds: 10 },
|
|
278
|
-
projects: "auto",
|
|
279
278
|
grep: null,
|
|
280
|
-
keepReporters: []
|
|
279
|
+
keepReporters: [],
|
|
280
|
+
overrideSlowMo: false
|
|
281
281
|
},
|
|
282
282
|
measure: {
|
|
283
|
+
api: true,
|
|
283
284
|
resourceTypes: ["document", "xhr", "fetch"],
|
|
284
285
|
ignoreExtensions: [
|
|
285
286
|
".js",
|
|
@@ -305,12 +306,20 @@ var DEFAULT_CONFIG = {
|
|
|
305
306
|
exclude: ["/socket.io/"],
|
|
306
307
|
excludeKnownThirdParty: true,
|
|
307
308
|
successStatuses: ["2xx", "3xx"],
|
|
308
|
-
steps:
|
|
309
|
+
steps: true,
|
|
309
310
|
pendingTimeoutMs: 2e3
|
|
310
311
|
},
|
|
311
312
|
keys: {
|
|
312
313
|
origins: {},
|
|
313
|
-
idPatterns: {
|
|
314
|
+
idPatterns: {
|
|
315
|
+
number: true,
|
|
316
|
+
uuid: true,
|
|
317
|
+
hex: true,
|
|
318
|
+
token: true,
|
|
319
|
+
mixed: true,
|
|
320
|
+
prefixed: true,
|
|
321
|
+
email: true
|
|
322
|
+
},
|
|
314
323
|
extraIdPatterns: [],
|
|
315
324
|
query: "names",
|
|
316
325
|
keepQueryValues: [],
|
|
@@ -374,7 +383,7 @@ var DEFAULT_CONFIG = {
|
|
|
374
383
|
hysteresis: { relative: 0.1, ratio: 0.01 },
|
|
375
384
|
loosenWarnRelative: 0.5
|
|
376
385
|
},
|
|
377
|
-
report: { dir: "pw-perf
|
|
386
|
+
report: { dir: "reports/pw-perf", html: true, rawUrls: false },
|
|
378
387
|
advanced: { maxSamplesPerKey: 5e3, seed: 1 }
|
|
379
388
|
};
|
|
380
389
|
|
|
@@ -630,11 +639,12 @@ var packageConfig = obj({
|
|
|
630
639
|
test: int({ minimum: 1, maximum: 1e3 }),
|
|
631
640
|
thresholds: int({ minimum: 1, maximum: 1e3 })
|
|
632
641
|
}),
|
|
633
|
-
projects: oneOf(constant("auto"), arr(str(), { minItems: 1, uniqueItems: true })),
|
|
634
642
|
grep: nullable(str({ minLength: 1 })),
|
|
635
|
-
keepReporters: uniqueStrings(1)
|
|
643
|
+
keepReporters: uniqueStrings(1),
|
|
644
|
+
overrideSlowMo: bool
|
|
636
645
|
}),
|
|
637
646
|
measure: obj({
|
|
647
|
+
api: bool,
|
|
638
648
|
resourceTypes: arr(
|
|
639
649
|
enumOf([
|
|
640
650
|
"document",
|
|
@@ -706,6 +716,7 @@ var packageConfig = obj({
|
|
|
706
716
|
hex: bool,
|
|
707
717
|
token: bool,
|
|
708
718
|
mixed: bool,
|
|
719
|
+
prefixed: bool,
|
|
709
720
|
email: bool
|
|
710
721
|
}),
|
|
711
722
|
extraIdPatterns: arr(urlPattern),
|
|
@@ -1108,6 +1119,18 @@ function relationalIssues(config, isSet) {
|
|
|
1108
1119
|
)
|
|
1109
1120
|
);
|
|
1110
1121
|
}
|
|
1122
|
+
const steps = valueAt(config, ["measure", "steps"]);
|
|
1123
|
+
const stepsOff = steps === false || isRecord(steps) && steps["enabled"] === false;
|
|
1124
|
+
if (valueAt(config, ["measure", "api"]) === false && stepsOff) {
|
|
1125
|
+
errors.push(
|
|
1126
|
+
issue2(
|
|
1127
|
+
"CONFIG_INVALID_VALUE",
|
|
1128
|
+
["measure"],
|
|
1129
|
+
"measure.api and measure.steps are both off, so nothing would be measured",
|
|
1130
|
+
"Turn on at least one of them: measure.api (backend requests) or measure.steps (test.step durations)."
|
|
1131
|
+
)
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1111
1134
|
const env = valueAt(config, ["run", "env"]);
|
|
1112
1135
|
if (typeof env === "string" && RESERVED_ENV_LABELS.includes(env)) {
|
|
1113
1136
|
errors.push(reservedEnvIssue(["run", "env"], env));
|
|
@@ -1314,6 +1337,11 @@ function overrideIssues(overrides) {
|
|
|
1314
1337
|
}
|
|
1315
1338
|
function applyOverrides(config, overrides) {
|
|
1316
1339
|
if (overrides.env !== void 0) config.run.env = overrides.env;
|
|
1340
|
+
if (overrides.thresholdsDir !== void 0) config.thresholds.dir = overrides.thresholdsDir;
|
|
1341
|
+
if (overrides.minSamples !== void 0) {
|
|
1342
|
+
const median = config.checks.time.median;
|
|
1343
|
+
median.minSamples = Math.min(median.minSamples, overrides.minSamples);
|
|
1344
|
+
}
|
|
1317
1345
|
if (overrides.passes !== void 0) {
|
|
1318
1346
|
config.run.passes[overrides.mode === "thresholds" ? "thresholds" : "test"] = overrides.passes;
|
|
1319
1347
|
}
|