playwright-performance-regression 0.1.0-next.1 → 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.
Files changed (41) hide show
  1. package/CHANGELOG.md +431 -0
  2. package/README.md +96 -64
  3. package/dist/{chunk-L5C63HEF.js → chunk-CISGJCFW.js} +378 -48
  4. package/dist/chunk-CXE5IWZY.js +1648 -0
  5. package/dist/{chunk-B64P2D5A.js → chunk-E2IX265O.js} +395 -206
  6. package/dist/chunk-IUI4AFE5.cjs +658 -0
  7. package/dist/{chunk-WZVQK7CQ.cjs → chunk-KELMALEG.cjs} +408 -218
  8. package/dist/{chunk-GCA73FFP.cjs → chunk-LUA4WRIQ.cjs} +382 -47
  9. package/dist/chunk-RL27E3AB.js +595 -0
  10. package/dist/{chunk-DYLCGMI2.js → chunk-S6UH6QPK.js} +6 -1
  11. package/dist/cli.js +2761 -2339
  12. package/dist/config.cjs +122 -137
  13. package/dist/config.d.cts +3 -2
  14. package/dist/config.d.ts +3 -2
  15. package/dist/config.js +117 -132
  16. package/dist/fixture.cjs +9 -5
  17. package/dist/fixture.d.cts +10 -4
  18. package/dist/fixture.d.ts +10 -4
  19. package/dist/fixture.js +4 -4
  20. package/dist/index.cjs +3 -3
  21. package/dist/index.d.cts +121 -25
  22. package/dist/index.d.ts +121 -25
  23. package/dist/index.js +1 -1
  24. package/dist/perf-api-2DH_keLh.d.cts +17 -0
  25. package/dist/perf-api-2DH_keLh.d.ts +17 -0
  26. package/dist/reporter.cjs +5713 -1237
  27. package/dist/reporter.js +6905 -693
  28. package/dist/test.cjs +4 -4
  29. package/dist/test.js +4 -4
  30. package/package.json +19 -1
  31. package/schemas/common.schema.json +2 -2
  32. package/schemas/config.schema.json +72 -26
  33. package/schemas/outcome.schema.json +2 -2
  34. package/schemas/run-report.schema.json +549 -20
  35. package/schemas/samples.schema.json +48 -37
  36. package/schemas/thresholds.schema.json +1 -1
  37. package/dist/chunk-3CLCMD2Q.js +0 -3411
  38. package/dist/chunk-4SFI55HF.cjs +0 -319
  39. package/dist/chunk-HBGADXLP.js +0 -254
  40. package/dist/perf-api-V4PeHVE0.d.cts +0 -22
  41. package/dist/perf-api-V4PeHVE0.d.ts +0 -22
package/dist/config.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk4SFI55HF_cjs = require('./chunk-4SFI55HF.cjs');
4
- var chunkGCA73FFP_cjs = require('./chunk-GCA73FFP.cjs');
3
+ var chunkIUI4AFE5_cjs = require('./chunk-IUI4AFE5.cjs');
4
+ var chunkLUA4WRIQ_cjs = require('./chunk-LUA4WRIQ.cjs');
5
5
 
6
6
  // src/config/reporter-path.ts
