playwright-performance-regression 0.1.0-next.0 → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +199 -0
- package/README.md +73 -52
- package/dist/{chunk-GCA73FFP.cjs → chunk-2JO5HVPC.cjs} +351 -44
- package/dist/{chunk-R2NPYGB7.cjs → chunk-44ASXVQN.cjs} +96 -198
- package/dist/{chunk-HES6BVZT.js → chunk-AQ2XKYNV.js} +349 -47
- package/dist/chunk-BAOTUUTV.cjs +611 -0
- package/dist/chunk-DX36GFOZ.js +558 -0
- package/dist/chunk-LTRHMBVY.js +5592 -0
- package/dist/{chunk-UTTU4FUC.js → chunk-MUZFQKGQ.js} +82 -184
- package/dist/cli.js +3500 -1157
- package/dist/config.cjs +91 -44
- package/dist/config.d.cts +4 -2
- package/dist/config.d.ts +4 -2
- package/dist/config.js +84 -37
- package/dist/fixture.cjs +5 -5
- package/dist/fixture.d.cts +2 -2
- package/dist/fixture.d.ts +2 -2
- package/dist/fixture.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +110 -22
- package/dist/index.d.ts +110 -22
- package/dist/index.js +1 -1
- package/dist/perf-api-Rm1h1O_-.d.cts +12 -0
- package/dist/perf-api-Rm1h1O_-.d.ts +12 -0
- package/dist/reporter.cjs +5204 -1209
- package/dist/reporter.js +2035 -254
- package/dist/test.cjs +4 -4
- package/dist/test.js +3 -3
- package/package.json +5 -3
- package/schemas/common.schema.json +2 -2
- package/schemas/config.schema.json +57 -21
- package/schemas/outcome.schema.json +1 -1
- package/schemas/run-report.schema.json +534 -19
- package/schemas/samples.schema.json +4 -39
- package/schemas/thresholds.schema.json +1 -1
- package/dist/chunk-6AB42SPF.js +0 -254
- package/dist/chunk-JEHUFIY3.js +0 -3390
- package/dist/chunk-LV3O2BAT.cjs +0 -319
- package/dist/perf-api-V4PeHVE0.d.cts +0 -22
- package/dist/perf-api-V4PeHVE0.d.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,205 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.0-next.3] - 2026-11-21
|
|
11
|
+
|
|
12
|
+
`0.1.0-next.2` was tagged but not published (the release stopped on the performance tests).
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `thresholds.preset`: `strict`, `normal` (default, the previous margins) or `loose` sets the
|
|
17
|
+
headroom of every derived threshold; fields in `checks.*.margin` still win.
|
|
18
|
+
- `run.grep`: only tests whose title or tags match run in perf mode (e.g. `'@perf'`), applied to
|
|
19
|
+
the measured projects only, so setup projects run in full.
|
|
20
|
+
- `pw-perf.config.ts` written by `init` starts with a "Most important settings" block.
|
|
21
|
+
|
|
22
|
+
- Passes: a run now runs your test command several times in a row (`run.passes`: 5 for `test`,
|
|
23
|
+
10 for `thresholds`; `PW_PERF_PASSES` or `--passes` for one run) instead of repeating each test
|
|
24
|
+
inside one Playwright run. Setup steps of the script (seeding data) run before every pass. Each
|
|
25
|
+
pass writes `pw-perf-results/pass-<k>.json` and the first pass evaluates all of them together:
|
|
26
|
+
one report (with `passes` in `report.json` and a "Passes" tile) and one result. A pass without
|
|
27
|
+
data gives `RUN_PASS_FAILED`; an interrupted pass `RUN_PASS_INTERRUPTED`. See `docs/cli.md`.
|
|
28
|
+
- A start banner with the mode, projects, tests × passes, a time estimate and the report path; in
|
|
29
|
+
a terminal outside CI it asks `Continue? (Y/n)` (`PW_PERF_YES=1` skips it).
|
|
30
|
+
|
|
31
|
+
- `check`: a dry run before the first measurement (`PW_PERF_MODE=check npm run e2e`, or
|
|
32
|
+
`npx pw-perf check`). It runs the first test of each file once (at most `--max-tests`,
|
|
33
|
+
`PW_PERF_MAX_TESTS`, default 10) and shows the projects, origins with their labels, top keys,
|
|
34
|
+
the thresholds files and an estimate of the full runs; it evaluates nothing and writes no files.
|
|
35
|
+
`CHECK_RANDOM_HOST` proposes host patterns for generated CI hosts.
|
|
36
|
+
|
|
37
|
+
- Host patterns in `keys.origins`: `'https://*.ci.example.com': ''` labels random hosts of CI
|
|
38
|
+
instances; `*` matches inside one host label, an exact entry wins, more literal characters win
|
|
39
|
+
between patterns. `baseURL` origins covered by `keys.origins` no longer change the
|
|
40
|
+
normalization fingerprint, so random `baseURL` hosts stop giving `THRESHOLDS_SOURCE_MISMATCH`.
|
|
41
|
+
Thresholds files derived before with an exact entry for the `baseURL` origin give
|
|
42
|
+
`THRESHOLDS_SOURCE_MISMATCH` once. See `docs/dynamic-environments.md`.
|
|
43
|
+
|
|
44
|
+
- After every run the last line is a `Next:` hint with the exact command of your project: derive
|
|
45
|
+
thresholds (`PW_PERF_MODE=thresholds npm run e2e`), commit the written files, or run the check
|
|
46
|
+
when nothing was measured. The command follows how the run was started (npm, pnpm or yarn
|
|
47
|
+
script, plain `npx playwright test`, or `npx pw-perf`).
|
|
48
|
+
- Warnings `RUN_PROJECT_NO_REQUESTS` (a measured project with only API tests) and
|
|
49
|
+
`CONFIG_BASEURL_EMPTY` (an empty `use.baseURL` or one built from an unset variable).
|
|
50
|
+
|
|
51
|
+
- Environment mode as the recommended way to run: `PW_PERF_MODE=test npm run e2e` (or `thresholds`)
|
|
52
|
+
runs your own test command in perf mode. The reporter writes the exact result to
|
|
53
|
+
`pw-perf-results/outcome.json` (exit code 0, 2 or 3; the old file is removed when the run starts)
|
|
54
|
+
and prints an `Outcome:` line; Playwright keeps its own exit code. `withPerf()` gives the workers
|
|
55
|
+
the run id and warns about `--reporter` (`RUN_REPORTER_FLAG`) and `--ui`/`--debug`
|
|
56
|
+
(`RUN_UNSUPPORTED_FLAG`); `PW_PERF_PRUNE=1` with a test filter writes the files without pruning
|
|
57
|
+
(`RUN_PRUNE_SKIPPED`). See the new section of `docs/cli.md`.
|
|
58
|
+
|
|
59
|
+
- Step timings: with `measure: { steps: true }` the durations of the existing `test.step` blocks
|
|
60
|
+
become keys of kind `step` (for example `login › submit`), checked and derived like endpoints,
|
|
61
|
+
with their own thresholds file `pw-perf-thresholds.steps.json`, a `Steps:` line in the console
|
|
62
|
+
and a Steps tab in the HTML report. Step titles are sanitized: ids, e-mails, URLs and secrets
|
|
63
|
+
never reach the keys or the reports, also inside quotes. Options `categories`, `maxDepth`,
|
|
64
|
+
`include`, `exclude`, `groupBy`, `normalizeTitles` and `redactQuotedValues`; warnings
|
|
65
|
+
`STEPS_NONE_FOUND`, `STEPS_HIGH_CARDINALITY`, `STEPS_TOO_MANY_KEYS` and
|
|
66
|
+
`STEPS_SECRET_REDACTED`. `init` asks about it when the project has `test.step` calls. See
|
|
67
|
+
`docs/steps.md`.
|
|
68
|
+
|
|
69
|
+
- The run report (`report.json`) holds more data for the HTML report: a
|
|
70
|
+
histogram of the retained durations per key, the median time outside TTFB
|
|
71
|
+
(`ttfb.otherP50`), the part of each limit a check uses (`usage`), up to three rule-based hints
|
|
72
|
+
per key, and `testBreakdown`: the backend cost of the 500 most expensive tests and a request
|
|
73
|
+
waterfall of the 5 slowest test runs.
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
|
|
77
|
+
- The HTML report has a new look: an app bar with the run details, a verdict card with the three
|
|
78
|
+
results (performance, tests, tool errors) and the exit code, a KPI strip, sticky tabs, violation
|
|
79
|
+
cards with the first hint, rankings with bars and an Endpoints/Steps switch, endpoints shown with
|
|
80
|
+
a colored method badge and highlighted path parameters, and failures in a clear red (light and
|
|
81
|
+
dark theme). Key details open in a centered dialog (`Esc`, Close or a click outside closes it;
|
|
82
|
+
full screen on phones). The details show p50, the evaluated percentile, p99 and max at a glance, the histogram bars above the limit in red and a headroom
|
|
83
|
+
meter for every check. Times in the key tables are whole milliseconds without a unit (the table
|
|
84
|
+
footer says “All times in ms”). Error rates in the checks are shown as percentages.
|
|
85
|
+
- The run summary and the `check` output are easier to scan: errors, warnings and the verdict
|
|
86
|
+
are in framed boxes, the counters and the violations in tables with lines, and statuses carry
|
|
87
|
+
emoji (✅ ⚠ ❌). Long warning messages wrap inside the box. `NO_COLOR` turns off only the
|
|
88
|
+
colors; `TERM=dumb` also turns frames into ASCII and emoji into `✔ ! ✖`.
|
|
89
|
+
- The `TESTS_FAILED` warning now says that the samples of failed tests are counted.
|
|
90
|
+
- `pw-perf init` is rebuilt around your own test command: it detects the scripts that run
|
|
91
|
+
`playwright test` and shows `Run: PW_PERF_MODE=test npm run <script>`, warns about flags that
|
|
92
|
+
break a measurement run (`INIT_SCRIPT_FLAG`) and later steps of the script
|
|
93
|
+
(`INIT_SCRIPT_LATER_STEPS`), asks which projects to measure, writes `@perf` as `run.grep`,
|
|
94
|
+
asks for the headroom preset, no longer asks about a trial period or environments, and ends
|
|
95
|
+
with a check. Steps 1 and 2 are one step with a short description of the package.
|
|
96
|
+
- When the wizard cannot wrap your fixtures module it changes no test file and shows a red box
|
|
97
|
+
with the code to paste (`INIT_TEST_OBJECT_MANUAL`). Without `playwright.config` it stops before
|
|
98
|
+
the first question.
|
|
99
|
+
- The CI recipes in `examples/ci/` (and the files `init` writes) have two jobs: a thresholds job
|
|
100
|
+
you start by hand that keeps the thresholds files as an artifact, and a weekly measurement job;
|
|
101
|
+
both set `PW_PERF_MODE` and run your test command, and read the exit code from
|
|
102
|
+
`pw-perf-results/outcome.json`.
|
|
103
|
+
- `npx pw-perf` without arguments prints the help instead of an error, with a box pointing to
|
|
104
|
+
`npx pw-perf init` in a project without config.
|
|
105
|
+
|
|
106
|
+
- **Breaking:** `run.repeat`, `PW_PERF_REPEAT` and `--repeat` are renamed to `run.passes`,
|
|
107
|
+
`PW_PERF_PASSES` and `--passes`; the old names are errors with a hint. Every project runs with
|
|
108
|
+
`repeatEach: 1`.
|
|
109
|
+
- Perf mode no longer forces `retries: 0`: the retries of your Playwright config apply, every
|
|
110
|
+
attempt is measured and a test that passes on a retry counts as passed. Retries no longer give
|
|
111
|
+
`RUN_CONDITIONS_CHANGED`.
|
|
112
|
+
- `pw-perf test` and `thresholds` print no mode line before the run; the start banner replaces it.
|
|
113
|
+
- `npx pw-perf --help` starts with the recommended form (`PW_PERF_MODE=test npm run e2e`, also
|
|
114
|
+
`thresholds` and `check`, with the Windows line) and presents the commands as the advanced
|
|
115
|
+
runner; it lists `--max-tests`. The README quick start uses the same form and says where the
|
|
116
|
+
result is (`pw-perf-results/outcome.json`).
|
|
117
|
+
- The HTML report size limit for 500 keys, 500 tests and 5 waterfalls is 10 MB (was 5 MB).
|
|
118
|
+
- The HTML report is redesigned: a verdict banner and key figures on top, tabs (Overview,
|
|
119
|
+
Endpoints, Tests, Warnings, Run & config), the details of a key with
|
|
120
|
+
links to it (`#key=api:<key>`, `#tab=tests`), search and filter chips, rankings (slowest, most
|
|
121
|
+
called, highest error rate, closest to the limit), a histogram per key, the split of TTFB and
|
|
122
|
+
the rest of the time, hints that explain a violation, the headroom to every limit, the backend
|
|
123
|
+
cost of each test and a waterfall of the 5 slowest test runs. It still is one offline file that
|
|
124
|
+
works without JavaScript, prints and adapts to the dark theme and small screens.
|
|
125
|
+
- `report.json` files written by `0.1.0-next.1` or earlier are migrated when read (`thresholds
|
|
126
|
+
--from`, `report`); the new fields are empty in them.
|
|
127
|
+
- Breaking: new format versions. The sample attachment is version 2 (without `custom`), the
|
|
128
|
+
thresholds file version 2 (`kind` is `api`) and `report.json` version 3 (without `custom` and
|
|
129
|
+
`evaluation.counts.custom`). Thresholds files of version 1 and run reports of versions 1 and 2
|
|
130
|
+
are migrated when read; the package writes the new versions. A thresholds file of kind
|
|
131
|
+
`custom` is rejected with `SCHEMA_VALIDATION_FAILED`.
|
|
132
|
+
|
|
133
|
+
- Breaking: the endpoint thresholds file has no kind in its name: `pw-perf-thresholds.json`
|
|
134
|
+
(`pw-perf-thresholds.<env>.json` with an environment label), was `pw-perf-thresholds.api.json`.
|
|
135
|
+
Rename the file with `git mv pw-perf-thresholds.api.json pw-perf-thresholds.json`; the old name
|
|
136
|
+
is not read. The environment labels `steps` and `requests` are reserved.
|
|
137
|
+
- Breaking: every file and directory the package creates now starts with `pw-perf`. The default
|
|
138
|
+
thresholds files are `pw-perf-thresholds.<kind>[.<env>].json` (`thresholds.filePrefix`, was
|
|
139
|
+
`perf-thresholds`) and the default output directory is `pw-perf-results/` (`report.dir`, was
|
|
140
|
+
`perf-results`); the files inside keep their names. The samples attachment of each test is
|
|
141
|
+
`pw-perf-samples` (was `playwright-performance-regression-samples`). Old names are not read: rename existing
|
|
142
|
+
thresholds files and the `.gitignore` entry, or set the old values in the config.
|
|
143
|
+
- `init` no longer asks for the label of the `baseURL` origin: labels are automatic (no label for
|
|
144
|
+
the `baseURL` origin, the host for other hosts), and the summary points to `keys.origins` for
|
|
145
|
+
shorter labels. The steps are numbered 1 to 10.
|
|
146
|
+
- `init` measures all tests by default, also when some tests are tagged `@perf` and with `--yes`.
|
|
147
|
+
`INIT_NO_TAGGED_TESTS` is now information shown in the wizard, not a warning.
|
|
148
|
+
- The `pw-perf.config.ts` written by `init` lists every option: the answers that differ from the
|
|
149
|
+
defaults as code, all other options as comments with their default value and a one-line
|
|
150
|
+
description, grouped by section. The comments are generated from the config schema.
|
|
151
|
+
- Measurement runs replace the `list` reporter with `dot` and add `dot` (also locally) when no
|
|
152
|
+
console reporter is left, so hundreds of executions no longer flood the terminal. Keep `list`
|
|
153
|
+
with `--reporter=list` or `run.keepReporters: ['list']`. The info line at the start says
|
|
154
|
+
`reporter list replaced with dot`.
|
|
155
|
+
- The run summary is easier to spot and read: a separator line and a bold header, bold section
|
|
156
|
+
headings, red error codes, yellow warning codes, dim hints, red blocking and yellow
|
|
157
|
+
non-blocking rows, and the verdict as a colored badge (`✔ PASSED`, `! PASSED WITH WARNINGS`,
|
|
158
|
+
`✖ FAILED`, `✖ ERROR`). Without colors the text keeps the same words and markers.
|
|
159
|
+
- The summary ends with one `Report:` line with the absolute path of `report.html` (or
|
|
160
|
+
`report.json` without HTML), and the thresholds diff with an absolute `Diff:` path; the CLI no
|
|
161
|
+
longer prints the `report:` and `thresholds diff:` lines after them.
|
|
162
|
+
- The counters line omits zero counts and says what it counts, e.g. `19 keys · 19 from file ·
|
|
163
|
+
8 checked by median only (few samples) · 2 file entries not seen`.
|
|
164
|
+
- `THRESHOLDS_FILE_MISSING` is reported only for a kind that has keys in the run.
|
|
165
|
+
|
|
166
|
+
### Removed
|
|
167
|
+
|
|
168
|
+
- **Breaking:** `gate.warnOnly` (the trial mode). The option is now `CONFIG_UNKNOWN_OPTION` with a
|
|
169
|
+
hint; to keep a CI job green on a regression, set `continue-on-error` on the job, or use
|
|
170
|
+
`gate.tolerance` / `gate.defaultThresholds: 'warn'`.
|
|
171
|
+
- **Breaking:** `pw-perf init` no longer writes `perf:*` scripts to `package.json` and no longer
|
|
172
|
+
changes test files (no import swap). Scripts written by an earlier wizard keep working.
|
|
173
|
+
- Breaking: custom measurements. `perf.measure()`, `perf.start()`, `perf.end()`,
|
|
174
|
+
`perf.sampleStart()` and `perf.sampleEnd()` are removed; the `perf` fixture keeps only
|
|
175
|
+
`perf.track(context)`, so old calls no longer type-check and throw a `TypeError` in JavaScript.
|
|
176
|
+
The kind `custom` is gone with its thresholds file `pw-perf-thresholds.custom[.<env>].json`
|
|
177
|
+
(no longer read or written; delete it by hand), the options `checks.*.*.limit.custom`,
|
|
178
|
+
`checks.errors.limit.custom` and `checks.slowShare.t.custom` (now `CONFIG_UNKNOWN_OPTION` with
|
|
179
|
+
a hint), the `CUSTOM_*` warnings, the `Custom:` line of the summary, the Custom tab of the HTML
|
|
180
|
+
report and the migration notes for `playwright-performance`. Time user-visible steps with
|
|
181
|
+
`test.step()` and `measure.steps: true` instead. See
|
|
182
|
+
[Upgrading](docs/upgrading.md#from-010-next1-to-010-next3-custom-measurements-removed).
|
|
183
|
+
|
|
184
|
+
### Fixed
|
|
185
|
+
|
|
186
|
+
- A run with too many failed tests (`TESTS_FAILED_TOO_MANY`) or another run problem no longer
|
|
187
|
+
reports "1 tool error" and "performance failed": the verdict names the cause (`too many failed
|
|
188
|
+
tests (30 of 101 executions); the performance result is not trustworthy`) and the CLI says
|
|
189
|
+
`performance result not trustworthy`. The exit code stays 3.
|
|
190
|
+
|
|
191
|
+
## [0.1.0-next.1] - 2026-11-19
|
|
192
|
+
|
|
193
|
+
### Added
|
|
194
|
+
|
|
195
|
+
- `init` asks first whether to set the package up with a guided tutorial; no (or
|
|
196
|
+
`--no-tutorial`) prints the manual setup steps and changes nothing.
|
|
197
|
+
- `init` speaks English, Spanish, French, Polish, Italian, Ukrainian and Russian: chosen in the
|
|
198
|
+
first step or with `--lang <code>`. Codes, file names and the written files stay English.
|
|
199
|
+
- Colors in the terminal for `init` (step headers, questions, diffs, summary) and the CLI
|
|
200
|
+
messages, run summary and thresholds diff, with `NO_COLOR`, `FORCE_COLOR` and `TERM=dumb`.
|
|
201
|
+
|
|
202
|
+
### Fixed
|
|
203
|
+
|
|
204
|
+
- The `init` hint and the docs show Playwright's tag option `{ tag: '@perf' }` for tagging tests.
|
|
205
|
+
- `bin` paths in both packages no longer start with `./`, so npm stops warning that it
|
|
206
|
+
corrected them when publishing.
|
|
207
|
+
- README: `yarn create` with a version (such as `@next`) needs Yarn 2 or later.
|
|
208
|
+
|
|
10
209
|
## [0.1.0-next.0] - 2026-11-19
|
|
11
210
|
|
|
12
211
|
### Added
|
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ Catch backend performance regressions from the Playwright tests you already have
|
|
|
12
12
|
## How it works
|
|
13
13
|
|
|
14
14
|
1. **Measures** the backend requests your browser makes while your existing e2e tests run, in a
|
|
15
|
-
separate measurement run (`
|
|
15
|
+
separate measurement run (`PW_PERF_MODE=test npm run e2e`): your test command runs a few times
|
|
16
|
+
in a row (passes), and all passes are evaluated together.
|
|
16
17
|
2. **Groups** the requests into endpoint keys such as `GET /api/orders/:id`, and computes
|
|
17
18
|
statistics per key: median, p95, p99, error rate and more.
|
|
18
19
|
3. **Derives thresholds** from a run and writes them to JSON files that you review and commit like
|
|
@@ -25,14 +26,18 @@ Your normal `npx playwright test` runs are not changed.
|
|
|
25
26
|
## Install
|
|
26
27
|
|
|
27
28
|
```sh
|
|
28
|
-
npm init playwright-performance-regression
|
|
29
|
+
npm init playwright-performance-regression@next
|
|
29
30
|
```
|
|
30
31
|
|
|
31
|
-
This installs the package as a dev dependency and starts a short guided setup (`pw-perf init
|
|
32
|
-
shows a diff of every change
|
|
33
|
-
|
|
34
|
-
`perf
|
|
35
|
-
|
|
32
|
+
This installs the package as a dev dependency and starts a short guided setup (`pw-perf init`;
|
|
33
|
+
after `0.1.0`: `npm init playwright-performance-regression`). It shows a diff of every change
|
|
34
|
+
before writing anything: it wraps your Playwright config and your fixtures module, creates
|
|
35
|
+
`pw-perf.config.ts`, ignores `pw-perf-results/` and can add the CI jobs. It never changes your test
|
|
36
|
+
files or `package.json`: when it cannot wrap your `test` object, it shows the code to paste. At the
|
|
37
|
+
end it runs a short check of what will be measured. `pnpm create` and
|
|
38
|
+
`yarn create` work too (Yarn 2 or later; Yarn 1 cannot install a specific version such as
|
|
39
|
+
`@next` with `yarn create`); `-- --yes` accepts the defaults without questions. The guided
|
|
40
|
+
setup speaks English, Spanish, French, Polish, Italian, Ukrainian and Russian (`--lang <code>`).
|
|
36
41
|
|
|
37
42
|
<details>
|
|
38
43
|
<summary>Manual setup</summary>
|
|
@@ -78,73 +83,86 @@ wrappers or custom reporters: see [Adopting the package in an existing project](
|
|
|
78
83
|
|
|
79
84
|
## Quick start
|
|
80
85
|
|
|
86
|
+
Run your usual test command with `PW_PERF_MODE` in front of it. `npm run e2e` stands for your own
|
|
87
|
+
script, or `npx playwright test`:
|
|
88
|
+
|
|
81
89
|
```sh
|
|
82
|
-
npm run
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
PW_PERF_MODE=check npm run e2e # dry run: what is measured and how long a run takes
|
|
91
|
+
PW_PERF_MODE=thresholds npm run e2e # measure and write the thresholds files
|
|
92
|
+
git add pw-perf-thresholds*.json && git commit -m "test: add performance thresholds"
|
|
93
|
+
PW_PERF_MODE=test npm run e2e # measure again and compare with the thresholds
|
|
85
94
|
```
|
|
86
95
|
|
|
87
|
-
|
|
96
|
+
On Windows: `npx cross-env PW_PERF_MODE=test npm run e2e` (PowerShell and cmd forms in
|
|
97
|
+
[docs/cli.md](docs/cli.md)). Without the variable the tests run as before, with no measuring.
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
The exit code is Playwright's own; the cause of a failure (a regression, failed tests, a config
|
|
100
|
+
error) is in `pw-perf-results/outcome.json`. The result is also printed in the terminal and written
|
|
101
|
+
to `pw-perf-results/report.json` and `pw-perf-results/report.html`. A runner with its own exit
|
|
102
|
+
codes is described in [Advanced: the pw-perf runner](docs/cli.md#advanced-the-pw-perf-runner).
|
|
92
103
|
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
Derive thresholds on the same machines that run the check, usually your CI runners (see
|
|
105
|
+
[CI](#ci) below); thresholds measured on a laptop do not fit CI. How much headroom they get is one
|
|
106
|
+
setting, `thresholds: { preset: 'strict' | 'normal' | 'loose' }`. See
|
|
107
|
+
[Thresholds](docs/thresholds.md).
|
|
95
108
|
|
|
96
|
-
##
|
|
109
|
+
## Step timings
|
|
97
110
|
|
|
98
|
-
|
|
111
|
+
Your existing `test.step` blocks can be measured too, without changing the tests:
|
|
99
112
|
|
|
100
113
|
```ts
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await perf.measure('checkout:load-cart', async () => {
|
|
104
|
-
await page.getByRole('button', { name: 'Checkout' }).click();
|
|
105
|
-
await page.getByText('Order summary').waitFor();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
114
|
+
// pw-perf.config.ts
|
|
115
|
+
export default definePerfConfig({ measure: { steps: true } });
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
`
|
|
111
|
-
|
|
112
|
-
and
|
|
118
|
+
A step `submit` inside a step `login` becomes the key `login › submit`, with its own statistics,
|
|
119
|
+
checks and thresholds file `pw-perf-thresholds.steps.json`. Step titles are sanitized: ids,
|
|
120
|
+
e-mails, URLs and secrets never reach the keys or the reports, also inside quotes. See
|
|
121
|
+
[Step timings](docs/steps.md).
|
|
113
122
|
|
|
114
123
|
## CI
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
The recommended path: (1) a CI job you start by hand runs with `PW_PERF_MODE=thresholds` and keeps
|
|
126
|
+
the thresholds files as an artifact, (2) you commit them, (3) a weekly job runs with
|
|
127
|
+
`PW_PERF_MODE=test` and fails on a regression. In GitHub Actions, shortened:
|
|
117
128
|
|
|
118
129
|
```yaml
|
|
119
130
|
name: Performance
|
|
120
131
|
on:
|
|
121
|
-
pull_request:
|
|
122
132
|
schedule:
|
|
123
|
-
- cron: '0 3 * *
|
|
133
|
+
- cron: '0 3 * * 1'
|
|
134
|
+
workflow_dispatch:
|
|
135
|
+
inputs:
|
|
136
|
+
mode: { type: choice, options: [test, thresholds], default: test }
|
|
124
137
|
jobs:
|
|
125
|
-
|
|
138
|
+
thresholds:
|
|
139
|
+
if: inputs.mode == 'thresholds'
|
|
140
|
+
runs-on: ubuntu-latest
|
|
141
|
+
env: { PW_PERF_MODE: thresholds }
|
|
142
|
+
steps:
|
|
143
|
+
- uses: actions/checkout@v7
|
|
144
|
+
- run: npm ci && npx playwright install --with-deps chromium
|
|
145
|
+
- run: npm run e2e
|
|
146
|
+
- uses: actions/upload-artifact@v7
|
|
147
|
+
if: always()
|
|
148
|
+
with: { name: pw-perf-thresholds, path: pw-perf-thresholds*.json }
|
|
149
|
+
measure:
|
|
150
|
+
if: github.event_name == 'schedule' || inputs.mode == 'test'
|
|
126
151
|
runs-on: ubuntu-latest
|
|
127
|
-
|
|
152
|
+
env: { PW_PERF_MODE: test }
|
|
128
153
|
steps:
|
|
129
154
|
- uses: actions/checkout@v7
|
|
130
|
-
-
|
|
131
|
-
|
|
132
|
-
node-version: 22
|
|
133
|
-
cache: npm
|
|
134
|
-
- run: npm ci
|
|
135
|
-
- run: npx playwright install --with-deps chromium
|
|
136
|
-
# A tagged subset on pull requests, the full measured suite at night.
|
|
137
|
-
- run: npx pw-perf test ${{ github.event_name == 'pull_request' && '--grep @perf' || '' }}
|
|
155
|
+
- run: npm ci && npx playwright install --with-deps chromium
|
|
156
|
+
- run: npm run e2e
|
|
138
157
|
- uses: actions/upload-artifact@v7
|
|
139
158
|
if: always() # the report matters most when the run fails
|
|
140
|
-
with:
|
|
141
|
-
name: perf-results
|
|
142
|
-
path: perf-results/
|
|
159
|
+
with: { name: pw-perf-results, path: pw-perf-results/ }
|
|
143
160
|
```
|
|
144
161
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
162
|
+
Not ready to block builds yet? Set `continue-on-error: true` on the measure job. The full recipes
|
|
163
|
+
for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines read the exact exit code (**0** ok,
|
|
164
|
+
**2** performance regression, **3** tool or config error) from `pw-perf-results/outcome.json`:
|
|
165
|
+
[CI](docs/ci.md).
|
|
148
166
|
|
|
149
167
|
## Limitations
|
|
150
168
|
|
|
@@ -152,11 +170,12 @@ with code 2 as a soft failure where the platform supports it: [CI](docs/ci.md).
|
|
|
152
170
|
- Only requests made by the browser are measured. Tests that use only the `request` fixture, and
|
|
153
171
|
calls through `page.request` or `context.request`, record nothing.
|
|
154
172
|
- Only Chromium projects are measured by default. Firefox and WebKit are best effort.
|
|
155
|
-
- The measurement run is separate from your normal run, uses one worker and
|
|
156
|
-
so it is slow: measure a subset (
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
|
|
173
|
+
- The measurement run is separate from your normal run, uses one worker and runs your test command
|
|
174
|
+
several times (passes), so it is slow: measure a subset (`run: { grep: '@perf' }`, `--project`).
|
|
175
|
+
- The test command, with its setup steps, runs once per pass; tests that create data without such
|
|
176
|
+
a step can collide in the next pass; make the data unique.
|
|
177
|
+
- A `--reporter` flag in the test command replaces the package reporter, so nothing is reported
|
|
178
|
+
(the run warns with `RUN_REPORTER_FLAG`); keep reporters in `playwright.config` instead.
|
|
160
179
|
|
|
161
180
|
## Privacy
|
|
162
181
|
|
|
@@ -193,6 +212,8 @@ that Playwright's HTML report and traces contain the full URLs.
|
|
|
193
212
|
- [CLI](docs/cli.md): commands, options and exit codes
|
|
194
213
|
- [Adoption](docs/adoption.md): existing projects, choosing tests, sample counts
|
|
195
214
|
- [Thresholds](docs/thresholds.md): deriving, reviewing, locking and muting
|
|
215
|
+
- [Step timings](docs/steps.md): measuring `test.step` blocks, keys and title sanitization
|
|
216
|
+
- [Dynamic environments](docs/dynamic-environments.md): npm scripts with setup steps, random CI hosts and host patterns
|
|
196
217
|
- [CI](docs/ci.md): recipes for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines
|
|
197
218
|
- [Troubleshooting](docs/troubleshooting.md): every warning and error code
|
|
198
219
|
- [FAQ](docs/faq.md) · [Upgrading and uninstalling](docs/upgrading.md)
|