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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +431 -0
  2. package/README.md +96 -64
  3. package/dist/{chunk-L5C63HEF.js → chunk-CISGJCFW.js} +378 -48
  4. package/dist/chunk-CXE5IWZY.js +1648 -0
  5. package/dist/{chunk-B64P2D5A.js → chunk-E2IX265O.js} +395 -206
  6. package/dist/chunk-IUI4AFE5.cjs +658 -0
  7. package/dist/{chunk-WZVQK7CQ.cjs → chunk-KELMALEG.cjs} +408 -218
  8. package/dist/{chunk-GCA73FFP.cjs → chunk-LUA4WRIQ.cjs} +382 -47
  9. package/dist/chunk-RL27E3AB.js +595 -0
  10. package/dist/{chunk-DYLCGMI2.js → chunk-S6UH6QPK.js} +6 -1
  11. package/dist/cli.js +2761 -2339
  12. package/dist/config.cjs +122 -137
  13. package/dist/config.d.cts +3 -2
  14. package/dist/config.d.ts +3 -2
  15. package/dist/config.js +117 -132
  16. package/dist/fixture.cjs +9 -5
  17. package/dist/fixture.d.cts +10 -4
  18. package/dist/fixture.d.ts +10 -4
  19. package/dist/fixture.js +4 -4
  20. package/dist/index.cjs +3 -3
  21. package/dist/index.d.cts +121 -25
  22. package/dist/index.d.ts +121 -25
  23. package/dist/index.js +1 -1
  24. package/dist/perf-api-2DH_keLh.d.cts +17 -0
  25. package/dist/perf-api-2DH_keLh.d.ts +17 -0
  26. package/dist/reporter.cjs +5713 -1237
  27. package/dist/reporter.js +6905 -693
  28. package/dist/test.cjs +4 -4
  29. package/dist/test.js +4 -4
  30. package/package.json +19 -1
  31. package/schemas/common.schema.json +2 -2
  32. package/schemas/config.schema.json +72 -26
  33. package/schemas/outcome.schema.json +2 -2
  34. package/schemas/run-report.schema.json +549 -20
  35. package/schemas/samples.schema.json +48 -37
  36. package/schemas/thresholds.schema.json +1 -1
  37. package/dist/chunk-3CLCMD2Q.js +0 -3411
  38. package/dist/chunk-4SFI55HF.cjs +0 -319
  39. package/dist/chunk-HBGADXLP.js +0 -254
  40. package/dist/perf-api-V4PeHVE0.d.cts +0 -22
  41. package/dist/perf-api-V4PeHVE0.d.ts +0 -22
package/README.md CHANGED
@@ -11,8 +11,10 @@ Catch backend performance regressions from the Playwright tests you already have
11
11
 
12
12
  ## How it works
13
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.
14
+ 1. **Measures** the backend requests your browser makes (and the `request` calls of API tests)
15
+ while your existing e2e tests run, in a separate measurement run
16
+ (`PW_PERF_MODE=test npm run e2e`): your test command runs a few times in a row (passes), and
17
+ all passes are evaluated together.
16
18
  2. **Groups** the requests into endpoint keys such as `GET /api/orders/:id`, and computes
17
19
  statistics per key: median, p95, p99, error rate and more.
18
20
  3. **Derives thresholds** from a run and writes them to JSON files that you review and commit like
@@ -25,16 +27,25 @@ Your normal `npx playwright test` runs are not changed.
25
27
  ## Install
26
28
 
27
29
  ```sh
28
- npm init playwright-performance-regression
30
+ npm init playwright-performance-regression@next
29
31
  ```
30
32
 
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>`).
33
+ This installs the package as a dev dependency and starts a short guided setup (after `0.1.0`:
34
+ `npm init playwright-performance-regression`; run it again at any time; in a project with the
35
+ package installed, `npx pw-perf` starts it too). It asks which tests to measure, the passes, what
36
+ to measure (endpoints, `test.step` blocks or both), the threshold headroom and your usual test
37
+ command, then shows a diff of every change before writing it: it creates `pw-perf.config.ts`
38
+ (`pw-perf.config.js` in a JavaScript project) with the most important options, wraps your
39
+ Playwright config and your fixtures module, ignores `reports/pw-perf/` and can add the CI jobs.
40
+ Without a fixtures module, it switches the `@playwright/test` imports of your test files to
41
+ `playwright-performance-regression/test`, one confirmed diff per file; when it cannot change the
42
+ test object, it shows the code to paste. `package.json` is never changed. At the end it offers a
43
+ check: your test command runs with `PW_PERF_MODE=thresholds`, then `PW_PERF_MODE=test`, both with
44
+ 2 passes, and the check's thresholds files are deleted afterwards. `pnpm create` and `yarn create`
45
+ work too (Yarn 2 or later; Yarn 1 cannot install a specific version such as `@next` with
46
+ `yarn create`). The guided setup speaks English, Spanish, French, Polish, Italian, Ukrainian and
47
+ Russian (it asks at the start). It takes no arguments; `PW_PERF_LANG`, `PW_PERF_DRY_RUN` and
48
+ `PW_PERF_NO_TUTORIAL` change it ([Guided setup](docs/cli.md#guided-setup)).
38
49
 
39
50
  <details>
40
51
  <summary>Manual setup</summary>
@@ -71,7 +82,8 @@ import { test, expect } from 'playwright-performance-regression/test';
71
82
  ```