7
7
  function currentFile() {
@@ -20,16 +20,10 @@ function reporterEntryPath() {
20
20
  // src/config/run-conditions.ts
21
21
  var CONSOLE_REPORTERS = /* @__PURE__ */ new Set(["list", "line", "dot", "github"]);
22
22
  var ARTIFACTS = ["trace", "video", "screenshot"];
23
- var PACKAGE_REPORTER = `${chunk4SFI55HF_cjs.PACKAGE_NAME}/reporter`;
23
+ var PACKAGE_REPORTER = `${chunkIUI4AFE5_cjs.PACKAGE_NAME}/reporter`;
24
24
  function projectName(project) {
25
25
  return project.name ?? "";
26
26
  }
27
- function browserOf(project, config) {
28
- return project?.use?.browserName ?? config.use?.browserName ?? project?.use?.defaultBrowserType ?? config.use?.defaultBrowserType ?? "chromium";
29
- }
30
- function quoted(names) {
31
- return names.map((name) => JSON.stringify(name)).join(", ");
32
- }
33
27
  function records(value) {
34
28
  if (value === void 0 || value === "off") return false;
35
29
  if (typeof value === "object" && value !== null && "mode" in value) return value.mode !== "off";
@@ -41,57 +35,26 @@ function positive(value) {
41
35
  function artifactsOff(use) {
42
36
  return { ...use, trace: "off", video: "off", screenshot: "off" };
43
37
  }
44
- function measuredNames(config, projects, option) {
45
- const names = projects.map(projectName);
46
- if (option !== "auto") {
47
- const known = new Set(names);
48
- const unknown = option.filter((name) => !known.has(name));
49
- if (unknown.length > 0) {
50
- const available = names.length === 0 || config.projects === void 0 ? "it has no projects, only the default one" : `its projects are ${quoted(names)}`;
51
- return {
52
- ok: false,
53
- issues: unknown.map((name) => ({
54
- code: "CONFIG_UNKNOWN_PROJECT",
55
- path: "run.projects",
56
- message: `run.projects: project ${JSON.stringify(name)} is not in the Playwright config; ${available}`,
57
- hint: 'Use project names from the Playwright config, or "auto".'
58
- }))
59
- };
60
- }
61
- return { ok: true, value: names.filter((name) => option.includes(name)) };
62
- }
38
+ function andGrep(extra, own) {
39
+ if (own === void 0) return new RegExp(extra, "i");
40
+ const list = Array.isArray(own) ? own : [own];
41
+ const flags = /* @__PURE__ */ new Set(["i", ...list.flatMap((re) => [...re.flags])]);
42
+ flags.delete("g");
43
+ flags.delete("y");
44
+ const ownSource = list.map((re) => `(?:${re.source})`).join("|");
45
+ return new RegExp(
46
+ `^(?=[\\s\\S]*?(?:${extra}))(?=[\\s\\S]*?(?:${ownSource}))`,
47
+ [...flags].sort().join("")
48
+ );
49
+ }
50
+ function measurableProjects(projects) {
63
51
  const supporting = new Set(
64
52
  projects.flatMap((p) => [
65
53
  ...p.dependencies ?? [],
66
54
  ...p.teardown === void 0 ? [] : [p.teardown]
67
55
  ])
68
56
  );
69
- const measured = projects.filter((p) => !supporting.has(projectName(p)) && browserOf(p, config) === "chromium").map(projectName);
70
- if (measured.length > 0) return { ok: true, value: measured };
71
- return {
72
- ok: false,
73
- issues: [
74
- {
75
- code: "CONFIG_NO_MEASURED_PROJECT",
76
- path: "run.projects",
77
- message: 'run.projects: no project is measured; "auto" measures Chromium projects that are not a dependency or teardown of another project, and the Playwright config has none',
78
- hint: 'List the projects to measure in run.projects, e.g. ["firefox"].'
79
- }
80
- ]
81
- };
82
- }
83
- function projectsToKeep(projects, measured) {
84
- const byName = new Map(projects.map((p) => [projectName(p), p]));
85
- const keep = /* @__PURE__ */ new Set();
86
- const visit = (name) => {
87
- const project = byName.get(name);
88
- if (project === void 0 || keep.has(name)) return;
89
- keep.add(name);
90
- for (const dependency of project.dependencies ?? []) visit(dependency);
91
- if (project.teardown !== void 0) visit(project.teardown);
92
- };
93
- for (const name of measured) visit(name);
94
- return keep;
57
+ return projects.map(projectName).filter((name) => !supporting.has(name));
95
58
  }
96
59
  function reporterEntries(reporter) {
97
60
  if (reporter === void 0) return [];
@@ -104,9 +67,13 @@ function planReporters(reporter, input) {
104
67
  const ours = (name) => name === input.reporterPath || name === PACKAGE_REPORTER;
105
68
  const kept = [];
106
69
  const removed = [];
70
+ const replaced = [];
107
71
  for (const entry of reporterEntries(reporter)) {
108
72
  const [name, options] = entry;
109
- if (!CONSOLE_REPORTERS.has(name) && !input.keepReporters.includes(name) && !ours(name)) {
73
+ if (name === "list" && !input.keepReporters.includes(name)) {
74
+ if (!replaced.includes(name)) replaced.push(name);
75
+ kept.push(["dot"]);
76
+ } else if (!CONSOLE_REPORTERS.has(name) && !input.keepReporters.includes(name) && !ours(name)) {
110
77
  removed.push(name);
111
78
  } else if (name === "html") {
112
79
  kept.push([name, { ...options, open: "never" }]);
@@ -114,143 +81,161 @@ function planReporters(reporter, input) {
114
81
  kept.push(entry);
115
82
  }
116
83
  }
84
+ const firstDot = kept.findIndex(([name]) => name === "dot");
85
+ const deduped = kept.filter(([name], i) => name !== "dot" || i === firstDot);
117
86
  const reporters = [];
118
- if (!kept.some(([name]) => CONSOLE_REPORTERS.has(name))) {
119
- reporters.push([input.ci ? "dot" : "list"]);
120
- }
121
- reporters.push(...kept);
122
- if (!kept.some(([name]) => ours(name))) reporters.push([input.reporterPath]);
123
- return { reporters, removed };
87
+ if (!deduped.some(([name]) => CONSOLE_REPORTERS.has(name))) reporters.push(["dot"]);
88
+ reporters.push(...deduped);
89
+ if (!deduped.some(([name]) => ours(name))) reporters.push([input.reporterPath]);
90
+ return { reporters, removed, replaced };
124
91
  }
125
- function overriddenSettings(config, kept, repeat, measured) {
92
+ function effectiveLaunchOptions(config, project) {
93
+ return project?.use?.launchOptions ?? config.use?.launchOptions;
94
+ }
95
+ function measuredLaunchOptions(config, measured) {
96
+ if (config.projects === void 0) return [config.use?.launchOptions];
97
+ return config.projects.filter((p) => measured.has(projectName(p))).map((p) => effectiveLaunchOptions(config, p));
98
+ }
99
+ function overriddenSettings(config, kept, slowMoOverridden) {
126
100
  const scopes = [config, ...kept];
127
- const repeatChanged = kept.length === 0 ? config.repeatEach !== void 0 && config.repeatEach !== repeat : kept.some((p) => {
128
- const own = p.repeatEach ?? config.repeatEach;
129
- return own !== void 0 && own !== (measured.has(projectName(p)) ? repeat : 1);
130
- });
101
+ const repeatChanged = [config, ...kept].some(
102
+ (scope) => scope.repeatEach !== void 0 && scope.repeatEach !== 1
103
+ );
131
104
  const changed = [
132
105
  ["workers", config.workers !== 1],
133
- ["retries", scopes.some((scope) => positive(scope.retries))],
134
106
  ["repeatEach", repeatChanged],
135
107
  ["maxFailures", positive(config.maxFailures)],
136
108
  ["globalTimeout", positive(config.globalTimeout)],
137
109
  ...ARTIFACTS.map((name) => [
138
110
  name,
139
111
  scopes.some((scope) => records(scope.use?.[name]))
140
- ])
112
+ ]),
113
+ ["slowMo", slowMoOverridden]
141
114
  ];
142
115
  return changed.filter(([, value]) => value).map(([name]) => name);
143
116
  }
144
- function slowMoWarnings(config, kept) {
145
- const places = [
146
- ...positive(config.use?.launchOptions?.slowMo) ? ["the global config"] : [],
147
- ...kept.filter((p) => positive(p.use?.launchOptions?.slowMo)).map((p) => `project ${JSON.stringify(projectName(p))}`)
148
- ];
149
- if (places.length === 0) return [];
150
- return [
151
- {
152
- code: "CONFIG_SLOW_MO",
153
- path: "use.launchOptions.slowMo",
154
- message: `use.launchOptions.slowMo: is greater than 0 in ${places.join(", ")}; it slows down every browser action and distorts the measured times`,
155
- hint: "Remove slowMo from the Playwright config for the measurement run."
156
- }
157
- ];
158
- }
159
- function enginesWarnings(config, projects, measured) {
160
- const byName = new Map(projects.map((p) => [projectName(p), p]));
161
- const engines = [...new Set(measured.map((name) => browserOf(byName.get(name), config)))];
162
- if (engines.length < 2) return [];
163
- return [
164
- {
165
- code: "CONFIG_MULTIPLE_ENGINES",
166
- path: "run.projects",
167
- message: `run.projects: the measured projects use more than one browser engine (${engines.join(", ")}); their samples go to the same keys`,
168
- hint: "Measure one browser engine per run: list projects of one engine in run.projects."
169
- }
170
- ];
171
- }
172
117
  function planPerfRun(config, input) {
173
118
  const source = config;
174
119
  const projects = source.projects ?? [{}];
175
- const measured = measuredNames(source, projects, input.projects);
176
- if (!measured.ok) return measured;
177
- const measuredSet = new Set(measured.value);
178
- const keep = projectsToKeep(projects, measured.value);
179
- const kept = source.projects === void 0 ? [] : projects.filter((p) => keep.has(projectName(p)));
180
- const removedProjects = source.projects === void 0 ? [] : projects.filter((p) => !keep.has(projectName(p))).map(projectName);
181
- const { reporters, removed } = planReporters(source.reporter, input);
120
+ const measured = measurableProjects(projects);
121
+ const { reporters, removed, replaced } = planReporters(source.reporter, input);
182
122
  const result = {
183
123
  ...source,
184
124
  workers: 1,
185
- retries: 0,
186
125
  maxFailures: 0,
187
126
  globalTimeout: 0,
188
127
  use: artifactsOff(source.use),
189
128
  reporter: reporters
190
129
  };
191
- if (source.projects === void 0) {
192
- result.repeatEach = input.repeat;
130
+ result.repeatEach = 1;
131
+ const grep = input.grep ?? null;
132
+ const overrideSlowMo = input.overrideSlowMo ?? false;
133
+ const kept = source.projects ?? [];
134
+ const measuredSet = new Set(measured);
135
+ if (source.projects !== void 0) {
136
+ result.projects = kept.map((p) => {
137
+ const project = { ...p, repeatEach: 1, use: artifactsOff(p.use) };
138
+ const isMeasured = measuredSet.has(projectName(p));
139
+ if (grep !== null && isMeasured) {
140
+ project.grep = andGrep(grep, p.grep ?? source.grep);
141
+ }
142
+ if (overrideSlowMo && isMeasured) {
143
+ project.use = {
144
+ ...project.use,
145
+ launchOptions: { ...effectiveLaunchOptions(source, p), slowMo: 0 }
146
+ };
147
+ }
148
+ return project;
149
+ });
193
150
  } else {
194
- result.projects = kept.map((p) => ({
195
- ...p,
196
- retries: 0,
197
- repeatEach: measuredSet.has(projectName(p)) ? input.repeat : 1,
198
- use: artifactsOff(p.use)
199
- }));
151
+ if (grep !== null) result.grep = andGrep(grep, source.grep);
152
+ if (overrideSlowMo) {
153
+ result.use = { ...result.use, launchOptions: { ...source.use?.launchOptions, slowMo: 0 } };
154
+ }
200
155
  }
156
+ const slowMoOverridden = overrideSlowMo && measuredLaunchOptions(source, measuredSet).some((options) => positive(options?.slowMo));
201
157
  return {
202
158
  ok: true,
203
159
  value: {
204
160
  config: result,
205
- measuredProjects: measured.value,
161
+ measuredProjects: measured,
206
162
  runConditions: {
207
- overridden: overriddenSettings(source, kept, input.repeat, measuredSet),
208
- removedProjects,
209
- removedReporters: removed
210
- },
211
- warnings: [
212
- ...enginesWarnings(source, projects, measured.value),
213
- ...slowMoWarnings(source, kept)
214
- ]
163
+ overridden: overriddenSettings(source, kept, slowMoOverridden),
164
+ removedReporters: removed,
165
+ replacedReporters: replaced
166
+ }
215
167
  }
216
168
  };
217
169
  }
218
170
 
219
171
  // src/config/with-perf.ts
220
172
  function withPerf(config, perfConfig) {
221
- const mode = chunk4SFI55HF_cjs.readModeState(process.env);
222
- if (!mode.ok) throw new chunk4SFI55HF_cjs.ConfigError(mode.issues);
223
- if (mode.value === null) return config;
173
+ const first = chunkIUI4AFE5_cjs.readModeState(process.env);
174
+ if (!first.ok) throw new chunkIUI4AFE5_cjs.ConfigError(first.issues);
175
+ if (first.value === null) return config;
176
+ const argvIssues = mainProcessSetup(first.value.mode);
177
+ const mode = chunkIUI4AFE5_cjs.readModeState(process.env);
178
+ if (!mode.ok || mode.value === null) throw new Error("withPerf: the mode state changed");
224
179
  const state = mode.value;
225
- const resolved = chunkGCA73FFP_cjs.resolveConfig(perfConfig, {
226
- mode: state.mode,
227
- ...state.repeat === void 0 ? {} : { repeat: state.repeat },
228
- ...state.env === void 0 ? {} : { env: state.env }
180
+ const resolved = chunkLUA4WRIQ_cjs.resolveConfig(perfConfig, {
181
+ mode: state.mode === "check" ? "test" : state.mode,
182
+ ...passesOverride(state),
183
+ ...state.env === void 0 ? {} : { env: state.env },
184
+ ...state.thresholdsDir === void 0 ? {} : { thresholdsDir: state.thresholdsDir },
185
+ ...state.minSamples === void 0 ? {} : { minSamples: state.minSamples }
229
186
  });
230
- if (!resolved.ok) throw new chunk4SFI55HF_cjs.ConfigError(resolved.issues);
187
+ if (!resolved.ok) throw new chunkIUI4AFE5_cjs.ConfigError(resolved.issues);
231
188
  const { config: perf, snapshot, warnings } = resolved.value;
232
189
  const plan = planPerfRun(config, {
233
- projects: perf.run.projects,
234
190
  keepReporters: perf.run.keepReporters,
235
- repeat: perf.run.repeat[state.mode],
236
- ci: chunk4SFI55HF_cjs.isCiEnv(process.env),
191
+ grep: perf.run.grep,
192
+ overrideSlowMo: perf.run.overrideSlowMo,
237
193
  reporterPath: reporterEntryPath()
238
194
  });
239
- if (!plan.ok) throw new chunk4SFI55HF_cjs.ConfigError(plan.issues);
240
- chunk4SFI55HF_cjs.setRegistered({
195
+ chunkIUI4AFE5_cjs.setRegistered({
241
196
  config: perf,
242
197
  snapshot,
243
198
  mode: state,
244
- packageVersion: chunk4SFI55HF_cjs.version,
199
+ packageVersion: chunkIUI4AFE5_cjs.version,
245
200
  measuredProjects: plan.value.measuredProjects,
246
201
  runConditions: plan.value.runConditions,
247
- warnings: [...warnings, ...plan.value.warnings]
202
+ warnings: [...warnings, ...argvIssues],
203
+ perfConfigPassed: perfConfig !== void 0
248
204
  });
249
205
  return plan.value.config;
250
206
  }
207
+ function passesOverride(state) {
208
+ if (state.mode === "check") return {};
209
+ if (state.pass !== void 0) return { passes: state.pass.total };
210
+ return state.passes === void 0 ? {} : { passes: state.passes };
211
+ }
212
+ var SETUP_DONE = /* @__PURE__ */ Symbol.for("playwright-performance-regression.mainProcessSetup");
213
+ function mainProcessSetup(mode) {
214
+ if (process.env.TEST_WORKER_INDEX !== void 0) return [];
215
+ const store = globalThis;
216
+ const done = store[SETUP_DONE];
217
+ if (done !== void 0) return done;
218
+ if ((process.env[chunkIUI4AFE5_cjs.RUN_ID_ENV] ?? "") === "") {
219
+ process.env[chunkIUI4AFE5_cjs.RUN_ID_ENV] = chunkIUI4AFE5_cjs.generateRunId(/* @__PURE__ */ new Date(), Math.random);
220
+ }
221
+ const found = chunkIUI4AFE5_cjs.argvWarnings(process.argv, chunkIUI4AFE5_cjs.PACKAGE_NAME, mode);
222
+ if (found.reporter !== null && mode !== "check") throw new chunkIUI4AFE5_cjs.ConfigError([found.reporter]);
223
+ const report = [];
224
+ for (const issue of [found.reporter, found.unsupported]) {
225
+ if (issue === null) continue;
226
+ process.stderr.write(
227
+ `${chunkIUI4AFE5_cjs.PACKAGE_NAME}: warning ${issue.code}: ${issue.message}
228
+ Hint: ${issue.hint}
229
+ `
230
+ );
231
+ }
232
+ if (found.unsupported !== null) report.push(found.unsupported);
233
+ store[SETUP_DONE] = report;
234
+ return report;
235
+ }
251
236
 
252
237
  Object.defineProperty(exports, "definePerfConfig", {
253
238
  enumerable: true,
254
- get: function () { return chunkGCA73FFP_cjs.definePerfConfig; }
239
+ get: function () { return chunkLUA4WRIQ_cjs.definePerfConfig; }
255
240
  });
256
241
  exports.withPerf = withPerf;
package/dist/config.d.cts CHANGED
@@ -7,8 +7,9 @@ import { PlaywrightTestConfig } from '@playwright/test';
7
7
  * else (01-REQ-08, P-02). In perf mode it resolves the package config, registers it for the
8
8
  * reporter and the fixtures of this process and returns a copy of `config` with the run
9
9
  * conditions of perf mode; invalid config or mode variables throw ConfigError before any test
10
- * runs. No I/O, no randomness: the result depends only on the arguments and the environment, so
11
- * it is the same in the main process and in the workers (01-REQ-09).
10
+ * runs. The returned config depends only on the arguments and the environment, so it is the same
11
+ * in the main process and in the workers (01-REQ-09). Only in the main process it sets
12
+ * PW_PERF_RUN_ID for the workers and warns about arguments (04-REQ-60, 04-REQ-61).
12
13
  */
13
14
  declare function withPerf<T extends PlaywrightTestConfig>(config: T, perfConfig?: PerfConfigInput): T;
14
15
 
package/dist/config.d.ts CHANGED
@@ -7,8 +7,9 @@ import { PlaywrightTestConfig } from '@playwright/test';
7
7
  * else (01-REQ-08, P-02). In perf mode it resolves the package config, registers it for the
8
8
  * reporter and the fixtures of this process and returns a copy of `config` with the run
9
9
  * conditions of perf mode; invalid config or mode variables throw ConfigError before any test
10
- * runs. No I/O, no randomness: the result depends only on the arguments and the environment, so
11
- * it is the same in the main process and in the workers (01-REQ-09).
10
+ * runs. The returned config depends only on the arguments and the environment, so it is the same
11
+ * in the main process and in the workers (01-REQ-09). Only in the main process it sets
12
+ * PW_PERF_RUN_ID for the workers and warns about arguments (04-REQ-60, 04-REQ-61).
12
13
  */
13
14
  declare function withPerf<T extends PlaywrightTestConfig>(config: T, perfConfig?: PerfConfigInput): T;
14
15