playwright-performance-regression 0.0.0-stage → 0.1.0-next.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 +268 -0
- package/LICENSE +21 -0
- package/README.md +214 -2
- package/dist/chunk-6AB42SPF.js +254 -0
- package/dist/chunk-DYLCGMI2.js +63 -0
- package/dist/chunk-GCA73FFP.cjs +1139 -0
- package/dist/chunk-HES6BVZT.js +1097 -0
- package/dist/chunk-JEHUFIY3.js +3390 -0
- package/dist/chunk-LV3O2BAT.cjs +319 -0
- package/dist/chunk-R2NPYGB7.cjs +758 -0
- package/dist/chunk-UTTU4FUC.js +756 -0
- package/dist/cli.js +2909 -0
- package/dist/config.cjs +256 -0
- package/dist/config.d.cts +15 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +252 -0
- package/dist/fixture.cjs +16 -0
- package/dist/fixture.d.cts +22 -0
- package/dist/fixture.d.ts +22 -0
- package/dist/fixture.js +4 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +637 -0
- package/dist/index.d.ts +637 -0
- package/dist/index.js +1 -0
- package/dist/perf-api-V4PeHVE0.d.cts +22 -0
- package/dist/perf-api-V4PeHVE0.d.ts +22 -0
- package/dist/reporter.cjs +4769 -0
- package/dist/reporter.d.cts +18 -0
- package/dist/reporter.d.ts +18 -0
- package/dist/reporter.js +1409 -0
- package/dist/test.cjs +14 -0
- package/dist/test.d.cts +7 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +10 -0
- package/package.json +146 -4
- package/schemas/common.schema.json +81 -0
- package/schemas/config.schema.json +875 -0
- package/schemas/outcome.schema.json +44 -0
- package/schemas/run-report.schema.json +505 -0
- package/schemas/samples.schema.json +169 -0
- package/schemas/thresholds.schema.json +138 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// src/core/types/constants.ts
|
|
2
|
+
var CONTEXT_CLOSED_FAILURE_TEXT = "pw-perf: context closed";
|
|
3
|
+
var PACKAGE_NAME = "playwright-performance-regression";
|
|
4
|
+
var SAMPLES_ATTACHMENT_NAME = `${PACKAGE_NAME}-samples`;
|
|
5
|
+
var CLI_COMMAND = "npx pw-perf";
|
|
6
|
+
var REPOSITORY_URL = "https://github.com/Meser6/playwright-performance-regression";
|
|
7
|
+
var DOCS_CONFIG_URL = `${REPOSITORY_URL}/blob/main/docs/configuration.md`;
|
|
8
|
+
var CONFIG_FILE_BASENAME = "pw-perf.config";
|
|
9
|
+
var CONFIG_FILE_EXTENSIONS = [
|
|
10
|
+
".ts",
|
|
11
|
+
".mts",
|
|
12
|
+
".js",
|
|
13
|
+
".mjs",
|
|
14
|
+
".cjs",
|
|
15
|
+
".json"
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
// src/core/types/common.ts
|
|
19
|
+
var ConfigError = class extends Error {
|
|
20
|
+
issues;
|
|
21
|
+
constructor(issues) {
|
|
22
|
+
const count = `${issues.length} ${issues.length === 1 ? "problem" : "problems"}`;
|
|
23
|
+
super(
|
|
24
|
+
[
|
|
25
|
+
`${PACKAGE_NAME}: invalid configuration (${count})`,
|
|
26
|
+
...issues.flatMap((issue) => [
|
|
27
|
+
` - ${issue.message}`,
|
|
28
|
+
...issue.hint === void 0 ? [] : [` ${issue.hint}`]
|
|
29
|
+
]),
|
|
30
|
+
`See ${DOCS_CONFIG_URL} for all options.`
|
|
31
|
+
].join("\n")
|
|
32
|
+
);
|
|
33
|
+
this.name = "ConfigError";
|
|
34
|
+
this.issues = issues;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/core/types/thresholds.ts
|
|
39
|
+
var LIMIT_NAMES = [
|
|
40
|
+
"t",
|
|
41
|
+
"median",
|
|
42
|
+
"percentile",
|
|
43
|
+
"p99",
|
|
44
|
+
"minApdex",
|
|
45
|
+
"maxWilson",
|
|
46
|
+
"maxErrorRate"
|
|
47
|
+
];
|
|
48
|
+
var DIFF_CATEGORIES = [
|
|
49
|
+
"added",
|
|
50
|
+
"removed",
|
|
51
|
+
"loosened",
|
|
52
|
+
"tightened",
|
|
53
|
+
"mixed",
|
|
54
|
+
"unchanged",
|
|
55
|
+
"locked",
|
|
56
|
+
"unseen",
|
|
57
|
+
"skipped"
|
|
58
|
+
];
|
|
59
|
+
function limitLabel(limit, level) {
|
|
60
|
+
switch (limit) {
|
|
61
|
+
case "percentile":
|
|
62
|
+
return level;
|
|
63
|
+
case "minApdex":
|
|
64
|
+
return "apdex";
|
|
65
|
+
case "maxWilson":
|
|
66
|
+
return "wilson";
|
|
67
|
+
case "maxErrorRate":
|
|
68
|
+
return "errors";
|
|
69
|
+
default:
|
|
70
|
+
return limit;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function limitValueText(limit, value) {
|
|
74
|
+
if (value === null) return "null";
|
|
75
|
+
return limit === "t" || limit === "median" || limit === "percentile" || limit === "p99" ? String(value) : value.toFixed(3);
|
|
76
|
+
}
|
|
77
|
+
var MARKERS = {
|
|
78
|
+
added: "+",
|
|
79
|
+
removed: "-",
|
|
80
|
+
loosened: "\u2191",
|
|
81
|
+
tightened: "\u2193",
|
|
82
|
+
mixed: "\xB1",
|
|
83
|
+
unchanged: "=",
|
|
84
|
+
locked: "#",
|
|
85
|
+
unseen: "?",
|
|
86
|
+
skipped: "."
|
|
87
|
+
};
|
|
88
|
+
function diffMarker(diff) {
|
|
89
|
+
const large = diff.changes.some((c) => c.large === true);
|
|
90
|
+
return `${MARKERS[diff.category]}${large ? "!" : ""}`;
|
|
91
|
+
}
|
|
92
|
+
var LISTED_CATEGORIES = /* @__PURE__ */ new Set([
|
|
93
|
+
"added",
|
|
94
|
+
"removed",
|
|
95
|
+
"loosened",
|
|
96
|
+
"tightened",
|
|
97
|
+
"mixed"
|
|
98
|
+
]);
|
|
99
|
+
function diffCountsText(diff) {
|
|
100
|
+
const parts = [];
|
|
101
|
+
for (const category of DIFF_CATEGORIES) {
|
|
102
|
+
const n = diff.counts[category];
|
|
103
|
+
if (n === 0) continue;
|
|
104
|
+
let extra = "";
|
|
105
|
+
if (category === "unchanged") {
|
|
106
|
+
const kept = diff.keys.filter((k) => k.withinHysteresis === true).length;
|
|
107
|
+
if (kept > 0) extra = ` (${kept} within hysteresis)`;
|
|
108
|
+
} else if (category === "locked") {
|
|
109
|
+
const incomplete = diff.keys.filter((k) => k.incomplete === true).length;
|
|
110
|
+
if (incomplete > 0)
|
|
111
|
+
extra = ` (${incomplete} incomplete ${incomplete === 1 ? "entry" : "entries"})`;
|
|
112
|
+
}
|
|
113
|
+
parts.push(`${n} ${category}${extra}`);
|
|
114
|
+
}
|
|
115
|
+
return parts.length === 0 ? "no entries" : parts.join(" \xB7 ");
|
|
116
|
+
}
|
|
117
|
+
function diffValuesText(diff, side, level, separator) {
|
|
118
|
+
if (diff.limits !== void 0) {
|
|
119
|
+
const shown = diff.category === "added" === (side === "after");
|
|
120
|
+
if (!shown) return "";
|
|
121
|
+
const limits = diff.limits;
|
|
122
|
+
return LIMIT_NAMES.map(
|
|
123
|
+
(name) => `${limitLabel(name, level)} ${limitValueText(name, limits[name])}`
|
|
124
|
+
).join(separator);
|
|
125
|
+
}
|
|
126
|
+
return diff.changes.map((c) => `${limitLabel(c.limit, level)} ${limitValueText(c.limit, c[side])}`).join(separator);
|
|
127
|
+
}
|
|
128
|
+
function diffChangeText(diff, level, separator) {
|
|
129
|
+
if (diff.limits !== void 0) {
|
|
130
|
+
return diffValuesText(diff, diff.category === "added" ? "after" : "before", level, separator);
|
|
131
|
+
}
|
|
132
|
+
return diff.changes.map(
|
|
133
|
+
(c) => `${limitLabel(c.limit, level)} ${limitValueText(c.limit, c.before)} \u2192 ${limitValueText(c.limit, c.after)}`
|
|
134
|
+
).join(separator);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/mode/index.ts
|
|
138
|
+
var MODE = "PW_PERF_MODE";
|
|
139
|
+
var REPEAT = "PW_PERF_REPEAT";
|
|
140
|
+
var ENV = "PW_PERF_ENV";
|
|
141
|
+
var RUN_ID = "PW_PERF_RUN_ID";
|
|
142
|
+
var OUTCOME_FILE = "PW_PERF_OUTCOME_FILE";
|
|
143
|
+
var PRUNE = "PW_PERF_PRUNE";
|
|
144
|
+
var MODE_ENV_NAMES = [MODE, REPEAT, ENV, RUN_ID, OUTCOME_FILE, PRUNE];
|
|
145
|
+
var POSITIVE_INTEGER = /^[1-9][0-9]*$/u;
|
|
146
|
+
var ENV_LABEL = /^[a-z0-9-]{1,32}$/u;
|
|
147
|
+
function parseRepeat(text) {
|
|
148
|
+
return POSITIVE_INTEGER.test(text) ? Number(text) : null;
|
|
149
|
+
}
|
|
150
|
+
function isEnvLabel(text) {
|
|
151
|
+
return ENV_LABEL.test(text);
|
|
152
|
+
}
|
|
153
|
+
var REPEAT_FORMAT = 'an integer >= 1, like "5"';
|
|
154
|
+
var ENV_LABEL_FORMAT = 'a label of lowercase letters, digits and "-" (at most 32 characters), like "staging"';
|
|
155
|
+
function generateRunId(date, random) {
|
|
156
|
+
const time = date.toISOString().slice(0, 19).replaceAll(":", "-");
|
|
157
|
+
const hex = Math.floor(random() * 65536).toString(16).padStart(4, "0");
|
|
158
|
+
return `${time}-${hex}`;
|
|
159
|
+
}
|
|
160
|
+
function read(env, name) {
|
|
161
|
+
const value = env[name];
|
|
162
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
163
|
+
}
|
|
164
|
+
function invalid(name, expected, value, hint) {
|
|
165
|
+
return {
|
|
166
|
+
code: "MODE_INVALID_VALUE",
|
|
167
|
+
message: `${name}: expected ${expected}, got ${JSON.stringify(value)}`,
|
|
168
|
+
hint
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function readModeState(env) {
|
|
172
|
+
const mode = read(env, MODE);
|
|
173
|
+
if (mode === void 0) return { ok: true, value: null };
|
|
174
|
+
const issues = [];
|
|
175
|
+
if (mode !== "test" && mode !== "thresholds") {
|
|
176
|
+
issues.push(
|
|
177
|
+
invalid(
|
|
178
|
+
MODE,
|
|
179
|
+
'"test" or "thresholds"',
|
|
180
|
+
mode,
|
|
181
|
+
`Unset ${MODE} to run without perf mode, or start the run with "npx pw-perf test".`
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const state = { mode: mode === "thresholds" ? "thresholds" : "test" };
|
|
186
|
+
const repeat = read(env, REPEAT);
|
|
187
|
+
if (repeat !== void 0) {
|
|
188
|
+
const parsed = parseRepeat(repeat);
|
|
189
|
+
if (parsed !== null) state.repeat = parsed;
|
|
190
|
+
else {
|
|
191
|
+
issues.push(
|
|
192
|
+
invalid(
|
|
193
|
+
REPEAT,
|
|
194
|
+
REPEAT_FORMAT,
|
|
195
|
+
repeat,
|
|
196
|
+
`Fix the number of repetitions per test, or unset ${REPEAT} to use run.repeat from the config.`
|
|
197
|
+
)
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const label = read(env, ENV);
|
|
202
|
+
if (label !== void 0) {
|
|
203
|
+
if (isEnvLabel(label)) state.env = label;
|
|
204
|
+
else {
|
|
205
|
+
issues.push(
|
|
206
|
+
invalid(
|
|
207
|
+
ENV,
|
|
208
|
+
ENV_LABEL_FORMAT,
|
|
209
|
+
label,
|
|
210
|
+
`Fix the environment label, or unset ${ENV} to use run.env from the config.`
|
|
211
|
+
)
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const runId = read(env, RUN_ID);
|
|
216
|
+
if (runId !== void 0) state.runId = runId;
|
|
217
|
+
const outcomeFile = read(env, OUTCOME_FILE);
|
|
218
|
+
if (outcomeFile !== void 0) state.outcomeFile = outcomeFile;
|
|
219
|
+
const prune = read(env, PRUNE);
|
|
220
|
+
if (prune !== void 0) {
|
|
221
|
+
if (prune === "1") state.prune = true;
|
|
222
|
+
else {
|
|
223
|
+
issues.push(
|
|
224
|
+
invalid(
|
|
225
|
+
PRUNE,
|
|
226
|
+
'"1"',
|
|
227
|
+
prune,
|
|
228
|
+
`Set ${PRUNE}=1 to remove unlocked entries not seen in the run, or unset it.`
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return issues.length > 0 ? { ok: false, issues } : { ok: true, value: state };
|
|
234
|
+
}
|
|
235
|
+
function writeModeState(state) {
|
|
236
|
+
const env = { [MODE]: state.mode };
|
|
237
|
+
if (state.repeat !== void 0) env[REPEAT] = String(state.repeat);
|
|
238
|
+
if (state.env !== void 0) env[ENV] = state.env;
|
|
239
|
+
if (state.runId !== void 0) env[RUN_ID] = state.runId;
|
|
240
|
+
if (state.outcomeFile !== void 0) env[OUTCOME_FILE] = state.outcomeFile;
|
|
241
|
+
if (state.prune === true) env[PRUNE] = "1";
|
|
242
|
+
return env;
|
|
243
|
+
}
|
|
244
|
+
function isCiEnv(env) {
|
|
245
|
+
return read(env, "CI") !== void 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// package.json
|
|
249
|
+
var version = "0.1.0-next.0";
|
|
250
|
+
var peerDependencies = {
|
|
251
|
+
"@playwright/test": ">=1.57.0"
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export { CLI_COMMAND, CONFIG_FILE_BASENAME, CONFIG_FILE_EXTENSIONS, CONTEXT_CLOSED_FAILURE_TEXT, ConfigError, DIFF_CATEGORIES, DOCS_CONFIG_URL, ENV_LABEL_FORMAT, LIMIT_NAMES, LISTED_CATEGORIES, MODE_ENV_NAMES, PACKAGE_NAME, REPEAT_FORMAT, REPOSITORY_URL, SAMPLES_ATTACHMENT_NAME, diffChangeText, diffCountsText, diffMarker, diffValuesText, generateRunId, isCiEnv, isEnvLabel, parseRepeat, peerDependencies, readModeState, version, writeModeState };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/registry/index.ts
|
|
2
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("pw-perf.registry");
|
|
3
|
+
function slot() {
|
|
4
|
+
const global = globalThis;
|
|
5
|
+
let current = global[REGISTRY_KEY];
|
|
6
|
+
if (current === void 0) {
|
|
7
|
+
current = {
|
|
8
|
+
state: void 0,
|
|
9
|
+
wrappedTests: /* @__PURE__ */ new WeakSet(),
|
|
10
|
+
trackedContexts: /* @__PURE__ */ new Set(),
|
|
11
|
+
activeCollector: void 0
|
|
12
|
+
};
|
|
13
|
+
global[REGISTRY_KEY] = current;
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
function fingerprint(state) {
|
|
18
|
+
return JSON.stringify([
|
|
19
|
+
state.snapshot,
|
|
20
|
+
state.mode,
|
|
21
|
+
state.packageVersion,
|
|
22
|
+
state.measuredProjects,
|
|
23
|
+
state.runConditions
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
function setRegistered(state) {
|
|
27
|
+
const registry = slot();
|
|
28
|
+
const previous = registry.state;
|
|
29
|
+
if (previous !== void 0 && fingerprint(previous) === fingerprint(state)) return void 0;
|
|
30
|
+
registry.state = state;
|
|
31
|
+
if (previous === void 0) return void 0;
|
|
32
|
+
const warning = {
|
|
33
|
+
code: "CONFIG_CHANGED_IN_PROCESS",
|
|
34
|
+
message: "config: withPerf() was called again in this process with a different package config; the last one is used",
|
|
35
|
+
hint: "Apply withPerf() once, to the Playwright config that is run, with one package config."
|
|
36
|
+
};
|
|
37
|
+
state.warnings.push(warning);
|
|
38
|
+
return warning;
|
|
39
|
+
}
|
|
40
|
+
function getRegistered() {
|
|
41
|
+
return slot().state;
|
|
42
|
+
}
|
|
43
|
+
function notWrappedWarning() {
|
|
44
|
+
return {
|
|
45
|
+
code: "NOT_WRAPPED_WITH_PERF",
|
|
46
|
+
message: "config: withPerf() was not applied to the Playwright config in this process, so the default package config is used",
|
|
47
|
+
hint: 'Wrap the Playwright config: export default withPerf(defineConfig({ ... }), perfConfig) with withPerf from "playwright-performance-regression/config".'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function wrappedTests() {
|
|
51
|
+
return slot().wrappedTests;
|
|
52
|
+
}
|
|
53
|
+
function trackedContexts() {
|
|
54
|
+
return slot().trackedContexts;
|
|
55
|
+
}
|
|
56
|
+
function activeCollector() {
|
|
57
|
+
return slot().activeCollector;
|
|
58
|
+
}
|
|
59
|
+
function setActiveCollector(collector) {
|
|
60
|
+
slot().activeCollector = collector;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { activeCollector, getRegistered, notWrappedWarning, setActiveCollector, setRegistered, trackedContexts, wrappedTests };
|