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