playwright-performance-regression 0.1.0-next.4 → 1.0.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 CHANGED
@@ -7,6 +7,144 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.0] - 2026-11-23
11
+
12
+ The first stable release, published under the `latest` dist-tag: install with
13
+ `npm init playwright-performance-regression`. From now on the project follows semantic versioning
14
+ strictly (breaking changes only in a new major version). Upgrading from `0.1.0-next.4`: see
15
+ [Upgrading](docs/upgrading.md#from-010-nextx-to-100); in short, prune the thresholds entries of
16
+ the newly skipped realtime transports and keep or copy your CI jobs yourself.
17
+
18
+ ### Breaking
19
+
20
+ - **More realtime transports skipped by default.** The default `measure.exclude` is now
21
+ `['/socket.io/', '/sockjs/', '/sockjs-node/', '/signalr/', '/_blazor/']`: besides socket.io it
22
+ skips the HTTP requests of SockJS (also Meteor and the webpack-dev-server 3 reload client),
23
+ classic ASP.NET SignalR and Blazor Server. These are handshakes, long polling and streams, not
24
+ backend endpoints, and gave long or `PENDING` samples. Keys under these paths no longer appear
25
+ in the report; their entries in a thresholds file stay and are reported as not seen
26
+ (`THRESHOLDS_UNSEEN_ENTRIES`). Other keys and the normalization fingerprint do not change, so
27
+ thresholds files stay valid. Migration: run a thresholds run of the full suite with
28
+ `PW_PERF_PRUNE=1` to remove the old entries. A config file that sets `measure.exclude` (an
29
+ earlier guided setup wrote it) keeps its own list: add the new patterns there or use
30
+ `[...perfDefaults.measure.exclude, ...]`. The guided setup now writes the longer default list.
31
+ - **The guided setup adds no CI jobs.** The CI step is gone (steps are now `[n/9]`) and the wizard
32
+ no longer writes `.github/workflows/perf.yml`, `.gitlab/perf.gitlab-ci.yml`, `Jenkinsfile.perf`
33
+ or `azure-pipelines.perf.yml`; it still adds no scripts. Your test command is only used in the
34
+ commands printed at the end and for the check, and the step says so. Migration: CI files written
35
+ by an earlier wizard are left as they are and keep working; copy the recipes from
36
+ `examples/ci/` and [CI](docs/ci.md) for new projects or to pick up the changes below (thresholds
37
+ artifact of `reports/pw-perf/` only, `junit.xml`).
38
+
39
+ ### Added
40
+
41
+ - **Warning and table for keys on default thresholds.** When a thresholds file has entries but
42
+ some endpoints or steps of a measurement run (`PW_PERF_MODE=test`) have none, the run warns
43
+ with the new `THRESHOLDS_KEYS_ON_DEFAULTS` (one per kind, with the number of keys and up to
44
+ three of them) and the console prints a table of those keys under the counters: samples,
45
+ median, the evaluated percentile, the default limits applied and the result, keys with a
46
+ violation first, at most 10 rows and a "… and N more" line. The warning also appears in
47
+ `report.json`, the HTML report and `junit.xml`; its hint suggests a thresholds run to add the
48
+ entries. Not in thresholds mode, and not for a missing or empty file (`THRESHOLDS_FILE_MISSING`
49
+ and `THRESHOLDS_FILE_EMPTY` cover those). It does not change the evaluation or the exit code.
50
+ - **Thresholds files in the report folder.** A thresholds run (`PW_PERF_MODE=thresholds`) writes
51
+ the thresholds files as before and also copies them, byte for byte and under the same names
52
+ (with the environment label), into `report.dir` (`reports/pw-perf/pw-perf-thresholds.json`,
53
+ `reports/pw-perf/pw-perf-thresholds.steps.json`): every file of the measured kinds, also when
54
+ this run left it unchanged, so one CI artifact of `reports/pw-perf/` holds everything to commit
55
+ next to `thresholds-diff.md`. No copies when writing a thresholds file failed or in the check of
56
+ the guided setup. A failed copy is the warning `THRESHOLDS_COPY_FAILED` and does not change the
57
+ exit code. The copies directly in `report.dir` no longer stop it from being emptied at the start
58
+ of the next run. The CI recipes in `examples/ci/` now upload only `reports/pw-perf/` in the
59
+ thresholds job (Azure: the `pw-perf-report` artifact in both modes).
60
+ - **JUnit XML report.** A measurement run (`PW_PERF_MODE=test`) writes `reports/pw-perf/junit.xml`
61
+ next to `report.json`, so GitLab, Jenkins and Azure DevOps show the result in their test views:
62
+ one test case per endpoint and step key, a failure only for a blocking violation (exit code 2),
63
+ muted and not evaluated keys as skipped, tool errors as an error of the `measurement run` test
64
+ case. Not written in thresholds mode or by a check. Turn it off with `report.junit: false`; a
65
+ failed write is the tool error `REPORT_JUNIT_WRITE_FAILED` (exit code 3).
66
+ - **JUnit in the CI recipes.** The recipes in `examples/ci/` publish `junit.xml` without changing
67
+ the job status: GitLab `artifacts: reports: junit`, Jenkins `junit` (empty results allowed,
68
+ build not marked unstable by it), Azure `PublishTestResults@2` in mode `test` only, and an
69
+ optional, commented-out test report step for GitHub Actions. `docs/ci.md` explains where the
70
+ result shows up and how to read it.
71
+
72
+ ### Changed
73
+
74
+ - **Tables in the thresholds diff and the start box.** The changes of a thresholds run are
75
+ listed in a table with lines (marker, key, change), like the tables of the run summary, and the
76
+ skipped keys in a second table with their reason; the start box of a perf-mode run is a table
77
+ with the mode in its top edge, labels on the left and values on the right (long values are
78
+ shortened in the middle). `NO_COLOR` only drops the colors; `TERM=dumb` draws the tables with
79
+ `+`, `-` and `|`.
80
+ - **Clearer labels in the HTML report.** The checks table of a key shows Raw (the value measured
81
+ in the run) and Bound (the 95% confidence bound that Apdex, slow share and error rate compare
82
+ with the limit) instead of Actual and Observed, with a one-line legend; `report.json` keeps the
83
+ field names `actual` and `observed`. The column Headroom is now Limit used (it shows how much of
84
+ the limit is used). A line under the checks table gives T of Apdex and slow share and says when
85
+ T is the lowest the thresholds allow, so a key can pass them while its percentiles fail. The
86
+ Steps tile says how many steps are over their limit ("1 over limit · 0 near limit"). The Tests
87
+ result and the tile without steps count test runs ("passed 50 test runs"), not tests. Hints of
88
+ steps say "samples" instead of "responses". The key header in the details dialog shows the
89
+ origin label as a token before the path (`api` and `/api/prices`, not `GET api/api/prices`),
90
+ with the origin address in its tooltip. The note that the medians of the TTFB split can differ
91
+ from p50 only appears when they differ.
92
+ - **Rounded multiples and percentages.** The hard-limit hint shows the multiple of the limit with
93
+ two decimals, rounded ("2.67×", was "2.6×"), and never one that is not above the hard limit
94
+ factor ("2.05×", was "2.0× … above the hard limit of 2×"). The excess of a failed check in the
95
+ HTML report is the text of the console and `junit.xml` (rounded: "+105%", was "+106%" from
96
+ rounding up), and every output shows at least "+1%" (the console could show "+0%"). The share of
97
+ the limit used by a passing check is rounded ("56% of limit", was "55%"), but never shown as 90%
98
+ or more below 0.9, where the near-limit hint and colour start.
99
+ - **Wording of the guided setup in es, fr, it, pl, uk and ru.** A review of every translated
100
+ text: the question about passes now asks how many passes per measurement (es, fr, it); one word
101
+ for a pass in Italian ("passata", no longer "passaggio", which also means a step) and for a
102
+ measurement ("misurazione"); the wizard is the "procedura guidata" in Italian; the summary is
103
+ "Récapitulatif" in French and "Сводка" in Russian; Ukrainian and Russian no longer say that a
104
+ run "falls" on a regression but that it ends with an error, call step titles "names" and write
105
+ "endpoint" in Cyrillic everywhere; plainer words for the cleaning of step titles (es, pl).
106
+ Meaning and placeholders are unchanged.
107
+ - **The guided setup ends with an IMPORTANT box.** After it writes the setup, the wizard ends
108
+ with a framed box (in the chosen language, at most 80 columns, ASCII with `TERM=dumb`) of the
109
+ next steps with your exact commands: derive the thresholds on CI, on the environment where the
110
+ tests will run (`PW_PERF_MODE=thresholds <your command>`; it can take several hours), download
111
+ the thresholds files from the CI artifacts (the report folder `reports/pw-perf`), commit them,
112
+ and from then on run `PW_PERF_MODE=test <your command>`. It replaces the `Run:` line and the
113
+ "Next steps" list; when the check did not run, one line suggests `PW_PERF_MODE=check` first.
114
+ Without a terminal or with `PW_PERF_DRY_RUN=1` the summary is as before.
115
+ - **The guided setup creates empty thresholds files.** It always adds `pw-perf-thresholds.json`
116
+ and `pw-perf-thresholds.steps.json` next to the Playwright config, without entries and whatever
117
+ you chose to measure, each with its own diff and confirmation; an existing thresholds file is
118
+ never changed. A measurement run with an empty file warns with the new `THRESHOLDS_FILE_EMPTY`
119
+ and suggests a thresholds run (as for a missing file), a check shows `0 entries` and the same
120
+ next step, and the thresholds run fills the files without `THRESHOLDS_MANUAL_FILE`.
121
+ - **The config file of the guided setup lists every option as code.** `pw-perf.config.ts` (or
122
+ `.js`) now sets all 15 listed options: your answers and the default value of every other
123
+ option, so you edit a value instead of uncommenting lines and objects. Each section has a
124
+ short comment above it, and the `report.dir` comment says the folder (with `junit.xml`) is not
125
+ committed. Config files written by an earlier wizard keep working unchanged.
126
+
127
+ ### Fixed
128
+
129
+ - **Violation cards show the rule that failed the run.** A card in the Overview of the HTML report
130
+ showed the failed check with the highest share of its limit, e.g. slow share "+5 pp", while its
131
+ hint explained a p95 above the hard limit. It now shows the deciding check: a blocking check
132
+ above the hard limit first, then other blocking checks. The Limit used column of the key tables
133
+ shows the same check for a failed key.
134
+ - **Step thresholds file no longer "differs".** Run & config compared the normalization
135
+ fingerprint of the step thresholds file with the fingerprint of URL keys, so it always showed
136
+ "differs: keys may not match". It now compares it with the step fingerprint of the run; a real
137
+ difference also links to the `THRESHOLDS_SOURCE_MISMATCH` warning.
138
+ - **No limit for rules that were not evaluated.** A key with too few samples for p95 or p99 showed
139
+ their limits (in red when above), although those rules decided nothing. The key table now shows
140
+ "/ —" with a footnote, and the details say "p95 · not evaluated".
141
+ - **Start box closes on every line.** The title line of the start box used ⏱️ (a character with
142
+ the emoji variation selector U+FE0F), whose width terminals count differently, so its right
143
+ edge stood one column off in VS Code and Terminal.app. The title now uses ⏳, which every modern
144
+ terminal shows in two columns, and no frame or table uses U+FE0F sequences. Text widths of
145
+ frames and tables now follow the wcwidth conventions (variation selectors, joiners and combining
146
+ marks take no column; an emoji sequence is never cut apart).
147
+
10
148
  ## [0.1.0-next.4] - 2026-11-23
11
149
 
12
150
  Upgrading from `0.1.0-next.3`: see [Upgrading](docs/upgrading.md). In short, run your test
package/README.md CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  Catch backend performance regressions from the Playwright tests you already have.
4
4
 
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
5
  ![HTML report of a measurement run](.github/assets/report.png)
11
6
 
12
7
  ## How it works
@@ -27,23 +22,25 @@ Your normal `npx playwright test` runs are not changed.
27
22
  ## Install
28
23
 
29
24
  ```sh
30
- npm init playwright-performance-regression@next
25
+ npm init playwright-performance-regression
31
26
  ```
32
27
 
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
28
+ This installs the package as a dev dependency and starts a short guided setup (run it again at
29
+ any time; in a project with the package installed, `npx pw-perf` starts it too). It asks which tests to measure, the passes, what
36
30
  to measure (endpoints, `test.step` blocks or both), the threshold headroom and your usual test
37
31
  command, then shows a diff of every change before writing it: it creates `pw-perf.config.ts`
38
32
  (`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.
33
+ Playwright config and your fixtures module, ignores `reports/pw-perf/`. It adds no CI jobs and no scripts: your
34
+ test command is only used in the commands it prints at the end and for the check; the
35
+ [CI recipes](docs/ci.md) are yours to copy.
40
36
  Without a fixtures module, it switches the `@playwright/test` imports of your test files to
41
37
  `playwright-performance-regression/test`, one confirmed diff per file; when it cannot change the
42
38
  test object, it shows the code to paste. `package.json` is never changed. At the end it offers a
43
39
  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
40
+ 2 passes, and the check's thresholds files are deleted afterwards. It ends with an IMPORTANT box
41
+ of the next steps: thresholds on CI (can take several hours), download, commit, then
42
+ `PW_PERF_MODE=test`. `pnpm create` and `yarn create`
43
+ work too. The guided setup speaks English, Spanish, French, Polish, Italian, Ukrainian and
47
44
  Russian (it asks at the start). It takes no arguments; `PW_PERF_LANG`, `PW_PERF_DRY_RUN` and
48
45
  `PW_PERF_NO_TUTORIAL` change it ([Guided setup](docs/cli.md#guided-setup)).
49
46
 
@@ -108,7 +105,8 @@ On Windows: `npx cross-env PW_PERF_MODE=test npm run e2e` (PowerShell and cmd fo
108
105
  The exit code is Playwright's own; the cause of a failure (a regression, failed tests, a config
109
106
  error) is in `reports/pw-perf/outcome.json`. The result is also printed in the terminal and written
110
107
  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,
108
+ Steps, Tests and Run & config); a `test` run also writes `reports/pw-perf/junit.xml` for the test
109
+ views of CI systems. Every `test` and `thresholds` run empties `reports/pw-perf/` first,
112
110
  so it holds only the last run. All variables are described in [Running](docs/cli.md).
113
111
 
114
112
  Derive thresholds on the same machines that run the check, usually your CI runners (see
@@ -130,8 +128,9 @@ words become `:num` (`Transfer 1500 PLN` → `Transfer :num PLN`). See [Step tim
130
128
  ## CI
131
129
 
132
130
  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:
131
+ `reports/pw-perf/` as an artifact (the run copies the thresholds files there), (2) you commit the
132
+ thresholds files, (3) a weekly job runs with `PW_PERF_MODE=test` and fails on a regression. In
133
+ GitHub Actions, shortened:
135
134
 
136
135
  ```yaml
137
136
  name: Performance
@@ -152,7 +151,7 @@ jobs:
152
151
  - run: npm run e2e
153
152
  - uses: actions/upload-artifact@v7
154
153
  if: always()
155
- with: { name: pw-perf-thresholds, path: pw-perf-thresholds*.json }
154
+ with: { name: pw-perf-thresholds, path: reports/pw-perf/ }
156
155
  measure:
157
156
  if: github.event_name == 'schedule' || inputs.mode == 'test'
158
157
  runs-on: ubuntu-latest
@@ -1,6 +1,6 @@
1
1
  import { wrappedTests, trackedContexts, activeCollector, getRegistered, setActiveCollector, wrappedRequestContexts } from './chunk-S6UH6QPK.js';
2
- import { ABORT_FAILURE_TEXTS, CONTEXT_CLOSED_FAILURE_TEXT, readModeState, ConfigError, DEFAULT_MAX_TESTS, version, SAMPLES_ATTACHMENT_NAME, checkStateFileName } from './chunk-RL27E3AB.js';
3
- import { perfDefaults } from './chunk-CISGJCFW.js';
2
+ import { ABORT_FAILURE_TEXTS, CONTEXT_CLOSED_FAILURE_TEXT, readModeState, ConfigError, DEFAULT_MAX_TESTS, version, SAMPLES_ATTACHMENT_NAME, checkStateFileName } from './chunk-YKBX6SAT.js';
3
+ import { perfDefaults } from './chunk-5Y34Q4DR.js';
4
4
  import { readFileSync, writeFileSync } from 'fs';
5
5
  import { tmpdir } from 'os';
6
6
  import { join } from 'path';
@@ -301,7 +301,7 @@ var DEFAULT_CONFIG = {
301
301
  ".eot"
302
302
  ],
303
303
  include: [],
304
- exclude: ["/socket.io/"],
304
+ exclude: ["/socket.io/", "/sockjs/", "/sockjs-node/", "/signalr/", "/_blazor/"],
305
305
  excludeKnownThirdParty: true,
306
306
  successStatuses: ["2xx", "3xx"],
307
307
  steps: true,
@@ -381,7 +381,7 @@ var DEFAULT_CONFIG = {
381
381
  hysteresis: { relative: 0.1, ratio: 0.01 },
382
382
  loosenWarnRelative: 0.5
383
383
  },
384
- report: { dir: "reports/pw-perf", html: true, rawUrls: false },
384
+ report: { dir: "reports/pw-perf", html: true, junit: true, rawUrls: false },
385
385
  advanced: { maxSamplesPerKey: 5e3, seed: 1 }
386
386
  };
387
387
 
@@ -748,7 +748,7 @@ var packageConfig = obj({
748
748
  hysteresis: obj({ relative: unit, ratio: num({ minimum: 0, maximum: 0.01 }) }),
749
749
  loosenWarnRelative: num({ minimum: 0, maximum: 100 })
750
750
  }),
751
- report: obj({ dir: str({ minLength: 1 }), html: bool, rawUrls: bool }),
751
+ report: obj({ dir: str({ minLength: 1 }), html: bool, junit: bool, rawUrls: bool }),
752
752
  advanced: obj({
753
753
  maxSamplesPerKey: int({ minimum: 100, maximum: 1e5 }),
754
754
  seed: int({ minimum: 0, maximum: 4294967295 })
@@ -1,5 +1,5 @@
1
- import { KINDS } from './chunk-RL27E3AB.js';
2
- import { str, nullable, constant, obj, bool, msOrNull, epochMs, enumOf, oneOf, int, arr, issue, isoDate, ratio, msLimit, fingerprint, hostFingerprint, derivationSettings, percentileName, count, timestamp, runId, envLabelOrNull, tool, kind, record, key, nul, anyObject, ms, num, packageConfig, mode, evaluationStatus, testsStatus, isRecord, Sink, child, expandSteps, DEFAULT_CONFIG } from './chunk-CISGJCFW.js';
1
+ import { KINDS } from './chunk-YKBX6SAT.js';
2
+ import { str, nullable, constant, obj, bool, msOrNull, epochMs, enumOf, oneOf, int, arr, issue, isoDate, ratio, msLimit, fingerprint, hostFingerprint, derivationSettings, percentileName, count, timestamp, runId, envLabelOrNull, tool, kind, record, key, nul, anyObject, ms, num, packageConfig, mode, evaluationStatus, testsStatus, isRecord, Sink, child, expandSteps, DEFAULT_CONFIG } from './chunk-5Y34Q4DR.js';
3
3
  import { rmSync, readFileSync, readdirSync, lstatSync, realpathSync, existsSync } from 'fs';
4
4
  import { readFile, mkdir, writeFile, rename, rm, access } from 'fs/promises';
5
5
  import { tmpdir, homedir, cpus, availableParallelism } from 'os';
@@ -184,6 +184,51 @@ function stringifyStable(value) {
184
184
  `;
185
185
  }
186
186
 
187
+ // src/core/format/violation.ts
188
+ var TIME_RULES = /* @__PURE__ */ new Set([
189
+ "median",
190
+ "percentile",
191
+ "p99"
192
+ ]);
193
+ var SHARE_RULES = /* @__PURE__ */ new Set([
194
+ "apdex",
195
+ "wilson",
196
+ "errors"
197
+ ]);
198
+ function exceedance(check2) {
199
+ if (check2.rule === "apdex") return check2.actual === 0 ? Infinity : check2.limit / check2.actual;
200
+ return check2.limit === 0 ? Infinity : check2.actual / check2.limit;
201
+ }
202
+ function overText(check2) {
203
+ if (SHARE_RULES.has(check2.rule)) {
204
+ const points = Math.max(1, Math.round(Math.abs(check2.actual - check2.limit) * 100));
205
+ return `+${String(points)} pp`;
206
+ }
207
+ const r = exceedance(check2);
208
+ if (!Number.isFinite(r)) return ">999%";
209
+ const over = Math.max(1, Math.round((r - 1) * 100));
210
+ return over > 999 ? ">999%" : `+${String(over)}%`;
211
+ }
212
+ function formatFactor(ratio2, threshold = null) {
213
+ const scaled = Math.round(ratio2 * 1e6) / 1e4;
214
+ let hundredths = Math.round(scaled);
215
+ if (threshold !== null && hundredths / 100 <= threshold && ratio2 > threshold) {
216
+ hundredths = Math.ceil(scaled);
217
+ }
218
+ return (hundredths / 100).toFixed(2);
219
+ }
220
+ function formatMs(ms2) {
221
+ return `${Math.round(ms2)} ms`;
222
+ }
223
+ function formatActual(check2) {
224
+ if (TIME_RULES.has(check2.rule)) return formatMs(check2.actual);
225
+ const observed = check2.observed === null ? "" : ` (${check2.observed.toFixed(3)})`;
226
+ return `${check2.actual.toFixed(3)}${observed}`;
227
+ }
228
+ function formatLimit(check2) {
229
+ return TIME_RULES.has(check2.rule) ? formatMs(check2.limit) : check2.limit.toFixed(3);
230
+ }
231
+
187
232
  // src/io/json.ts
188
233
  async function writeTextAtomic(path, text) {
189
234
  const dir = dirname(path);
@@ -1308,9 +1353,10 @@ function migrateRunReportV3(document) {
1308
1353
  if (!isRecord(config) || !isRecord(config.run)) return document;
1309
1354
  const { projects: _projects, ...run } = config.run;
1310
1355
  const measure = isRecord(config.measure) ? { api: true, ...config.measure } : config.measure;
1356
+ const report = isRecord(config.report) ? { ...config.report, junit: false } : config.report;
1311
1357
  return {
1312
1358
  ...document,
1313
- config: { ...config, run: { ...run, overrideSlowMo: false }, measure }
1359
+ config: { ...config, run: { ...run, overrideSlowMo: false }, measure, report }
1314
1360
  };
1315
1361
  }
1316
1362
  var RUN_REPORT_FORMAT = {
@@ -1465,37 +1511,101 @@ function plural(n, word, many = `${word}s`) {
1465
1511
  return `${n} ${n === 1 ? word : many}`;
1466
1512
  }
1467
1513
  function truncateMiddle(text, width) {
1468
- const chars = Array.from(text);
1469
- if (chars.length <= width) return text;
1514
+ if (textWidth(text) <= width) return text;
1470
1515
  if (width <= 1) return "…".slice(0, width);
1471
- const head = Math.ceil((width - 1) / 2);
1472
- const tail = width - 1 - head;
1473
- return `${chars.slice(0, head).join("")}…${tail === 0 ? "" : chars.slice(-tail).join("")}`;
1516
+ const chars = clusters(text);
1517
+ const headRoom = Math.ceil((width - 1) / 2);
1518
+ const tailRoom = width - 1 - headRoom;
1519
+ let head = "";
1520
+ let used = 0;
1521
+ for (const c of chars) {
1522
+ if (used + c.width > headRoom) break;
1523
+ head += c.text;
1524
+ used += c.width;
1525
+ }
1526
+ let tail = "";
1527
+ used = 0;
1528
+ for (let i = chars.length - 1; i >= 0; i -= 1) {
1529
+ const c = chars[i];
1530
+ if (c === void 0 || used + c.width > tailRoom) break;
1531
+ tail = c.text + tail;
1532
+ used += c.width;
1533
+ }
1534
+ return `${head}…${tail}`;
1474
1535
  }
1475
1536
  var WIDE = [
1476
1537
  [8986, 8987],
1477
1538
  [9193, 9196],
1478
1539
  [9200, 9200],
1479
1540
  [9203, 9203],
1541
+ [9725, 9726],
1542
+ [9748, 9749],
1543
+ [9800, 9811],
1544
+ [9855, 9855],
1545
+ [9875, 9875],
1480
1546
  [9889, 9889],
1547
+ [9898, 9899],
1548
+ [9917, 9918],
1549
+ [9924, 9925],
1550
+ [9934, 9934],
1481
1551
  [9940, 9940],
1552
+ [9962, 9962],
1553
+ [9970, 9971],
1554
+ [9973, 9973],
1555
+ [9978, 9978],
1556
+ [9981, 9981],
1482
1557
  [9989, 9989],
1558
+ [9994, 9995],
1559
+ [10024, 10024],
1483
1560
  [10060, 10060],
1484
1561
  [10062, 10062],
1485
1562
  [10067, 10069],
1486
1563
  [10071, 10071],
1564
+ [10133, 10135],
1565
+ [10160, 10160],
1566
+ [10175, 10175],
1567
+ [11035, 11036],
1487
1568
  [11088, 11088],
1488
1569
  [11093, 11093],
1489
1570
  [127744, 129791]
1490
1571
  ];
1572
+ var ZERO = [
1573
+ [768, 879],
1574
+ [8203, 8205],
1575
+ [8400, 8447],
1576
+ [65024, 65039],
1577
+ [127995, 127999],
1578
+ [917760, 917999]
1579
+ ];
1580
+ var VS16 = 65039;
1581
+ var ZWJ = 8205;
1582
+ function inRanges(cp, ranges) {
1583
+ return ranges.some(([from, to]) => cp >= from && cp <= to);
1584
+ }
1491
1585
  function charWidth(char) {
1492
1586
  const cp = char.codePointAt(0) ?? 0;
1493
- return WIDE.some(([from, to]) => cp >= from && cp <= to) ? 2 : 1;
1587
+ if (inRanges(cp, ZERO)) return 0;
1588
+ return inRanges(cp, WIDE) ? 2 : 1;
1589
+ }
1590
+ function clusters(text) {
1591
+ const out = [];
1592
+ let joined = false;
1593
+ for (const char of text) {
1594
+ const cp = char.codePointAt(0) ?? 0;
1595
+ const last = out[out.length - 1];
1596
+ if (last !== void 0 && (joined || charWidth(char) === 0)) {
1597
+ last.text += char;
1598
+ if (cp === VS16) last.width = 2;
1599
+ joined = cp === ZWJ;
1600
+ continue;
1601
+ }
1602
+ out.push({ text: char, width: charWidth(char) });
1603
+ joined = false;
1604
+ }
1605
+ return out;
1494
1606
  }
1495
1607
  function textWidth(text) {
1496
- let width = 0;
1497
- for (const char of text) width += charWidth(char);
1498
- return width;
1608
+ return clusters(text).reduce((sum2, c) => sum2 + c.width, 0);
1499
1609
  }
1500
1610
  function padEnd(text, width) {
1501
1611
  return text + " ".repeat(Math.max(0, width - textWidth(text)));
@@ -1515,9 +1625,8 @@ function cellsOf(line) {
1515
1625
  const spans = line.spans ?? [{ text: line.text ?? "", style: line.style }];
1516
1626
  const cells = [];
1517
1627
  for (const span of spans) {
1518
- for (const char of span.text) {
1519
- cells.push({ char, style: span.style, width: charWidth(char) });
1520
- }
1628
+ for (const c of clusters(span.text))
1629
+ cells.push({ char: c.text, style: span.style, width: c.width });
1521
1630
  }
1522
1631
  return cells;
1523
1632
  }
@@ -1610,10 +1719,22 @@ function box(lines, opts) {
1610
1719
  return `${boxLines(lines, opts).join("\n")}
1611
1720
  `;
1612
1721
  }
1722
+ function cutText(text, width) {
1723
+ if (textWidth(text) <= width) return text;
1724
+ let out = "";
1725
+ let used = 0;
1726
+ for (const c of clusters(text)) {
1727
+ if (used + c.width > width - 1) break;
1728
+ out += c.text;
1729
+ used += c.width;
1730
+ }
1731
+ return `${out}…`;
1732
+ }
1613
1733
  function table(columns, rows, opts) {
1614
1734
  const g = opts.ascii ? { v: "|", h: "-", top: ["+", "+", "+"], mid: ["+", "+", "+"], bottom: ["+", "+", "+"] } : { v: "│", h: "─", top: ["┌", "┬", "┐"], mid: ["├", "┼", "┤"], bottom: ["└", "┴", "┘"] };
1735
+ const header = opts.header !== false;
1615
1736
  const natural = columns.map(
1616
- (c, i) => Math.max(textWidth(c.header), ...rows.map((r) => textWidth(r.cells[i] ?? "")))
1737
+ (c, i) => Math.max(header ? textWidth(c.header) : 0, ...rows.map((r) => textWidth(r.cells[i] ?? "")))
1617
1738
  );
1618
1739
  const overhead = 3 * columns.length + 1;
1619
1740
  const widths = columns.map((c, i) => {
@@ -1621,28 +1742,47 @@ function table(columns, rows, opts) {
1621
1742
  const others = natural.reduce((sum2, w, j) => j === i ? sum2 : sum2 + w, 0);
1622
1743
  return Math.max(c.minWidth ?? 1, Math.min(natural[i] ?? 0, opts.width - overhead - others));
1623
1744
  });
1624
- const dim = (text) => paint(text, "dim", opts.color);
1625
- const rule = ([left, cross, right]) => dim(`${left}${widths.map((w) => g.h.repeat(w + 2)).join(cross)}${right}`);
1626
- const line = (cells, style) => {
1745
+ let title = opts.title ?? "";
1746
+ if (title !== "") {
1747
+ const inner = () => widths.reduce((sum2, w) => sum2 + w + 3, -1);
1748
+ const room = Math.max(1, opts.width - 2 - 4);
1749
+ title = cutText(title, room);
1750
+ const need = textWidth(title) + 4 - inner();
1751
+ const last = widths.length - 1;
1752
+ if (need > 0 && last >= 0) widths[last] = (widths[last] ?? 0) + need;
1753
+ }
1754
+ const border = opts.border ?? "dim";
1755
+ const edge = (text) => paint(text, border, opts.color);
1756
+ const ruleText = ([left, cross, right]) => `${left}${widths.map((w) => g.h.repeat(w + 2)).join(cross)}${right}`;
1757
+ const rule = (marks2) => edge(ruleText(marks2));
1758
+ const top = () => {
1759
+ if (title === "") return rule(g.top);
1760
+ const rest = ruleText(g.top).slice(textWidth(title) + 4);
1761
+ return `${edge(`${g.top[0] ?? ""}${g.h} `)}${paint(title, "bold", opts.color)}${edge(` ${rest}`)}`;
1762
+ };
1763
+ const line = (cells, style, cellStyles = []) => {
1627
1764
  const texts = columns.map((c, i) => {
1628
1765
  const w = widths[i] ?? 0;
1629
1766
  const raw = cells[i] ?? "";
1630
1767
  const text = c.flex === true ? truncateMiddle(raw, w) : raw;
1631
1768
  const padded = c.align === "right" ? padStart(text, w) : padEnd(text, w);
1632
- return style === void 0 ? padded : paint(padded, style, opts.color);
1769
+ const cellStyle = cellStyles[i] ?? style ?? c.style;
1770
+ return cellStyle === void 0 ? padded : paint(padded, cellStyle, opts.color);
1633
1771
  });
1634
- return `${dim(g.v)} ${texts.join(` ${dim(g.v)} `)} ${dim(g.v)}`;
1772
+ return `${edge(g.v)} ${texts.join(` ${edge(g.v)} `)} ${edge(g.v)}`;
1635
1773
  };
1636
1774
  return [
1637
- rule(g.top),
1638
- line(
1639
- columns.map((c) => c.header),
1640
- "bold"
1641
- ),
1642
- rule(g.mid),
1643
- ...rows.map((r) => line(r.cells, r.style)),
1775
+ top(),
1776
+ ...header ? [
1777
+ line(
1778
+ columns.map((c) => c.header),
1779
+ "bold"
1780
+ ),
1781
+ rule(g.mid)
1782
+ ] : [],
1783
+ ...rows.map((r) => line(r.cells, r.style, r.cellStyles)),
1644
1784
  rule(g.bottom)
1645
1785
  ];
1646
1786
  }
1647
1787
 
1648
- export { SCHEMA_VERSIONS, asciiTerminal, box, boxLines, ceilTo, colorEnabled, compareText, directoryOf, emptyDirSync, floorTo, homeDir, isDirectorySync, listDirSync, loadThresholds, marks, padEnd, paint, painter, parseRunReport, parseSampleBatch, plural, readCiInfo, readHostInfo, readPackageInfo, readSuite, readTextFile, readTextFileSync, realPathSync, relativeSlashPath, removeFileSync, resolvePath, roundMs, roundRatio, runPass, scanDirSync, schemaIssueToIssue, stringifyStable, table, tempPath, textWidth, thresholdsFilePaths, truncateMiddle, writeJsonStable, writeTextAtomic };
1788
+ export { SCHEMA_VERSIONS, asciiTerminal, box, boxLines, ceilTo, colorEnabled, compareText, directoryOf, emptyDirSync, exceedance, floorTo, formatActual, formatFactor, formatLimit, formatMs, homeDir, isDirectorySync, listDirSync, loadThresholds, marks, overText, padEnd, paint, painter, parseRunReport, parseSampleBatch, plural, readCiInfo, readHostInfo, readPackageInfo, readSuite, readTextFile, readTextFileSync, realPathSync, relativeSlashPath, removeFileSync, resolvePath, roundMs, roundRatio, runPass, scanDirSync, schemaIssueToIssue, stringifyStable, table, tempPath, textWidth, thresholdsFilePaths, truncateMiddle, writeJsonStable, writeTextAtomic };