playwright-performance-regression 0.0.0 → 0.1.0-next.1

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 ADDED
@@ -0,0 +1,286 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
6
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0-next.1] - 2026-11-19
11
+
12
+ ### Added
13
+
14
+ - `init` asks first whether to set the package up with a guided tutorial; no (or
15
+ `--no-tutorial`) prints the manual setup steps and changes nothing.
16
+ - `init` speaks English, Spanish, French, Polish, Italian, Ukrainian and Russian: chosen in the
17
+ first step or with `--lang <code>`. Codes, file names and the written files stay English.
18
+ - Colors in the terminal for `init` (step headers, questions, diffs, summary) and the CLI
19
+ messages, run summary and thresholds diff, with `NO_COLOR`, `FORCE_COLOR` and `TERM=dumb`.
20
+
21
+ ### Fixed
22
+
23
+ - The `init` hint and the docs show Playwright's tag option `{ tag: '@perf' }` for tagging tests.
24
+ - `bin` paths in both packages no longer start with `./`, so npm stops warning that it
25
+ corrected them when publishing.
26
+ - README: `yarn create` with a version (such as `@next`) needs Yarn 2 or later.
27
+
28
+ ## [0.1.0-next.0] - 2026-11-19
29
+
30
+ ### Added
31
+
32
+ - Package manifest with the entry points `playwright-performance-regression`, `/config`,
33
+ `/fixture`, `/test`, `/reporter` and the `playwright-performance-regression` and `pw-perf`
34
+ commands.
35
+ - JSON Schemas for the configuration and all file formats, published under `schemas/`.
36
+ - Reading of the sample batch, run report, thresholds and outcome files with `schemaVersion`
37
+ checks, migrations and error codes `SCHEMA_INVALID_JSON`, `SCHEMA_VERSION_MISSING`,
38
+ `SCHEMA_VERSION_TOO_NEW`, `SCHEMA_VERSION_MISMATCH`, `SCHEMA_VALIDATION_FAILED` and
39
+ `THRESHOLDS_KIND_MISMATCH`; a muting `until` date must exist in the calendar.
40
+ - Stable JSON output for every file the package writes: sorted keys, 2-space indent, final
41
+ newline, atomic write.
42
+ - Run report assembly with rounding, fixed array order and raw URLs only with `report.rawUrls`;
43
+ CI metadata for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines.
44
+ - `definePerfConfig()` and `perfDefaults` in the package entry point. `perfDefaults` holds the
45
+ resolved default config (frozen), for extending a default list such as
46
+ `measure.exclude: [...perfDefaults.measure.exclude, 'intercom.io']`.
47
+ - Package config resolution: defaults from the `default` keywords of
48
+ `schemas/config.schema.json`, objects merged and arrays replaced, `RegExp` or
49
+ `{ regex, flags }` URL patterns (compiled without the `g` and `y` flags, so a pattern matches
50
+ the same way on every call), environment overrides of `run.env` and `run.repeat`, and a
51
+ JSON snapshot of the effective config for the run report.
52
+ - Config validation that reports all problems at once, with the option path, the value received,
53
+ the expected format and, for a mistyped option, the closest known name: error codes
54
+ `CONFIG_UNKNOWN_OPTION`, `CONFIG_INVALID_TYPE`, `CONFIG_INVALID_VALUE` and
55
+ `CONFIG_INVALID_REGEX`; warnings `CONFIG_DUPLICATE_ORIGIN_LABEL`,
56
+ `CONFIG_RESOURCE_TYPE_LONG_LIVED` and `CONFIG_PERCENTILE_IS_P99`.
57
+ - Endpoint keys from request URLs: origin labels, id patterns for numbers, UUIDs, hex strings,
58
+ tokens, mixed-case ids and e-mail addresses (`:id`, `:email`), sorted query parameter names
59
+ with optional kept values, deterministic truncation of long keys and a custom `keyBuilder`
60
+ with fallback warnings `NORMALIZE_KEY_BUILDER_INVALID` and `NORMALIZE_KEY_BUILDER_THREW`.
61
+ - Normalization fingerprint of the key rules and warnings `NORMALIZE_HIGH_CARDINALITY` and
62
+ `NORMALIZE_TOO_MANY_KEYS` for key explosion.
63
+ - Statistics per endpoint key and custom measurement: sample, success, error and per-status
64
+ counts (cancelled requests are labeled `ABORTED` and are not errors by default), time sources,
65
+ test counts, samples from failed tests, exact minimum, maximum and average, percentiles p50,
66
+ p90, p95, p99 and the evaluated percentile (linear interpolation, as in spreadsheets and
67
+ NumPy), TTFB, the 3 slowest samples with their start time and the 5 tests with the most
68
+ samples. Above `advanced.maxSamplesPerKey` successful samples a seeded uniform sample is kept;
69
+ the result does not depend on the order of the samples.
70
+ - Only samples of measured projects are aggregated; warnings
71
+ `STATS_SAMPLES_OUTSIDE_MEASURED_PROJECTS`, `STATS_SAMPLES_WITHOUT_BROWSER_TIMING` and
72
+ `STATS_MULTIPLE_BROWSERS`.
73
+ - Apdex and Wilson score interval functions used by the evaluation and thresholds.
74
+ - Evaluation of every endpoint key and custom measurement against the thresholds files: limits
75
+ from the file entry, completed from the config for hand-written entries, or default
76
+ thresholds; rules `median`, `percentile`, `p99`, `apdex` (upper bound of the 95% interval),
77
+ `wilson` and `errors` (lower bound), each with its own minimum sample count; hard limit,
78
+ tolerance in keys or percent, `gate.warnOnly` and `gate.defaultThresholds`; evaluation status
79
+ `passed`, `warned`, `failed` or `error` and per-kind counters. An invalid thresholds file
80
+ stops the evaluation of its kind only and never falls back to default thresholds.
81
+ - Muting of a key in the thresholds file (`gate: "warn"` with `note` and `until`): its
82
+ violations never block until the end date; warnings `THRESHOLDS_MUTED`,
83
+ `THRESHOLDS_MUTE_EXPIRING` (7 days before) and `THRESHOLDS_MUTE_EXPIRED`.
84
+ - Thresholds file warnings `THRESHOLDS_FILE_MISSING` (also naming a file without the
85
+ environment label), `THRESHOLDS_FILE_OUTDATED`, `THRESHOLDS_UNSEEN_ENTRIES`,
86
+ `THRESHOLDS_ENTRIES_NOT_EVALUATED`, `EVAL_PERCENTILE_MISMATCH`, `THRESHOLDS_ENV_MISMATCH`,
87
+ `THRESHOLDS_SOURCE_MISMATCH` (other browser, Playwright minor version, machine or
88
+ normalization) and `EVAL_NO_SAMPLES`.
89
+ - Exit code of a perf-mode run in the outcome file: 3 for tool errors, 2 for blocking
90
+ violations in `test` mode, otherwise 0 (also with warnings and in `thresholds` mode). Failed
91
+ tests are a warning `TESTS_FAILED` up to `gate.maxFailedTestShare` and a tool error
92
+ `TESTS_FAILED_TOO_MANY` above it; a timed-out, interrupted or `maxFailures`-stopped run is
93
+ `RUN_INCOMPLETE`, a sharded run `RUN_SHARDED`.
94
+ - Console summary of a run report: header with mode, environment, tests and CI commit; tool
95
+ errors and up to 10 warnings with hints; counters per kind and muted keys; a table of
96
+ violations (blocking first, by relative exceedance, at most 20 rows, keys shortened in the
97
+ middle to fit the terminal width) with the `over` percentage and `HARD` and `MUTED` flags;
98
+ the slowest sample of the first blocking keys; the result line and the report paths.
99
+ - Derivation of thresholds files from a run report: per key `t`, `median`, the evaluated
100
+ percentile, `p99`, `minApdex`, `maxWilson` and `maxErrorRate` from the margins in
101
+ `checks.*.margin`, `checks.slowShare.t.<kind>` and `thresholds.smallSampleN`, rounded towards
102
+ the looser limit. A derived entry always passes the run it was derived from, and its limits
103
+ keep `median ≤ percentile < p99`. Keys whose median is above `checks.slowShare.t.<kind>.max`
104
+ get no `apdex` and `wilson` limits; keys with fewer successful samples than
105
+ `checks.time.median.minSamples` get no entry.
106
+ - Existing thresholds files are updated, not replaced: `locked` and hand-written partial entries
107
+ stay byte for byte, `note`, `gate` and `until` are kept on every recomputed entry, entries of
108
+ keys not seen in the run stay unless `--prune` is given, and `thresholds.update: "new-only"`
109
+ only adds new keys. An entry whose new limits are within `thresholds.hysteresis` and that
110
+ still passes the source run stays as it is, so a repeated derivation does not rewrite the
111
+ file. A file is written only when its entries, the derivation settings, the environment, the
112
+ evaluated percentile or the run conditions (browsers, machine, normalization, Playwright
113
+ major.minor) changed; its `generated` block describes the source run.
114
+ - Derivation refusals `THRESHOLDS_SOURCE_INCOMPLETE` (interrupted or timed-out run, tool
115
+ errors), `THRESHOLDS_EMPTY_REPORT`, `THRESHOLDS_NOTHING_TO_DERIVE` and an invalid existing
116
+ thresholds file; warnings `THRESHOLDS_KIND_SKIPPED`, `THRESHOLDS_MANUAL_FILE`,
117
+ `THRESHOLDS_SOURCE_TESTS_FAILED`, `THRESHOLDS_SOURCE_TEST_MODE`, `THRESHOLDS_ENV_MISMATCH`,
118
+ `THRESHOLDS_SOURCE_MISMATCH` and `THRESHOLDS_LOOSENED_MUCH` (a time limit grew by more than
119
+ `thresholds.loosenWarnRelative`).
120
+ - Thresholds diff per file: every key as added, removed, loosened, tightened, mixed, unchanged
121
+ (also within hysteresis), locked, unseen or skipped, with the limit values before and after;
122
+ large loosenings are marked `!` and expired mutings are listed on their own line. Console
123
+ output (at most 30 rows per file, keys shortened to the terminal width) and Markdown for
124
+ `thresholds-diff.md` (every change, for a PR description).
125
+ - `withPerf()` and `definePerfConfig()` in `playwright-performance-regression/config`. Outside
126
+ perf mode `withPerf()` returns the Playwright config object as it is and does nothing else. In
127
+ perf mode (`PW_PERF_MODE=test` or `thresholds`, with `PW_PERF_REPEAT`, `PW_PERF_ENV`,
128
+ `PW_PERF_RUN_ID`, `PW_PERF_OUTCOME_FILE` and `PW_PERF_PRUNE`) it resolves the package config
129
+ and returns a copy of the Playwright config with one worker, no retries, `maxFailures` and
130
+ `globalTimeout` 0, trace, video and screenshots off, and `repeatEach` set to the number of
131
+ repetitions for measured projects only (their dependencies and teardowns run once). Measured
132
+ projects follow `run.projects` (`"auto"`: Chromium projects that are not a dependency or
133
+ teardown of another project); other projects are removed from the run. Only the console
134
+ reporters (`list`, `line`, `dot`, `github`), `run.keepReporters` (a kept `html` reporter never
135
+ opens) and the package reporter stay; a console reporter is added when none is left.
136
+ - Errors that stop a perf-mode run before any test: `MODE_INVALID_VALUE` (an invalid `PW_PERF_*`
137
+ value never turns perf mode off silently), `CONFIG_UNKNOWN_PROJECT` and
138
+ `CONFIG_NO_MEASURED_PROJECT`; warnings `CONFIG_MULTIPLE_ENGINES`, `CONFIG_SLOW_MO`,
139
+ `CONFIG_CHANGED_IN_PROCESS` and `NOT_WRAPPED_WITH_PERF`, kept for the reporter.
140
+ - `withPerfFixtures()` and `trackContext()` in `playwright-performance-regression/fixture`, and a
141
+ ready `test` and `expect` in `playwright-performance-regression/test`. Outside perf mode
142
+ `withPerfFixtures()` only adds the `perf` fixture; Playwright's `context` and `page` are not
143
+ overridden. Wrapping a test object again changes nothing.
144
+ - Request measurement in perf mode for the tests of measured projects: every request of the
145
+ `context` fixture, of the `page` fixture's context (also a page built on its own context,
146
+ with the informational diagnostic `COLLECTOR_CONTEXT_AUTO_TRACKED`), of contexts passed to
147
+ `perf.track()` and of worker-scoped contexts registered with `trackContext()`, including
148
+ popups, new tabs, frames and workers. Filters from `measure.*` (scheme, resource type, file
149
+ extension at the end of the path, `include`, `exclude`) and a built-in list of 30 analytics,
150
+ tag manager, monitoring and chat hosts (`measure.excludeKnownThirdParty`). Requests started by
151
+ a service worker are skipped; responses generated by one are flagged `fromServiceWorker`.
152
+ Each redirect step is its own sample.
153
+ - Sample timing from the browser: `duration` from request start to the last byte (including
154
+ queueing, connection setup and a CORS preflight), `requestStart` and `ttfb`, rounded to
155
+ 0.1 ms; the worker clock (`timeSource: "node"`) when the browser gives no end time.
156
+ - End of test: requests in flight are awaited once per test, before Playwright closes the
157
+ context, for at most `measure.pendingTimeoutMs` and never past the teardown time limit (the
158
+ test timeout minus 1 s for other teardowns). Requests still running after that become
159
+ `PENDING` samples; a response whose body was never read keeps its HTTP status without a
160
+ duration. Requests of a page or context closed by the test fail at once with the text
161
+ `pw-perf: context closed`, without waiting.
162
+ - Every test of a measured project gets the attachment `playwright-performance-regression-samples`
163
+ (also an empty one); projects that are not measured, such as a login setup project, are not
164
+ measured. At most 20 000 request samples per test (`COLLECTOR_SAMPLE_LIMIT_REACHED`).
165
+ Collector errors never change a test result: they become the diagnostics
166
+ `COLLECTOR_LISTENER_ERROR` and `COLLECTOR_TIMING_FAILED`, or `COLLECTOR_ATTACH_FAILED` on
167
+ stderr.
168
+ - Custom measurements with the `perf` fixture: `perf.measure(name, fn)`, `perf.start(name)` and
169
+ `perf.end(name)` (returns the duration in ms, also outside perf mode), the aliases
170
+ `sampleStart`/`sampleEnd`, outcomes `ok`, `error` and `unfinished`, name validation
171
+ (`TypeError` with `CUSTOM_INVALID_NAME`) and the diagnostics `CUSTOM_ALREADY_STARTED`,
172
+ `CUSTOM_END_WITHOUT_START` and `CUSTOM_UNFINISHED`.
173
+ - The package reporter (`playwright-performance-regression/reporter`), added by `withPerf()` in
174
+ perf mode. It aggregates the sample attachments of the measured projects, evaluates them
175
+ against the thresholds files of the run's environment label
176
+ (`<thresholds.dir>/<thresholds.filePrefix>.<kind>[.<env>].json`, never the file without the
177
+ label), writes
178
+ `<report.dir>/report.json`, prints the summary (colors only in a terminal without
179
+ `NO_COLOR`, tables fitted to the terminal width) and writes the outcome file to
180
+ `PW_PERF_OUTCOME_FILE`. In `thresholds` mode it also writes the changed thresholds files and
181
+ `<report.dir>/thresholds-diff.md` and prints the diff after the summary; nothing is written
182
+ for an incomplete or untrustworthy run, and `PW_PERF_PRUNE=1` removes entries not seen in the
183
+ run. Playwright's status becomes `failed` when the exit code of the run is not 0. At the start
184
+ of the run it prints the settings perf mode changed and the number of test executions. A run
185
+ that starts no test (`--list`, a filter that selects nothing) writes and prints nothing.
186
+ - HTML report `<report.dir>/report.html` next to `report.json` (unless `report.html` is
187
+ `false`): one self-contained file without network requests, readable without JavaScript, with
188
+ the verdict, counters, muted keys, warnings, endpoint and custom measurement tables (violations
189
+ first, details per key with checks, a percentile bar, statuses, slowest samples and top tests),
190
+ thresholds files, run conditions and the config snapshot. JavaScript adds sorting, filters and
191
+ a download of the embedded data (aggregates without raw samples). Light and dark theme, print
192
+ styles and a Content-Security-Policy without inline exceptions. Tool errors
193
+ `HTML_RENDER_FAILED` and `HTML_WRITE_FAILED` keep `report.json` and end with exit code 3.
194
+ - Reporter warnings `RUN_CONDITIONS_CHANGED` (other workers, retries or repetitions than perf
195
+ mode sets, retried results or trace and video attachments set in test files),
196
+ `TESTS_NOT_INSTRUMENTED`, `ATTACHMENT_DUPLICATE`, `COLLECTOR_REQUESTS_PENDING` (with the keys
197
+ that have the most pending requests), `CONFIG_DUPLICATE_ORIGIN_LABEL` for `use.baseURL` of
198
+ measured projects, `NOT_WRAPPED_WITH_PERF` and `THRESHOLDS_DIFF_WRITE_FAILED`; tool errors
199
+ `RUN_SHARDED`, `REPORT_WRITE_FAILED`, `THRESHOLDS_WRITE_FAILED` and
200
+ `REPORTER_INTERNAL_ERROR`; `OUTCOME_WRITE_FAILED` on stderr. A sample attachment that cannot
201
+ be read is skipped with a tool error.
202
+ - The `pw-perf` command (also `playwright-performance-regression`): `pw-perf test` and
203
+ `pw-perf thresholds` run `playwright test` in perf mode. Own options `--env`, `--repeat` and
204
+ (thresholds) `--prune` are read anywhere before `--`; every other argument goes to Playwright
205
+ unchanged, and `--config`/`-c` belongs to Playwright. `--repeat` and `--env` are checked like
206
+ `PW_PERF_REPEAT` and `PW_PERF_ENV`. Playwright is found in the project (from the directory of
207
+ `-c` when given, so a monorepo can run `pw-perf test -c apps/web/playwright.config.ts` from its
208
+ root) and started with Node, without a shell. With `--reporter` the package reporter is added to
209
+ the last `--reporter` value. The CLI sets the `PW_PERF_*` variables, prints the mode line and a
210
+ tip to measure a subset, forwards SIGINT and SIGTERM to Playwright (a second Ctrl+C within 5 s
211
+ stops it at once) and ends with the exit code of the outcome file: 0, 2 or 3, 130 or 143 after a
212
+ signal, Playwright's own code with `--list`. Without an outcome file the result is 3 with
213
+ `CLI_OUTCOME_MISSING` and its usual causes (no `withPerf()`, a config error, no matching test).
214
+ After the run it prints one result line and the report path.
215
+ - CLI errors `CLI_UNKNOWN_COMMAND`, `CLI_INVALID_OPTION`, `CLI_MISSING_ARGUMENT`,
216
+ `CLI_UNSUPPORTED_PLAYWRIGHT_OPTION` (`--ui`, `--ui-host`, `--ui-port`, `--debug`, `--shard`),
217
+ `CLI_PRUNE_WITH_FILTER` (`--prune` with `--grep`, `--grep-invert`, `--project`,
218
+ `--last-failed`, `--only-changed`, `--test-list` or file paths), `CLI_FROM_WITH_PLAYWRIGHT_ARGS`,
219
+ `CLI_PLAYWRIGHT_NOT_FOUND`, `CLI_REPORTER_PATH_UNSUPPORTED`, `CLI_SPAWN_FAILED`,
220
+ `CLI_OUTCOME_INVALID`, `CLI_REPORT_NOT_FOUND`, `CLI_WRITE_FAILED` and `CLI_INTERNAL_ERROR`;
221
+ warnings `CLI_MODE_ALREADY_SET` and `CLI_PLAYWRIGHT_UNSUPPORTED_VERSION`.
222
+ - `pw-perf thresholds --from <report.json>` derives the thresholds files from a run report without
223
+ running tests, with the same functions as a thresholds run (identical files), and writes
224
+ `thresholds-diff.md`. The environment label is `--env` or the label of the report;
225
+ `CLI_REPORT_TESTS_FAILED` warns about a report with failed tests. It needs no Playwright.
226
+ - Package config in the commands without tests: `--config <file>`, else `pw-perf.config.*`
227
+ (`.ts`, `.mts`, `.js`, `.mjs`, `.cjs`, `.json`) in the current directory or in the config
228
+ directory of the report, else the config snapshot of the report. TypeScript files are loaded by
229
+ Node itself; a file that cannot be loaded gives `CONFIG_FILE_LOAD_FAILED` with a fix hint for
230
+ imports without extension, `tsconfig` path aliases and enums (an error with `--config`, a
231
+ warning and the snapshot otherwise), and Node's type-stripping warnings become one `note:` line.
232
+ `CONFIG_FILE_NOT_FOUND` for a missing `--config` file, `CONFIG_SNAPSHOT_DIFFERS` when the file
233
+ differs from the snapshot in options that change the result. The CLI prints the config source
234
+ and the base directory of relative paths (`CLI_CONFIG_DIR_MISSING` when it falls back to the
235
+ current directory).
236
+ - `pw-perf report [--input] [--output] [--config]` renders the HTML report again from a run
237
+ report (`CLI_REPORT_NOT_FOUND` when it is missing), also with `report.html: false`; the page is
238
+ identical to the one written by the run. It needs no Playwright. `HTML_RENDER_FAILED` and
239
+ `CLI_WRITE_FAILED` end it with exit code 3. `--help` (also per command, with the
240
+ note on repeated tests and data conflicts) and `--version`.
241
+ - `pw-perf init [--yes] [--dry-run]`: guided setup in eleven steps, each with a short explanation.
242
+ It reads the project as text (playwright.config is never imported), asks for the label of the
243
+ `baseURL` origin, which tests to measure (all or `@perf`, with `INIT_NO_TAGGED_TESTS` when no
244
+ test has the tag), the repetitions, a warn-only start, environments and a CI job, and shows a
245
+ diff of every change before it asks to apply it: a new `pw-perf.config.ts` with only the values
246
+ that differ from the defaults, `withPerf()` around `export default defineConfig({...})`,
247
+ `export default {...}` or `module.exports = ...`, `withPerfFixtures()` around
248
+ `export const test = base.extend(...)` (or `exports.test = ...`), or imports of `test` from
249
+ `@playwright/test` switched to `playwright-performance-regression/test`, `perf-results/` in
250
+ `.gitignore`, `perf:test` and `perf:thresholds` scripts (with `--grep @perf` and one pair per
251
+ environment with `--env`), and a CI job file from `examples/ci/` for GitHub Actions, GitLab CI,
252
+ Jenkins or Azure Pipelines. Other layouts (config wrappers, several test objects, `mergeTests`)
253
+ and existing scripts or CI files are left as they are, with an `INIT_MANUAL_STEP` instruction.
254
+ A second run changes nothing; an existing `pw-perf.config.ts` is replaced only after its own
255
+ confirmation (never with `--yes`). Without a terminal and without `--yes` it only shows the
256
+ plan. Exit codes: 0 done, 3 `INIT_NO_PLAYWRIGHT_CONFIG`, `INIT_PLAYWRIGHT_TOO_OLD` or
257
+ `INIT_WRITE_FAILED`, 130 interrupted (nothing is written before the changes step).
258
+ - `create-playwright-performance-regression` for `npm init playwright-performance-regression`
259
+ (also `pnpm create` and `yarn create`): installs the package of the same version as a dev
260
+ dependency with the package manager of the project's lockfile, without a shell, then runs
261
+ `pw-perf init` with the given arguments.
262
+ - CI recipes in `examples/ci/` (`github-actions.yml`, `gitlab-ci.yml`, `Jenkinsfile`,
263
+ `azure-pipelines.yml`): pull request and nightly triggers, the report uploaded always, exit
264
+ code 2 as a soft failure on GitLab, Jenkins and Azure Pipelines, and a time limit.
265
+ - User documentation: a README with installation, quick start, CI, limitations, privacy and
266
+ compatibility, and `docs/` with configuration (generated from
267
+ `schemas/config.schema.json`), CLI, adoption in existing projects, thresholds, CI,
268
+ troubleshooting for every warning and error code, FAQ, and upgrading.
269
+ - Example projects `examples/basic` and `examples/with-setup`, runnable against the demo app of
270
+ the repository.
271
+ - Both packages are published from GitHub Actions with npm provenance (trusted publishing), in
272
+ the same version, with pre-releases under the `next` dist-tag; a demo HTML report with a
273
+ blocking violation is published on GitHub Pages.
274
+
275
+ ### Changed
276
+
277
+ - `schemas/samples.schema.json`: field descriptions now say that `duration` is `null` also for
278
+ a response that never finished, that `requestStart` and `ttfb` never include a CORS preflight,
279
+ and that `failureText` can be the collector's context-closed text. The structure is unchanged.
280
+ - File validation messages describe the expected format of an environment label or percentile
281
+ name (e.g. `a percentile name like "p95"`) instead of printing the regular expression.
282
+ - Smaller package: the entry points share code chunks instead of each bundling its own copy
283
+ (about 820 kB unpacked instead of 1.3 MB). Every entry point keeps its ESM and CommonJS build.
284
+ - The descriptions in the published `schemas/*.json` use the real names
285
+ (`pw-perf.config.json`, `PW_PERF_ENV`, `PW_PERF_REPEAT`, `PW_PERF_OUTCOME_FILE`, the
286
+ `playwright-performance-regression-samples` attachment) instead of placeholders.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jakub Kaczmarczyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,217 @@
1
1
  # playwright-performance-regression