72
83
 
73
84
  Optionally add `pw-perf.config.ts` and pass it as the second argument of `withPerf()`; see
74
- [Configuration](docs/configuration.md).
85
+ [Configuration](docs/configuration.md). Remove `--reporter` from the command you measure with:
86
+ it replaces the package reporter, so a measurement run stops with `RUN_REPORTER_FLAG`.
75
87
 
76
88
  </details>
77
89
 
@@ -80,85 +92,103 @@ wrappers or custom reporters: see [Adopting the package in an existing project](
80
92
 
81
93
  ## Quick start
82
94
 
95
+ Run your usual test command with `PW_PERF_MODE` in front of it. `npm run e2e` stands for your own
96
+ script, or `npx playwright test`:
97
+
83
98
  ```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
99
+ PW_PERF_MODE=check npm run e2e # dry run: what is measured and how long a run takes
100
+ PW_PERF_MODE=thresholds npm run e2e # measure and write the thresholds files
101
+ git add pw-perf-thresholds*.json && git commit -m "test: add performance thresholds"
102
+ PW_PERF_MODE=test npm run e2e # measure again and compare with the thresholds
87
103
  ```
88
104
 
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).
105
+ On Windows: `npx cross-env PW_PERF_MODE=test npm run e2e` (PowerShell and cmd forms in
106
+ [docs/cli.md](docs/cli.md)). Without the variable the tests run as before, with no measuring.
94
107
 
95
- The result is printed in the terminal and written to `perf-results/report.json` and
96
- `perf-results/report.html`.
108
+ The exit code is Playwright's own; the cause of a failure (a regression, failed tests, a config
109
+ error) is in `reports/pw-perf/outcome.json`. The result is also printed in the terminal and written
110
+ to `reports/pw-perf/report.json` and `reports/pw-perf/report.html` (tabs Overview, Endpoints,
111
+ Steps, Tests and Run & config). Every `test` and `thresholds` run empties `reports/pw-perf/` first,
112
+ so it holds only the last run. All variables are described in [Running](docs/cli.md).
97
113
 
