playwright-performance-regression 0.1.0-next.1 → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +181 -0
- package/README.md +70 -51
- package/dist/{chunk-GCA73FFP.cjs → chunk-2JO5HVPC.cjs} +351 -44
- package/dist/{chunk-WZVQK7CQ.cjs → chunk-44ASXVQN.cjs} +96 -198
- package/dist/{chunk-L5C63HEF.js → chunk-AQ2XKYNV.js} +347 -45
- package/dist/chunk-BAOTUUTV.cjs +611 -0
- package/dist/chunk-DX36GFOZ.js +558 -0
- package/dist/chunk-LTRHMBVY.js +5592 -0
- package/dist/{chunk-B64P2D5A.js → chunk-MUZFQKGQ.js} +82 -184
- package/dist/cli.js +2825 -1406
- package/dist/config.cjs +91 -44
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/config.js +84 -37
- package/dist/fixture.cjs +5 -5
- package/dist/fixture.d.cts +2 -2
- package/dist/fixture.d.ts +2 -2
- package/dist/fixture.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +110 -22
- package/dist/index.d.ts +110 -22
- package/dist/index.js +1 -1
- package/dist/perf-api-Rm1h1O_-.d.cts +12 -0
- package/dist/perf-api-Rm1h1O_-.d.ts +12 -0
- package/dist/reporter.cjs +5184 -1207
- package/dist/reporter.js +2029 -245
- package/dist/test.cjs +4 -4
- package/dist/test.js +3 -3
- package/package.json +3 -1
- package/schemas/common.schema.json +2 -2
- package/schemas/config.schema.json +57 -21
- package/schemas/outcome.schema.json +1 -1
- package/schemas/run-report.schema.json +534 -19
- package/schemas/samples.schema.json +4 -39
- package/schemas/thresholds.schema.json +1 -1
- package/dist/chunk-3CLCMD2Q.js +0 -3411
- package/dist/chunk-4SFI55HF.cjs +0 -319
- package/dist/chunk-HBGADXLP.js +0 -254
- package/dist/perf-api-V4PeHVE0.d.cts +0 -22
- package/dist/perf-api-V4PeHVE0.d.ts +0 -22
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
import { wrappedTests, trackedContexts, activeCollector, setActiveCollector, getRegistered } from './chunk-DYLCGMI2.js';
|
|
2
|
-
import { readModeState, ConfigError, version, SAMPLES_ATTACHMENT_NAME, CONTEXT_CLOSED_FAILURE_TEXT } from './chunk-
|
|
3
|
-
import { perfDefaults } from './chunk-
|
|
2
|
+
import { readModeState, ConfigError, DEFAULT_MAX_TESTS, version, SAMPLES_ATTACHMENT_NAME, checkStateFileName, CONTEXT_CLOSED_FAILURE_TEXT } from './chunk-DX36GFOZ.js';
|
|
3
|
+
import { perfDefaults } from './chunk-AQ2XKYNV.js';
|
|
4
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
5
|
+
import { tmpdir } from 'os';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
|
|
8
|
+
var memory = { files: [], ran: 0 };
|
|
9
|
+
function checkStatePath(runId) {
|
|
10
|
+
return join(tmpdir(), checkStateFileName(runId));
|
|
11
|
+
}
|
|
12
|
+
function load(path) {
|
|
13
|
+
if (path === null) return memory;
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
16
|
+
return { files: Array.isArray(parsed.files) ? parsed.files : [], ran: Number(parsed.ran ?? 0) };
|
|
17
|
+
} catch {
|
|
18
|
+
return { files: [], ran: 0 };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function save(path, state) {
|
|
22
|
+
if (path === null) memory = state;
|
|
23
|
+
else writeFileSync(path, JSON.stringify(state));
|
|
24
|
+
}
|
|
25
|
+
function checkRunsTest(runId, maxTests, project, file) {
|
|
26
|
+
const path = runId === void 0 ? null : checkStatePath(runId);
|
|
27
|
+
const state = load(path);
|
|
28
|
+
const id = `${project}\0${file}`;
|
|
29
|
+
if (state.ran >= maxTests || state.files.includes(id)) return false;
|
|
30
|
+
save(path, { files: [...state.files, id], ran: state.ran + 1 });
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/collector/perf-api.ts
|
|
35
|
+
function createPerfApi(track) {
|
|
36
|
+
return Object.freeze({ track });
|
|
37
|
+
}
|
|
4
38
|
|
|
5
39
|
// src/collector/constants.ts
|
|
6
40
|
var KNOWN_THIRD_PARTY_HOSTS = Object.freeze([
|
|
@@ -39,156 +73,6 @@ var PENDING_RESERVE_MS = 1e3;
|
|
|
39
73
|
var SAMPLE_LIMIT_PER_TEST = 2e4;
|
|
40
74
|
var COLLECTOR_NAME = "playwright-js";
|
|
41
75
|
|
|
42
|
-
// src/collector/timing.ts
|
|
43
|
-
function roundMs(x) {
|
|
44
|
-
return Math.round(x * 10) / 10 + 0;
|
|
45
|
-
}
|
|
46
|
-
function partialTiming(timing) {
|
|
47
|
-
const { requestStart, responseStart } = timing;
|
|
48
|
-
const ttfb = responseStart - requestStart;
|
|
49
|
-
return {
|
|
50
|
-
requestStart: requestStart >= 0 ? roundMs(requestStart) : null,
|
|
51
|
-
ttfb: requestStart >= 0 && responseStart >= 0 && ttfb >= 0 ? roundMs(ttfb) : null
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function computeTiming(timing, fallback) {
|
|
55
|
-
const browser = timing.responseEnd >= 0;
|
|
56
|
-
return {
|
|
57
|
-
startTime: Math.round(timing.startTime),
|
|
58
|
-
duration: roundMs(
|
|
59
|
-
browser ? timing.responseEnd : Math.max(0, fallback.finishedAtNode - fallback.startedAtNode)
|
|
60
|
-
),
|
|
61
|
-
...partialTiming(timing),
|
|
62
|
-
timeSource: browser ? "browser" : "node"
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function pendingBudgetMs(input) {
|
|
66
|
-
const { pendingTimeoutMs, testTimeoutMs, sinceTeardownStartMs } = input;
|
|
67
|
-
if (testTimeoutMs === 0) return Math.max(0, pendingTimeoutMs);
|
|
68
|
-
const left = testTimeoutMs - sinceTeardownStartMs - PENDING_RESERVE_MS;
|
|
69
|
-
return Math.max(0, Math.min(pendingTimeoutMs, left));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// src/collector/custom-timer.ts
|
|
73
|
-
var MAX_NAME_LENGTH = 200;
|
|
74
|
-
var NAME = /^[^\s\u0000-\u001F\u007F](?:[^\u0000-\u001F\u007F]*[^\s\u0000-\u001F\u007F])?$/u;
|
|
75
|
-
function validateMeasurementName(name) {
|
|
76
|
-
let problem;
|
|
77
|
-
if (typeof name !== "string") problem = `expected a string, got ${typeof name}`;
|
|
78
|
-
else if ([...name].length > MAX_NAME_LENGTH) {
|
|
79
|
-
problem = `the name has more than ${MAX_NAME_LENGTH} characters`;
|
|
80
|
-
} else if (!NAME.test(name)) {
|
|
81
|
-
problem = name.trim() === "" ? "the name is empty" : "the name starts or ends with whitespace or contains a control character";
|
|
82
|
-
}
|
|
83
|
-
if (problem !== void 0) {
|
|
84
|
-
throw new TypeError(
|
|
85
|
-
`CUSTOM_INVALID_NAME: invalid custom measurement name ${JSON.stringify(String(name))}: ${problem}. Use 1-${MAX_NAME_LENGTH} characters without control characters and without leading or trailing whitespace, e.g. "checkout:load-cart".`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
var CustomTimer = class {
|
|
90
|
-
#opts;
|
|
91
|
-
#diag;
|
|
92
|
-
#samples = [];
|
|
93
|
-
/** Open start() measurements by name (06-REQ-06). */
|
|
94
|
-
#started = /* @__PURE__ */ new Map();
|
|
95
|
-
/** measure() calls in progress, each with its own start (06-REQ-05). */
|
|
96
|
-
#measuring = /* @__PURE__ */ new Set();
|
|
97
|
-
#finished = false;
|
|
98
|
-
constructor(opts, diag) {
|
|
99
|
-
this.#opts = opts;
|
|
100
|
-
this.#diag = diag;
|
|
101
|
-
}
|
|
102
|
-
/** Measures `fn` (06-REQ-05): returns its result; on an exception records 'error' and rethrows. */
|
|
103
|
-
async measure(name, fn) {
|
|
104
|
-
validateMeasurementName(name);
|
|
105
|
-
const running = { name, startedAt: this.#opts.now() };
|
|
106
|
-
this.#measuring.add(running);
|
|
107
|
-
let result;
|
|
108
|
-
try {
|
|
109
|
-
result = await fn();
|
|
110
|
-
} catch (error) {
|
|
111
|
-
this.#close(running, "error");
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
this.#close(running, "ok");
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
start(name) {
|
|
118
|
-
validateMeasurementName(name);
|
|
119
|
-
const previous = this.#started.get(name);
|
|
120
|
-
if (previous !== void 0) {
|
|
121
|
-
this.#unfinished(previous);
|
|
122
|
-
this.#issue(
|
|
123
|
-
"CUSTOM_ALREADY_STARTED",
|
|
124
|
-
`custom: perf.start(${JSON.stringify(name)}) was called while this measurement was running; the earlier one is recorded as unfinished`,
|
|
125
|
-
"Call perf.end() before starting the same measurement again, or use perf.measure()."
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
this.#started.set(name, { name, startedAt: this.#opts.now() });
|
|
129
|
-
}
|
|
130
|
-
/** Ends a measurement; returns its duration in ms, or undefined without a start (06-REQ-07). */
|
|
131
|
-
end(name) {
|
|
132
|
-
validateMeasurementName(name);
|
|
133
|
-
const running = this.#started.get(name);
|
|
134
|
-
if (running === void 0) {
|
|
135
|
-
this.#issue(
|
|
136
|
-
"CUSTOM_END_WITHOUT_START",
|
|
137
|
-
`custom: perf.end(${JSON.stringify(name)}) was called without a matching perf.start()`,
|
|
138
|
-
"Call perf.start() with the same name in the same test before perf.end()."
|
|
139
|
-
);
|
|
140
|
-
return void 0;
|
|
141
|
-
}
|
|
142
|
-
this.#started.delete(name);
|
|
143
|
-
return this.#close(running, "ok");
|
|
144
|
-
}
|
|
145
|
-
/** Closes open measurements as 'unfinished' (06-REQ-09) and returns all samples. */
|
|
146
|
-
finish() {
|
|
147
|
-
if (!this.#finished) {
|
|
148
|
-
this.#finished = true;
|
|
149
|
-
const open = [...this.#started.values(), ...this.#measuring];
|
|
150
|
-
this.#started.clear();
|
|
151
|
-
this.#measuring.clear();
|
|
152
|
-
for (const running of open) this.#unfinished(running);
|
|
153
|
-
if (open.length > 0) {
|
|
154
|
-
this.#issue(
|
|
155
|
-
"CUSTOM_UNFINISHED",
|
|
156
|
-
`custom: measurements still running when the test ended: ${[...new Set(open.map((r) => JSON.stringify(r.name)))].join(", ")}`,
|
|
157
|
-
"End every perf.start() with perf.end(), or check whether the test timed out during the measurement.",
|
|
158
|
-
open.length
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return [...this.#samples];
|
|
163
|
-
}
|
|
164
|
-
#close(running, outcome) {
|
|
165
|
-
const duration = roundMs(Math.max(0, this.#opts.now() - running.startedAt));
|
|
166
|
-
this.#measuring.delete(running);
|
|
167
|
-
if (this.#opts.record && !this.#finished) {
|
|
168
|
-
this.#samples.push({
|
|
169
|
-
name: running.name,
|
|
170
|
-
outcome,
|
|
171
|
-
duration,
|
|
172
|
-
endTime: Math.round(this.#opts.wallNow())
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return duration;
|
|
176
|
-
}
|
|
177
|
-
#unfinished(running) {
|
|
178
|
-
if (!this.#opts.record) return;
|
|
179
|
-
this.#samples.push({
|
|
180
|
-
name: running.name,
|
|
181
|
-
outcome: "unfinished",
|
|
182
|
-
duration: null,
|
|
183
|
-
endTime: null
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
#issue(code, message, hint, count) {
|
|
187
|
-
if (!this.#opts.record) return;
|
|
188
|
-
this.#diag.add({ code, message, hint, ...count === void 0 ? {} : { count } });
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
76
|
// src/collector/diagnostics.ts
|
|
193
77
|
function createDiagnostics() {
|
|
194
78
|
const entries = /* @__PURE__ */ new Map();
|
|
@@ -212,20 +96,6 @@ function errorText(error) {
|
|
|
212
96
|
return String(error);
|
|
213
97
|
}
|
|
214
98
|
|
|
215
|
-
// src/collector/perf-api.ts
|
|
216
|
-
function createPerfApi(timer, track) {
|
|
217
|
-
const start = (name) => timer.start(name);
|
|
218
|
-
const end = (name) => timer.end(name);
|
|
219
|
-
return Object.freeze({
|
|
220
|
-
measure: (name, fn) => timer.measure(name, fn),
|
|
221
|
-
start,
|
|
222
|
-
end,
|
|
223
|
-
sampleStart: start,
|
|
224
|
-
sampleEnd: end,
|
|
225
|
-
track
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
99
|
// src/collector/filters.ts
|
|
230
100
|
function isKnownThirdPartyHost(host, hosts = KNOWN_THIRD_PARTY_HOSTS) {
|
|
231
101
|
const name = host.toLowerCase().replace(/\.$/u, "");
|
|
@@ -259,6 +129,36 @@ function shouldTrack(req, measure) {
|
|
|
259
129
|
return true;
|
|
260
130
|
}
|
|
261
131
|
|
|
132
|
+
// src/collector/timing.ts
|
|
133
|
+
function roundMs(x) {
|
|
134
|
+
return Math.round(x * 10) / 10 + 0;
|
|
135
|
+
}
|
|
136
|
+
function partialTiming(timing) {
|
|
137
|
+
const { requestStart, responseStart } = timing;
|
|
138
|
+
const ttfb = responseStart - requestStart;
|
|
139
|
+
return {
|
|
140
|
+
requestStart: requestStart >= 0 ? roundMs(requestStart) : null,
|
|
141
|
+
ttfb: requestStart >= 0 && responseStart >= 0 && ttfb >= 0 ? roundMs(ttfb) : null
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function computeTiming(timing, fallback) {
|
|
145
|
+
const browser = timing.responseEnd >= 0;
|
|
146
|
+
return {
|
|
147
|
+
startTime: Math.round(timing.startTime),
|
|
148
|
+
duration: roundMs(
|
|
149
|
+
browser ? timing.responseEnd : Math.max(0, fallback.finishedAtNode - fallback.startedAtNode)
|
|
150
|
+
),
|
|
151
|
+
...partialTiming(timing),
|
|
152
|
+
timeSource: browser ? "browser" : "node"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function pendingBudgetMs(input) {
|
|
156
|
+
const { pendingTimeoutMs, testTimeoutMs, sinceTeardownStartMs } = input;
|
|
157
|
+
if (testTimeoutMs === 0) return Math.max(0, pendingTimeoutMs);
|
|
158
|
+
const left = testTimeoutMs - sinceTeardownStartMs - PENDING_RESERVE_MS;
|
|
159
|
+
return Math.max(0, Math.min(pendingTimeoutMs, left));
|
|
160
|
+
}
|
|
161
|
+
|
|
262
162
|
// src/collector/request-tracker.ts
|
|
263
163
|
var NO_TIMING = {
|
|
264
164
|
startTime: -1,
|
|
@@ -523,7 +423,6 @@ var TestCollector = class {
|
|
|
523
423
|
api;
|
|
524
424
|
#opts;
|
|
525
425
|
#diag = createDiagnostics();
|
|
526
|
-
#timer;
|
|
527
426
|
#trackers = /* @__PURE__ */ new Map();
|
|
528
427
|
#requests = [];
|
|
529
428
|
#pending = [];
|
|
@@ -535,11 +434,7 @@ var TestCollector = class {
|
|
|
535
434
|
#draining;
|
|
536
435
|
constructor(opts) {
|
|
537
436
|
this.#opts = opts;
|
|
538
|
-
this
|
|
539
|
-
{ now: opts.now, wallNow: opts.wallNow, record: true },
|
|
540
|
-
this.#diag
|
|
541
|
-
);
|
|
542
|
-
this.api = createPerfApi(this.#timer, (context) => {
|
|
437
|
+
this.api = createPerfApi((context) => {
|
|
543
438
|
this.track(context);
|
|
544
439
|
});
|
|
545
440
|
const keep = (list, sample) => {
|
|
@@ -626,7 +521,6 @@ var TestCollector = class {
|
|
|
626
521
|
}
|
|
627
522
|
/** The sample batch of the test (05-REQ-15); call after drain(). */
|
|
628
523
|
batch() {
|
|
629
|
-
const custom = this.#timer.finish();
|
|
630
524
|
if (this.#dropped > 0) {
|
|
631
525
|
this.#diag.add({
|
|
632
526
|
code: "COLLECTOR_SAMPLE_LIMIT_REACHED",
|
|
@@ -637,14 +531,13 @@ var TestCollector = class {
|
|
|
637
531
|
this.#dropped = 0;
|
|
638
532
|
}
|
|
639
533
|
return {
|
|
640
|
-
schemaVersion:
|
|
534
|
+
schemaVersion: 2,
|
|
641
535
|
collector: {
|
|
642
536
|
name: COLLECTOR_NAME,
|
|
643
537
|
version: this.#opts.version,
|
|
644
538
|
browserName: this.#browserName ?? null
|
|
645
539
|
},
|
|
646
540
|
requests: [...this.#requests, ...this.#pending],
|
|
647
|
-
custom,
|
|
648
541
|
diagnostics: this.#diag.list()
|
|
649
542
|
};
|
|
650
543
|
}
|
|
@@ -678,17 +571,12 @@ function perfModeOn() {
|
|
|
678
571
|
if (!mode.ok) throw new ConfigError(mode.issues);
|
|
679
572
|
return mode.value !== null;
|
|
680
573
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
new CustomTimer({ now, wallNow, record: false }, createDiagnostics()),
|
|
684
|
-
() => {
|
|
685
|
-
}
|
|
686
|
-
);
|
|
687
|
-
}
|
|
574
|
+
var PASSIVE_API = createPerfApi(() => {
|
|
575
|
+
});
|
|
688
576
|
function openBuffer(browserName, testInfo) {
|
|
689
577
|
const state = getRegistered();
|
|
690
578
|
if (state !== void 0 && !state.measuredProjects.includes(testInfo.project.name)) {
|
|
691
|
-
return { collector: null, api:
|
|
579
|
+
return { collector: null, api: PASSIVE_API };
|
|
692
580
|
}
|
|
693
581
|
const collector = new TestCollector({
|
|
694
582
|
measure: (state?.config ?? perfDefaults).measure,
|
|
@@ -701,14 +589,24 @@ function openBuffer(browserName, testInfo) {
|
|
|
701
589
|
for (const context of trackedContexts()) collector.track(context);
|
|
702
590
|
return { collector, api: collector.api };
|
|
703
591
|
}
|
|
592
|
+
function skipInCheck(testInfo) {
|
|
593
|
+
const state = getRegistered();
|
|
594
|
+
if (state === void 0 || state.mode.mode !== "check") return;
|
|
595
|
+
if (!state.measuredProjects.includes(testInfo.project.name)) return;
|
|
596
|
+
const max = state.mode.maxTests ?? DEFAULT_MAX_TESTS;
|
|
597
|
+
if (!checkRunsTest(state.mode.runId, max, testInfo.project.name, testInfo.file)) {
|
|
598
|
+
testInfo.skip(true, "pw-perf check: only the first test of each file runs");
|
|
599
|
+
}
|
|
600
|
+
}
|
|
704
601
|
var passiveFixtures = {
|
|
705
602
|
perf: async ({}, use) => {
|
|
706
|
-
await use(
|
|
603
|
+
await use(PASSIVE_API);
|
|
707
604
|
}
|
|
708
605
|
};
|
|
709
606
|
var perfFixtures = {
|
|
710
607
|
_perfBuffer: [
|
|
711
608
|
async ({ browserName }, use, testInfo) => {
|
|
609
|
+
skipInCheck(testInfo);
|
|
712
610
|
const buffer = openBuffer(browserName ?? null, testInfo);
|
|
713
611
|
const { collector } = buffer;
|
|
714
612
|
if (collector !== null) setActiveCollector(collector);
|