2
2
 
3
- Placeholder; the first release follows.
3
+ Catch backend performance regressions from the Playwright tests you already have.
4
4
 
5
- See https://github.com/Meser6/playwright-performance-regression
5
+ > **Pre-release.** `0.1.0-next.N` versions are published under the `next` tag: install with
6
+ > `npm init playwright-performance-regression@next` or
7
+ > `npm install --save-dev playwright-performance-regression@next`. Until `0.1.0`, the API, file
8
+ > formats and CLI may still change.
9
+
10
+ ![HTML report of a measurement run](.github/assets/report.png)
11
+
12
+ ## How it works
13
+
14
+ 1. **Measures** the backend requests your browser makes while your existing e2e tests run, in a
15
+ separate measurement run (`pw-perf test`), with every test repeated a few times.
16
+ 2. **Groups** the requests into endpoint keys such as `GET /api/orders/:id`, and computes
17
+ statistics per key: median, p95, p99, error rate and more.
18
+ 3. **Derives thresholds** from a run and writes them to JSON files that you review and commit like
19
+ code.
20
+ 4. **Fails the run** when an endpoint gets slower or returns more errors than its thresholds
21
+ allow, with a console summary and a self-contained HTML report.
22
+
23
+ Your normal `npx playwright test` runs are not changed.
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ npm init playwright-performance-regression
29
+ ```
30
+
31
+ This installs the package as a dev dependency and starts a short guided setup (`pw-perf init`). It
32
+ shows a diff of every change before writing anything: it wraps your Playwright config, wraps your
33
+ `test` object or switches test imports, creates `pw-perf.config.ts`, adds `perf:test` and
34
+ `perf:thresholds` scripts, ignores `perf-results/`, and can add a CI job. `pnpm create` and
35
+ `yarn create` work too (Yarn 2 or later; Yarn 1 cannot install a specific version such as
36
+ `@next` with `yarn create`); `-- --yes` accepts the defaults without questions. The guided
37
+ setup speaks English, Spanish, French, Polish, Italian, Ukrainian and Russian (`--lang <code>`).
38
+
39
+ <details>
40
+ <summary>Manual setup</summary>
41
+
42
+ ```sh
43
+ npm install -D playwright-performance-regression
44
+ ```
45
+
46
+ Wrap the Playwright config:
47
+
48
+ ```ts
49
+ // playwright.config.ts
50
+ import { defineConfig } from '@playwright/test';
51
+ import { withPerf } from 'playwright-performance-regression/config';
52
+
53
+ export default withPerf(defineConfig({/* your config, unchanged */}));
54
+ ```
55
+
56
+ Then either wrap your own test object:
57
+
58
+ ```ts
59
+ // fixtures.ts
60
+ import { test as base } from '@playwright/test';
61
+ import { withPerfFixtures } from 'playwright-performance-regression/fixture';
62
+
63
+ export const test = withPerfFixtures(base.extend({/* your fixtures */}));
64
+ export { expect } from '@playwright/test';
65
+ ```
66
+
67
+ or, if your tests import `test` straight from `@playwright/test`, switch that import:
68
+
69
+ ```ts
70
+ import { test, expect } from 'playwright-performance-regression/test';
71
+ ```
72
+
73
+ Optionally add `pw-perf.config.ts` and pass it as the second argument of `withPerf()`; see
74
+ [Configuration](docs/configuration.md).
75
+
76
+ </details>
77
+
78
+ Projects with their own fixtures, several test objects, `mergeTests`, playwright-bdd, config
79
+ wrappers or custom reporters: see [Adopting the package in an existing project](docs/adoption.md).
80
+
81
+ ## Quick start
82
+
83
+ ```sh
84
+ npm run perf:thresholds # measure and write the thresholds files
85
+ git add perf-thresholds.*.json && git commit -m "test: add performance thresholds"
86
+ npm run perf:test # measure again and compare with the thresholds
87
+ ```
88
+
89
+ Without the scripts: `npx pw-perf thresholds --grep @perf` and `npx pw-perf test --grep @perf`.
90
+
91
+ Derive thresholds on the same machines that run the check, usually your CI runners, and bring them
92
+ to your repository with `pw-perf thresholds --from <report.json>`. Thresholds measured on a laptop
93
+ do not fit CI. See [Thresholds](docs/thresholds.md).
94
+
95
+ The result is printed in the terminal and written to `perf-results/report.json` and
96
+ `perf-results/report.html`.
97
+
98
+ ## Custom measurements
99
+
100
+ Time a user-visible step that spans several requests, or anything else in the test:
101
+
102
+ ```ts
103
+ test('checkout', async ({ page, perf }) => {
104
+ await page.goto('/cart');
105
+ await perf.measure('checkout:load-cart', async () => {
106
+ await page.getByRole('button', { name: 'Checkout' }).click();
107
+ await page.getByText('Order summary').waitFor();
108
+ });
109
+ });
110
+ ```
111
+
112
+ `perf.start(name)` and `perf.end(name)` do the same without a callback. Custom measurements get
113
+ their own thresholds file and checks. Coming from `playwright-performance`? `perf.sampleStart()`
114
+ and `perf.sampleEnd()` are aliases of `start()` and `end()`.
115
+
116
+ ## CI
117
+
118
+ A GitHub Actions job that measures pull requests and runs every night:
119
+
120
+ ```yaml
121
+ name: Performance
122
+ on:
123
+ pull_request:
124
+ schedule:
125
+ - cron: '0 3 * * *'
126
+ jobs:
127
+ perf:
128
+ runs-on: ubuntu-latest
129
+ timeout-minutes: 60
130
+ steps:
131
+ - uses: actions/checkout@v7
132
+ - uses: actions/setup-node@v7
133
+ with:
134
+ node-version: 22
135
+ cache: npm
136
+ - run: npm ci
137
+ - run: npx playwright install --with-deps chromium
138
+ # A tagged subset on pull requests, the full measured suite at night.
139
+ - run: npx pw-perf test ${{ github.event_name == 'pull_request' && '--grep @perf' || '' }}
140
+ - uses: actions/upload-artifact@v7
141
+ if: always() # the report matters most when the run fails
142
+ with:
143
+ name: perf-results
144
+ path: perf-results/
145
+ ```
146
+
147
+ Exit codes: **0** no blocking regression, **2** performance regression, **3** tool or config error
148
+ (the measurement itself is not trustworthy). Recipes for GitLab CI, Jenkins and Azure Pipelines,
149
+ with code 2 as a soft failure where the platform supports it: [CI](docs/ci.md).
150
+
151
+ ## Limitations
152
+
153
+ - REST only: every GraphQL query goes to the same endpoint key.
154
+ - Only requests made by the browser are measured. Tests that use only the `request` fixture, and
155
+ calls through `page.request` or `context.request`, record nothing.
156
+ - Only Chromium projects are measured by default. Firefox and WebKit are best effort.
157
+ - The measurement run is separate from your normal run, uses one worker and repeats every test,
158
+ so it is slow: measure a subset (`--grep @perf`, `--project`).
159
+ - Repeated tests that create data can collide with each other; make the data unique.
160
+ - In manual mode (`PW_PERF_MODE=test npx playwright test`), a `--reporter` flag replaces the
161
+ package reporter and nothing is reported. Use `pw-perf test`.
162
+
163
+ ## Privacy
164
+
165
+ No telemetry. The package never makes network requests.
166
+
167
+ What ends up where:
168
+
169
+ - **Thresholds files and `report.json` / `report.html`** contain normalized endpoint keys: numbers,
170
+ UUIDs, long hex strings, tokens, mixed-case ids and e-mail addresses in the path are replaced
171
+ with `:id` or `:email`, and query values are dropped (only parameter names stay). Path segments
172
+ that match none of these patterns, such as user names, stay in the key; add patterns with
173
+ `keys.extraIdPatterns`. The report also contains test titles, file names, the operating system, CPU model
174
+ and CI metadata (commit, branch, build URL).
175
+ - **Raw URLs** go into the report only when you set `report.rawUrls: true`.
176
+ - **Playwright's own report** gets one attachment per test with the full URLs of the measured
177
+ requests.
178
+
179
+ **Before you share a report** outside your team, check the keys for personal data and remember
180
+ that Playwright's HTML report and traces contain the full URLs.
181
+
182
+ ## Compatibility
183
+
184
+ | | Supported |
185
+ | ----------------- | ----------------------------------------------------------------------------- |
186
+ | Node.js | 22.18 or newer (22, 24, 26) |
187
+ | Playwright Test | 1.57 or newer (`@playwright/test` is a peer dependency) |
188
+ | Operating systems | Linux, macOS, Windows |
189
+ | Browsers | Chromium (including Chrome and Edge channels); Firefox and WebKit best effort |
190
+ | Module formats | ESM and CommonJS configs; TypeScript configs loaded by Playwright |
191
+
192
+ ## Documentation
193
+
194
+ - [Configuration](docs/configuration.md): every option with its default
195
+ - [CLI](docs/cli.md): commands, options and exit codes
196
+ - [Adoption](docs/adoption.md): existing projects, choosing tests, sample counts
197
+ - [Thresholds](docs/thresholds.md): deriving, reviewing, locking and muting
198
+ - [CI](docs/ci.md): recipes for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines
199
+ - [Troubleshooting](docs/troubleshooting.md): every warning and error code
200
+ - [FAQ](docs/faq.md) · [Upgrading and uninstalling](docs/upgrading.md)
201
+ - [Examples](examples): a basic project and one with setup projects and own fixtures
202
+
203
+ ## Security
204
+
205
+ Please report vulnerabilities privately through
206
+ [GitHub private vulnerability reporting](https://github.com/Meser6/playwright-performance-regression/security/advisories/new),
207
+ not in public issues.
208
+
209
+ ## Contributing
210
+
211
+ Issues and pull requests are welcome. The project uses pnpm, Conventional Commits and squash
212
+ merges; `pnpm lint`, `pnpm typecheck` and `pnpm test` (after `pnpm build`) must pass. Releases
213
+ follow [RELEASING.md](RELEASING.md).
214
+
215
+ ## License
216
+
217
+ [MIT](LICENSE)