playwright-performance-regression 0.0.0 → 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 +212 -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 +144 -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
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLV3O2BAT_cjs = require('./chunk-LV3O2BAT.cjs');
|
|
4
|
+
var chunkGCA73FFP_cjs = require('./chunk-GCA73FFP.cjs');
|
|
5
|
+
|
|
6
|
+
// src/config/reporter-path.ts
|
|
7
|
+
function currentFile() {
|
|
8
|
+
return typeof __filename === "string" ? __filename : undefined;
|
|
9
|
+
}
|
|
10
|
+
function reporterPathNextTo(file) {
|
|
11
|
+
const cut = Math.max(file.lastIndexOf("/"), file.lastIndexOf("\\")) + 1;
|
|
12
|
+
const name = file.slice(cut);
|
|
13
|
+
const dot = name.lastIndexOf(".");
|
|
14
|
+
return `${file.slice(0, cut)}reporter${dot === -1 ? "" : name.slice(dot)}`;
|
|
15
|
+
}
|
|
16
|
+
function reporterEntryPath() {
|
|
17
|
+
return reporterPathNextTo(currentFile());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/config/run-conditions.ts
|
|
21
|
+
var CONSOLE_REPORTERS = /* @__PURE__ */ new Set(["list", "line", "dot", "github"]);
|
|
22
|
+
var ARTIFACTS = ["trace", "video", "screenshot"];
|
|
23
|
+
var PACKAGE_REPORTER = `${chunkLV3O2BAT_cjs.PACKAGE_NAME}/reporter`;
|
|
24
|
+
function projectName(project) {
|
|
25
|
+
return project.name ?? "";
|
|
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
|
+
function records(value) {
|
|
34
|
+
if (value === void 0 || value === "off") return false;
|
|
35
|
+
if (typeof value === "object" && value !== null && "mode" in value) return value.mode !== "off";
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
function positive(value) {
|
|
39
|
+
return value !== void 0 && value > 0;
|
|
40
|
+
}
|
|
41
|
+
function artifactsOff(use) {
|
|
42
|
+
return { ...use, trace: "off", video: "off", screenshot: "off" };
|
|
43
|
+
}
|
|
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
|
+
}
|
|
63
|
+
const supporting = new Set(
|
|
64
|
+
projects.flatMap((p) => [
|
|
65
|
+
...p.dependencies ?? [],
|
|
66
|
+
...p.teardown === void 0 ? [] : [p.teardown]
|
|
67
|
+
])
|
|
68
|
+
);
|
|
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;
|
|
95
|
+
}
|
|
96
|
+
function reporterEntries(reporter) {
|
|
97
|
+
if (reporter === void 0) return [];
|
|
98
|
+
if (typeof reporter === "string") return [[reporter]];
|
|
99
|
+
return reporter.map(
|
|
100
|
+
(item) => typeof item === "string" ? [item] : item.length > 1 ? [String(item[0]), item[1]] : [String(item[0])]
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function planReporters(reporter, input) {
|
|
104
|
+
const ours = (name) => name === input.reporterPath || name === PACKAGE_REPORTER;
|
|
105
|
+
const kept = [];
|
|
106
|
+
const removed = [];
|
|
107
|
+
for (const entry of reporterEntries(reporter)) {
|
|
108
|
+
const [name, options] = entry;
|
|
109
|
+
if (!CONSOLE_REPORTERS.has(name) && !input.keepReporters.includes(name) && !ours(name)) {
|
|
110
|
+
removed.push(name);
|
|
111
|
+
} else if (name === "html") {
|
|
112
|
+
kept.push([name, { ...options, open: "never" }]);
|
|
113
|
+
} else {
|
|
114
|
+
kept.push(entry);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
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 };
|
|
124
|
+
}
|
|
125
|
+
function overriddenSettings(config, kept, repeat, measured) {
|
|
126
|
+
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
|
+
});
|
|
131
|
+
const changed = [
|
|
132
|
+
["workers", config.workers !== 1],
|
|
133
|
+
["retries", scopes.some((scope) => positive(scope.retries))],
|
|
134
|
+
["repeatEach", repeatChanged],
|
|
135
|
+
["maxFailures", positive(config.maxFailures)],
|
|
136
|
+
["globalTimeout", positive(config.globalTimeout)],
|
|
137
|
+
...ARTIFACTS.map((name) => [
|
|
138
|
+
name,
|
|
139
|
+
scopes.some((scope) => records(scope.use?.[name]))
|
|
140
|
+
])
|
|
141
|
+
];
|
|
142
|
+
return changed.filter(([, value]) => value).map(([name]) => name);
|
|
143
|
+
}
|
|
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
|
+
function planPerfRun(config, input) {
|
|
173
|
+
const source = config;
|
|
174
|
+
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);
|
|
182
|
+
const result = {
|
|
183
|
+
...source,
|
|
184
|
+
workers: 1,
|
|
185
|
+
retries: 0,
|
|
186
|
+
maxFailures: 0,
|
|
187
|
+
globalTimeout: 0,
|
|
188
|
+
use: artifactsOff(source.use),
|
|
189
|
+
reporter: reporters
|
|
190
|
+
};
|
|
191
|
+
if (source.projects === void 0) {
|
|
192
|
+
result.repeatEach = input.repeat;
|
|
193
|
+
} 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
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
ok: true,
|
|
203
|
+
value: {
|
|
204
|
+
config: result,
|
|
205
|
+
measuredProjects: measured.value,
|
|
206
|
+
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
|
+
]
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/config/with-perf.ts
|
|
220
|
+
function withPerf(config, perfConfig) {
|
|
221
|
+
const mode = chunkLV3O2BAT_cjs.readModeState(process.env);
|
|
222
|
+
if (!mode.ok) throw new chunkLV3O2BAT_cjs.ConfigError(mode.issues);
|
|
223
|
+
if (mode.value === null) return config;
|
|
224
|
+
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 }
|
|
229
|
+
});
|
|
230
|
+
if (!resolved.ok) throw new chunkLV3O2BAT_cjs.ConfigError(resolved.issues);
|
|
231
|
+
const { config: perf, snapshot, warnings } = resolved.value;
|
|
232
|
+
const plan = planPerfRun(config, {
|
|
233
|
+
projects: perf.run.projects,
|
|
234
|
+
keepReporters: perf.run.keepReporters,
|
|
235
|
+
repeat: perf.run.repeat[state.mode],
|
|
236
|
+
ci: chunkLV3O2BAT_cjs.isCiEnv(process.env),
|
|
237
|
+
reporterPath: reporterEntryPath()
|
|
238
|
+
});
|
|
239
|
+
if (!plan.ok) throw new chunkLV3O2BAT_cjs.ConfigError(plan.issues);
|
|
240
|
+
chunkLV3O2BAT_cjs.setRegistered({
|
|
241
|
+
config: perf,
|
|
242
|
+
snapshot,
|
|
243
|
+
mode: state,
|
|
244
|
+
packageVersion: chunkLV3O2BAT_cjs.version,
|
|
245
|
+
measuredProjects: plan.value.measuredProjects,
|
|
246
|
+
runConditions: plan.value.runConditions,
|
|
247
|
+
warnings: [...warnings, ...plan.value.warnings]
|
|
248
|
+
});
|
|
249
|
+
return plan.value.config;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
Object.defineProperty(exports, "definePerfConfig", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () { return chunkGCA73FFP_cjs.definePerfConfig; }
|
|
255
|
+
});
|
|
256
|
+
exports.withPerf = withPerf;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PerfConfigInput } from './index.cjs';
|
|
2
|
+
export { definePerfConfig } from './index.cjs';
|
|
3
|
+
import { PlaywrightTestConfig } from '@playwright/test';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wraps the Playwright config. Outside perf mode it returns `config` itself and does nothing
|
|
7
|
+
* else (01-REQ-08, P-02). In perf mode it resolves the package config, registers it for the
|
|
8
|
+
* reporter and the fixtures of this process and returns a copy of `config` with the run
|
|
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).
|
|
12
|
+
*/
|
|
13
|
+
declare function withPerf<T extends PlaywrightTestConfig>(config: T, perfConfig?: PerfConfigInput): T;
|
|
14
|
+
|
|
15
|
+
export { PerfConfigInput, withPerf };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PerfConfigInput } from './index.js';
|
|
2
|
+
export { definePerfConfig } from './index.js';
|
|
3
|
+
import { PlaywrightTestConfig } from '@playwright/test';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wraps the Playwright config. Outside perf mode it returns `config` itself and does nothing
|
|
7
|
+
* else (01-REQ-08, P-02). In perf mode it resolves the package config, registers it for the
|
|
8
|
+
* reporter and the fixtures of this process and returns a copy of `config` with the run
|
|
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).
|
|
12
|
+
*/
|
|
13
|
+
declare function withPerf<T extends PlaywrightTestConfig>(config: T, perfConfig?: PerfConfigInput): T;
|
|
14
|
+
|
|
15
|
+
export { PerfConfigInput, withPerf };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { setRegistered } from './chunk-DYLCGMI2.js';
|
|
2
|
+
import { readModeState, ConfigError, isCiEnv, version, PACKAGE_NAME } from './chunk-6AB42SPF.js';
|
|
3
|
+
import { resolveConfig } from './chunk-HES6BVZT.js';
|
|
4
|
+
export { definePerfConfig } from './chunk-HES6BVZT.js';
|
|
5
|
+
|
|
6
|
+
// src/config/reporter-path.ts
|
|
7
|
+
function currentFile() {
|
|
8
|
+
return typeof __filename === "string" ? __filename : import.meta.filename;
|
|
9
|
+
}
|
|
10
|
+
function reporterPathNextTo(file) {
|
|
11
|
+
const cut = Math.max(file.lastIndexOf("/"), file.lastIndexOf("\\")) + 1;
|
|
12
|
+
const name = file.slice(cut);
|
|
13
|
+
const dot = name.lastIndexOf(".");
|
|
14
|
+
return `${file.slice(0, cut)}reporter${dot === -1 ? "" : name.slice(dot)}`;
|
|
15
|
+
}
|
|
16
|
+
function reporterEntryPath() {
|
|
17
|
+
return reporterPathNextTo(currentFile());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/config/run-conditions.ts
|
|
21
|
+
var CONSOLE_REPORTERS = /* @__PURE__ */ new Set(["list", "line", "dot", "github"]);
|
|
22
|
+
var ARTIFACTS = ["trace", "video", "screenshot"];
|
|
23
|
+
var PACKAGE_REPORTER = `${PACKAGE_NAME}/reporter`;
|
|
24
|
+
function projectName(project) {
|
|
25
|
+
return project.name ?? "";
|
|
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
|
+
function records(value) {
|
|
34
|
+
if (value === void 0 || value === "off") return false;
|
|
35
|
+
if (typeof value === "object" && value !== null && "mode" in value) return value.mode !== "off";
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
function positive(value) {
|
|
39
|
+
return value !== void 0 && value > 0;
|
|
40
|
+
}
|
|
41
|
+
function artifactsOff(use) {
|
|
42
|
+
return { ...use, trace: "off", video: "off", screenshot: "off" };
|
|
43
|
+
}
|
|
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
|
+
}
|
|
63
|
+
const supporting = new Set(
|
|
64
|
+
projects.flatMap((p) => [
|
|
65
|
+
...p.dependencies ?? [],
|
|
66
|
+
...p.teardown === void 0 ? [] : [p.teardown]
|
|
67
|
+
])
|
|
68
|
+
);
|
|
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;
|
|
95
|
+
}
|
|
96
|
+
function reporterEntries(reporter) {
|
|
97
|
+
if (reporter === void 0) return [];
|
|
98
|
+
if (typeof reporter === "string") return [[reporter]];
|
|
99
|
+
return reporter.map(
|
|
100
|
+
(item) => typeof item === "string" ? [item] : item.length > 1 ? [String(item[0]), item[1]] : [String(item[0])]
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function planReporters(reporter, input) {
|
|
104
|
+
const ours = (name) => name === input.reporterPath || name === PACKAGE_REPORTER;
|
|
105
|
+
const kept = [];
|
|
106
|
+
const removed = [];
|
|
107
|
+
for (const entry of reporterEntries(reporter)) {
|
|
108
|
+
const [name, options] = entry;
|
|
109
|
+
if (!CONSOLE_REPORTERS.has(name) && !input.keepReporters.includes(name) && !ours(name)) {
|
|
110
|
+
removed.push(name);
|
|
111
|
+
} else if (name === "html") {
|
|
112
|
+
kept.push([name, { ...options, open: "never" }]);
|
|
113
|
+
} else {
|
|
114
|
+
kept.push(entry);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
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 };
|
|
124
|
+
}
|
|
125
|
+
function overriddenSettings(config, kept, repeat, measured) {
|
|
126
|
+
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
|
+
});
|
|
131
|
+
const changed = [
|
|
132
|
+
["workers", config.workers !== 1],
|
|
133
|
+
["retries", scopes.some((scope) => positive(scope.retries))],
|
|
134
|
+
["repeatEach", repeatChanged],
|
|
135
|
+
["maxFailures", positive(config.maxFailures)],
|
|
136
|
+
["globalTimeout", positive(config.globalTimeout)],
|
|
137
|
+
...ARTIFACTS.map((name) => [
|
|
138
|
+
name,
|
|
139
|
+
scopes.some((scope) => records(scope.use?.[name]))
|
|
140
|
+
])
|
|
141
|
+
];
|
|
142
|
+
return changed.filter(([, value]) => value).map(([name]) => name);
|
|
143
|
+
}
|
|
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
|
+
function planPerfRun(config, input) {
|
|
173
|
+
const source = config;
|
|
174
|
+
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);
|
|
182
|
+
const result = {
|
|
183
|
+
...source,
|
|
184
|
+
workers: 1,
|
|
185
|
+
retries: 0,
|
|
186
|
+
maxFailures: 0,
|
|
187
|
+
globalTimeout: 0,
|
|
188
|
+
use: artifactsOff(source.use),
|
|
189
|
+
reporter: reporters
|
|
190
|
+
};
|
|
191
|
+
if (source.projects === void 0) {
|
|
192
|
+
result.repeatEach = input.repeat;
|
|
193
|
+
} 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
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
ok: true,
|
|
203
|
+
value: {
|
|
204
|
+
config: result,
|
|
205
|
+
measuredProjects: measured.value,
|
|
206
|
+
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
|
+
]
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/config/with-perf.ts
|
|
220
|
+
function withPerf(config, perfConfig) {
|
|
221
|
+
const mode = readModeState(process.env);
|
|
222
|
+
if (!mode.ok) throw new ConfigError(mode.issues);
|
|
223
|
+
if (mode.value === null) return config;
|
|
224
|
+
const state = mode.value;
|
|
225
|
+
const resolved = resolveConfig(perfConfig, {
|
|
226
|
+
mode: state.mode,
|
|
227
|
+
...state.repeat === void 0 ? {} : { repeat: state.repeat },
|
|
228
|
+
...state.env === void 0 ? {} : { env: state.env }
|
|
229
|
+
});
|
|
230
|
+
if (!resolved.ok) throw new ConfigError(resolved.issues);
|
|
231
|
+
const { config: perf, snapshot, warnings } = resolved.value;
|
|
232
|
+
const plan = planPerfRun(config, {
|
|
233
|
+
projects: perf.run.projects,
|
|
234
|
+
keepReporters: perf.run.keepReporters,
|
|
235
|
+
repeat: perf.run.repeat[state.mode],
|
|
236
|
+
ci: isCiEnv(process.env),
|
|
237
|
+
reporterPath: reporterEntryPath()
|
|
238
|
+
});
|
|
239
|
+
if (!plan.ok) throw new ConfigError(plan.issues);
|
|
240
|
+
setRegistered({
|
|
241
|
+
config: perf,
|
|
242
|
+
snapshot,
|
|
243
|
+
mode: state,
|
|
244
|
+
packageVersion: version,
|
|
245
|
+
measuredProjects: plan.value.measuredProjects,
|
|
246
|
+
runConditions: plan.value.runConditions,
|
|
247
|
+
warnings: [...warnings, ...plan.value.warnings]
|
|
248
|
+
});
|
|
249
|
+
return plan.value.config;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { withPerf };
|
package/dist/fixture.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkR2NPYGB7_cjs = require('./chunk-R2NPYGB7.cjs');
|
|
4
|
+
require('./chunk-LV3O2BAT.cjs');
|
|
5
|
+
require('./chunk-GCA73FFP.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "trackContext", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkR2NPYGB7_cjs.trackContext; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "withPerfFixtures", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkR2NPYGB7_cjs.withPerfFixtures; }
|
|
16
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TestType, BrowserContext } from '@playwright/test';
|
|
2
|
+
import { P as PerfFixtures } from './perf-api-V4PeHVE0.cjs';
|
|
3
|
+
export { a as PerfApi } from './perf-api-V4PeHVE0.cjs';
|
|
4
|
+
|
|
5
|
+
/** `base` with the `perf` fixture added; other fixtures and options keep their types. */
|
|
6
|
+
type PerfTestType<T> = T extends TestType<infer TestArgs, infer WorkerArgs> ? TestType<TestArgs & PerfFixtures, WorkerArgs> : never;
|
|
7
|
+
/**
|
|
8
|
+
* Adds the collector fixtures to `base` (05, chapter 3). Outside perf mode only the `perf`
|
|
9
|
+
* fixture is added and nothing else changes (05-REQ-01). Wrapping a test object this function
|
|
10
|
+
* returned gives it back unchanged (05-REQ-22). Never imports @playwright/test at runtime: it
|
|
11
|
+
* works with the `base` it gets (01-REQ-15).
|
|
12
|
+
*/
|
|
13
|
+
declare function withPerfFixtures<T extends TestType<any, any>>(base: T): PerfTestType<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a worker-scoped browser context: every test of a measured project tracks it with
|
|
16
|
+
* its own tracker (05-REQ-23). Call it once, right after creating the context. Does nothing
|
|
17
|
+
* outside perf mode.
|
|
18
|
+
*/
|
|
19
|
+
declare function trackContext(context: BrowserContext): void;
|
|
20
|
+
|
|
21
|
+
export { PerfFixtures, trackContext, withPerfFixtures };
|
|
22
|
+
export type { PerfTestType };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TestType, BrowserContext } from '@playwright/test';
|
|
2
|
+
import { P as PerfFixtures } from './perf-api-V4PeHVE0.js';
|
|
3
|
+
export { a as PerfApi } from './perf-api-V4PeHVE0.js';
|
|
4
|
+
|
|
5
|
+
/** `base` with the `perf` fixture added; other fixtures and options keep their types. */
|
|
6
|
+
type PerfTestType<T> = T extends TestType<infer TestArgs, infer WorkerArgs> ? TestType<TestArgs & PerfFixtures, WorkerArgs> : never;
|
|
7
|
+
/**
|
|
8
|
+
* Adds the collector fixtures to `base` (05, chapter 3). Outside perf mode only the `perf`
|
|
9
|
+
* fixture is added and nothing else changes (05-REQ-01). Wrapping a test object this function
|
|
10
|
+
* returned gives it back unchanged (05-REQ-22). Never imports @playwright/test at runtime: it
|
|
11
|
+
* works with the `base` it gets (01-REQ-15).
|
|
12
|
+
*/
|
|
13
|
+
declare function withPerfFixtures<T extends TestType<any, any>>(base: T): PerfTestType<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Registers a worker-scoped browser context: every test of a measured project tracks it with
|
|
16
|
+
* its own tracker (05-REQ-23). Call it once, right after creating the context. Does nothing
|
|
17
|
+
* outside perf mode.
|
|
18
|
+
*/
|
|
19
|
+
declare function trackContext(context: BrowserContext): void;
|
|
20
|
+
|
|
21
|
+
export { PerfFixtures, trackContext, withPerfFixtures };
|
|
22
|
+
export type { PerfTestType };
|
package/dist/fixture.js
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGCA73FFP_cjs = require('./chunk-GCA73FFP.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "definePerfConfig", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkGCA73FFP_cjs.definePerfConfig; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "perfDefaults", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkGCA73FFP_cjs.perfDefaults; }
|
|
14
|
+
});
|