98
- ## Custom measurements
114
+ Derive thresholds on the same machines that run the check, usually your CI runners (see
115
+ [CI](#ci) below); thresholds measured on a laptop do not fit CI. How much headroom they get is one
116
+ setting, `thresholds: { preset: 'strict' | 'normal' | 'loose' }`. See
117
+ [Thresholds](docs/thresholds.md).
99
118
 
100
- Time a user-visible step that spans several requests, or anything else in the test:
119
+ ## Step timings
101
120
 
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
- ```
121
+ Your existing `test.step` blocks are measured too, without changing the tests (on by default;
122
+ `measure: { steps: false }` in `pw-perf.config.ts` turns it off, `measure: { api: false }` measures
123
+ only the steps).
111
124
 
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()`.
125
+ A step `submit` inside a step `login` becomes the key `login › submit`, with its own statistics,
126
+ checks and thresholds file `pw-perf-thresholds.steps.json`. Step titles are sanitized: ids,
127
+ e-mails, URLs and secrets never reach the keys or the reports, also inside quotes; numbers in
128
+ words become `:num` (`Transfer 1500 PLN` → `Transfer :num PLN`). See [Step timings](docs/steps.md).
115
129
 
116
130
  ## CI
117
131
 
118
- A GitHub Actions job that measures pull requests and runs every night:
132
+ The recommended path: (1) a CI job you start by hand runs with `PW_PERF_MODE=thresholds` and keeps
133
+ the thresholds files as an artifact, (2) you commit them, (3) a weekly job runs with
134
+ `PW_PERF_MODE=test` and fails on a regression. In GitHub Actions, shortened:
119
135
 
120
136
  ```yaml
121
137
  name: Performance
122
138
  on:
123
- pull_request:
124
139
  schedule:
125
- - cron: '0 3 * * *'
140
+ - cron: '0 3 * * 1'
141
+ workflow_dispatch:
142
+ inputs:
143
+ mode: { type: choice, options: [test, thresholds], default: test }
126
144
  jobs:
127
- perf:
145
+ thresholds:
146
+ if: inputs.mode == 'thresholds'
147
+ runs-on: ubuntu-latest
148
+ env: { PW_PERF_MODE: thresholds }
149
+ steps:
150
+ - uses: actions/checkout@v7
151
+ - run: npm ci && npx playwright install --with-deps chromium
152
+ - run: npm run e2e
153
+ - uses: actions/upload-artifact@v7
154
+ if: always()
155
+ with: { name: pw-perf-thresholds, path: pw-perf-thresholds*.json }
156
+ measure:
157
+ if: github.event_name == 'schedule' || inputs.mode == 'test'
128
158
  runs-on: ubuntu-latest
129
- timeout-minutes: 60
159
+ env: { PW_PERF_MODE: test }
130
160
  steps:
131
161
  - 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' || '' }}
162
+ - run: npm ci && npx playwright install --with-deps chromium
163
+ - run: npm run e2e
140
164
  - uses: actions/upload-artifact@v7
141
165
  if: always() # the report matters most when the run fails
142
- with:
143
- name: perf-results
144
- path: perf-results/
166
+ with: { name: pw-perf-report, path: reports/pw-perf/ }
145
167
  ```
146
168
 
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).
169
+ Not ready to block builds yet? Set `continue-on-error: true` on the measure job. The full recipes
170
+ for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines read the exact exit code (**0** ok,
171
+ **2** performance regression, **3** tool or config error) from `reports/pw-perf/outcome.json`:
172
+ [CI](docs/ci.md).
150
173
 
151
174
  ## Limitations
152
175
 
153
176
  - 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`.
177
+ - Requests made by the browser and calls of Playwright's `request` fixture, `page.request` and
178
+ `context.request` are measured (keys such as `request GET /api/orders/:id`, separate from the
179
+ browser's); other HTTP clients (Node `fetch`, axios) are not. API tests are measured only when
180
+ they import `test` from the wrapped test object, and contexts from `request.newContext()` only
181
+ after `trackRequestContext(context)` ([Adoption](docs/adoption.md)).
182
+ - The projects your test command selects are measured (all without `--project`), except setup and
183
+ teardown projects. Chromium is supported; Firefox and WebKit are best effort, so select one engine
184
+ with `--project`.
185
+ - The measurement run is separate from your normal run, uses one worker and runs your test command
186
+ several times (passes), so it is slow: measure a subset (`run: { grep: '@perf' }`, `--project`).
187
+ - The test command, with its setup steps, runs once per pass; tests that create data without such
188
+ a step can collide in the next pass; make the data unique.
189
+ - A `--reporter` flag in the test command replaces the package reporter, so nothing is reported
190
+ (a test or thresholds run stops with `RUN_REPORTER_FLAG`); keep reporters in
191
+ `playwright.config` instead.
162
192
 
163
193
  ## Privacy
164
194
 
@@ -167,7 +197,7 @@ No telemetry. The package never makes network requests.
167
197
  What ends up where:
168
198
 
169
199
  - **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
200
+ UUIDs, long hex strings, tokens, mixed-case ids, prefixed ids (`ORD-1000`, `inv_58`) and e-mail addresses in the path are replaced
171
201
  with `:id` or `:email`, and query values are dropped (only parameter names stay). Path segments
172
202
  that match none of these patterns, such as user names, stay in the key; add patterns with
173
203
  `keys.extraIdPatterns`. The report also contains test titles, file names, the operating system, CPU model
@@ -192,9 +222,11 @@ that Playwright's HTML report and traces contain the full URLs.
192
222
  ## Documentation
193
223
 
194
224
  - [Configuration](docs/configuration.md): every option with its default
195
- - [CLI](docs/cli.md): commands, options and exit codes
225
+ - [Running](docs/cli.md): variables, the guided setup and exit codes
196
226
  - [Adoption](docs/adoption.md): existing projects, choosing tests, sample counts
197
227
  - [Thresholds](docs/thresholds.md): deriving, reviewing, locking and muting
228
+ - [Step timings](docs/steps.md): measuring `test.step` blocks, keys and title sanitization
229
+ - [Dynamic environments](docs/dynamic-environments.md): npm scripts with setup steps, random CI hosts and host patterns
198
230
  - [CI](docs/ci.md): recipes for GitHub Actions, GitLab CI, Jenkins and Azure Pipelines
199
231
  - [Troubleshooting](docs/troubleshooting.md): every warning and error code
200
232
  - [FAQ](docs/faq.md) · [Upgrading and uninstalling](docs/upgrading.md)