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.
Files changed (40) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/README.md +73 -52
  3. package/dist/{chunk-GCA73FFP.cjs → chunk-2JO5HVPC.cjs} +351 -44
  4. package/dist/{chunk-R2NPYGB7.cjs → chunk-44ASXVQN.cjs} +96 -198
  5. package/dist/{chunk-HES6BVZT.js → chunk-AQ2XKYNV.js} +349 -47
  6. package/dist/chunk-BAOTUUTV.cjs +611 -0
  7. package/dist/chunk-DX36GFOZ.js +558 -0
  8. package/dist/chunk-LTRHMBVY.js +5592 -0
  9. package/dist/{chunk-UTTU4FUC.js → chunk-MUZFQKGQ.js} +82 -184
  10. package/dist/cli.js +3500 -1157
  11. package/dist/config.cjs +91 -44
  12. package/dist/config.d.cts +4 -2
  13. package/dist/config.d.ts +4 -2
  14. package/dist/config.js +84 -37
  15. package/dist/fixture.cjs +5 -5
  16. package/dist/fixture.d.cts +2 -2
  17. package/dist/fixture.d.ts +2 -2
  18. package/dist/fixture.js +3 -3
  19. package/dist/index.cjs +3 -3
  20. package/dist/index.d.cts +110 -22
  21. package/dist/index.d.ts +110 -22
  22. package/dist/index.js +1 -1
  23. package/dist/perf-api-Rm1h1O_-.d.cts +12 -0
  24. package/dist/perf-api-Rm1h1O_-.d.ts +12 -0
  25. package/dist/reporter.cjs +5204 -1209
  26. package/dist/reporter.js +2035 -254
  27. package/dist/test.cjs +4 -4
  28. package/dist/test.js +3 -3
  29. package/package.json +5 -3
  30. package/schemas/common.schema.json +2 -2
  31. package/schemas/config.schema.json +57 -21
  32. package/schemas/outcome.schema.json +1 -1
  33. package/schemas/run-report.schema.json +534 -19
  34. package/schemas/samples.schema.json +4 -39
  35. package/schemas/thresholds.schema.json +1 -1
  36. package/dist/chunk-6AB42SPF.js +0 -254
  37. package/dist/chunk-JEHUFIY3.js +0 -3390
  38. package/dist/chunk-LV3O2BAT.cjs +0 -319
  39. package/dist/perf-api-V4PeHVE0.d.cts +0 -22
  40. package/dist/perf-api-V4PeHVE0.d.ts +0 -22
@@ -1,7 +1,41 @@
1
1
  'use strict';
2
2
 
3
- var chunkLV3O2BAT_cjs = require('./chunk-LV3O2BAT.cjs');
4
- var chunkGCA73FFP_cjs = require('./chunk-GCA73FFP.cjs');
3
+ var chunkBAOTUUTV_cjs = require('./chunk-BAOTUUTV.cjs');
4
+ var chunk2JO5HVPC_cjs = require('./chunk-2JO5HVPC.cjs');
5
+ var fs = require('fs');
6
+ var os = require('os');
7
+ var path = require('path');
8
+
9
+ var memory = { files: [], ran: 0 };
10
+ function checkStatePath(runId) {
11
+ return path.join(os.tmpdir(), chunkBAOTUUTV_cjs.checkStateFileName(runId));
12
+ }
13
+ function load(path) {
14
+ if (path === null) return memory;
15
+ try {
16
+ const parsed = JSON.parse(fs.readFileSync(path, "utf8"));
17
+ return { files: Array.isArray(parsed.files) ? parsed.files : [], ran: Number(parsed.ran ?? 0) };
18
+ } catch {
19
+ return { files: [], ran: 0 };
20
+ }
21
+ }
22
+ function save(path, state) {
23
+ if (path === null) memory = state;
24
+ else fs.writeFileSync(path, JSON.stringify(state));
25
+ }
26
+ function checkRunsTest(runId, maxTests, project, file) {
27
+ const path = runId === void 0 ? null : checkStatePath(runId);
28
+ const state = load(path);
29
+ const id = `${project}\0${file}`;
30
+ if (state.ran >= maxTests || state.files.includes(id)) return false;
31
+ save(path, { files: [...state.files, id], ran: state.ran + 1 });
32
+ return true;
33
+ }
34
+
35
+ // src/collector/perf-api.ts
36
+ function createPerfApi(track) {
37
+ return Object.freeze({ track });
38
+ }
5
39
 
6
40
  // src/collector/constants.ts
7
41
  var KNOWN_THIRD_PARTY_HOSTS = Object.freeze([
@@ -40,156 +74,6 @@ var PENDING_RESERVE_MS = 1e3;
40
74
  var SAMPLE_LIMIT_PER_TEST = 2e4;
41
75
  var COLLECTOR_NAME = "playwright-js";
42
76
 
43
- // src/collector/timing.ts
44
- function roundMs(x) {
45
- return Math.round(x * 10) / 10 + 0;
46
- }
47
- function partialTiming(timing) {
48
- const { requestStart, responseStart } = timing;
49
- const ttfb = responseStart - requestStart;
50
- return {
51
- requestStart: requestStart >= 0 ? roundMs(requestStart) : null,
52
- ttfb: requestStart >= 0 && responseStart >= 0 && ttfb >= 0 ? roundMs(ttfb) : null
53
- };
54
- }
55
- function computeTiming(timing, fallback) {
56
- const browser = timing.responseEnd >= 0;
57
- return {
58
- startTime: Math.round(timing.startTime),
59
- duration: roundMs(
60
- browser ? timing.responseEnd : Math.max(0, fallback.finishedAtNode - fallback.startedAtNode)
61
- ),
62
- ...partialTiming(timing),
63
- timeSource: browser ? "browser" : "node"
64
- };
65
- }
66
- function pendingBudgetMs(input) {
67
- const { pendingTimeoutMs, testTimeoutMs, sinceTeardownStartMs } = input;
68
- if (testTimeoutMs === 0) return Math.max(0, pendingTimeoutMs);
69
- const left = testTimeoutMs - sinceTeardownStartMs - PENDING_RESERVE_MS;
70
- return Math.max(0, Math.min(pendingTimeoutMs, left));
71
- }
72
-
73
- // src/collector/custom-timer.ts
74
- var MAX_NAME_LENGTH = 200;
75
- var NAME = /^[^\s\u0000-\u001F\u007F](?:[^\u0000-\u001F\u007F]*[^\s\u0000-\u001F\u007F])?$/u;
76
- function validateMeasurementName(name) {
77
- let problem;
78
- if (typeof name !== "string") problem = `expected a string, got ${typeof name}`;
79
- else if ([...name].length > MAX_NAME_LENGTH) {
80
- problem = `the name has more than ${MAX_NAME_LENGTH} characters`;
81
- } else if (!NAME.test(name)) {
82
- problem = name.trim() === "" ? "the name is empty" : "the name starts or ends with whitespace or contains a control character";
83
- }
84
- if (problem !== void 0) {
85
- throw new TypeError(
86
- `CUSTOM_INVALID_NAME: invalid custom measurement name ${JSON.stringify(String(name))}: ${problem}. Use 1-${MAX_NAME_LENGTH} characters without control characters and without leading or trailing whitespace, e.g. "checkout:load-cart".`
87
- );
88
- }
89
- }
90
- var CustomTimer = class {
91
- #opts;
92
- #diag;
93
- #samples = [];
94
- /** Open start() measurements by name (06-REQ-06). */
95
- #started = /* @__PURE__ */ new Map();
96
- /** measure() calls in progress, each with its own start (06-REQ-05). */
97
- #measuring = /* @__PURE__ */ new Set();
98
- #finished = false;
99
- constructor(opts, diag) {
100
- this.#opts = opts;
101
- this.#diag = diag;
102
- }
103
- /** Measures `fn` (06-REQ-05): returns its result; on an exception records 'error' and rethrows. */
104
- async measure(name, fn) {
105
- validateMeasurementName(name);
106
- const running = { name, startedAt: this.#opts.now() };
107
- this.#measuring.add(running);
108
- let result;
109
- try {
110
- result = await fn();
111
- } catch (error) {
112
- this.#close(running, "error");
113
- throw error;
114
- }
115
- this.#close(running, "ok");
116
- return result;
117
- }
118
- start(name) {
119
- validateMeasurementName(name);
120
- const previous = this.#started.get(name);
121
- if (previous !== void 0) {
122
- this.#unfinished(previous);
123
- this.#issue(
124
- "CUSTOM_ALREADY_STARTED",
125
- `custom: perf.start(${JSON.stringify(name)}) was called while this measurement was running; the earlier one is recorded as unfinished`,
126
- "Call perf.end() before starting the same measurement again, or use perf.measure()."
127
- );
128
- }
129
- this.#started.set(name, { name, startedAt: this.#opts.now() });
130
- }
131
- /** Ends a measurement; returns its duration in ms, or undefined without a start (06-REQ-07). */
132
- end(name) {
133
- validateMeasurementName(name);
134
- const running = this.#started.get(name);
135
- if (running === void 0) {
136
- this.#issue(
137
- "CUSTOM_END_WITHOUT_START",
138
- `custom: perf.end(${JSON.stringify(name)}) was called without a matching perf.start()`,
139
- "Call perf.start() with the same name in the same test before perf.end()."
140
- );
141
- return void 0;
142
- }
143
- this.#started.delete(name);
144
- return this.#close(running, "ok");
145
- }
146
- /** Closes open measurements as 'unfinished' (06-REQ-09) and returns all samples. */
147
- finish() {
148
- if (!this.#finished) {
149
- this.#finished = true;
150
- const open = [...this.#started.values(), ...this.#measuring];
151
- this.#started.clear();
152
- this.#measuring.clear();
153
- for (const running of open) this.#unfinished(running);
154
- if (open.length > 0) {
155
- this.#issue(
156
- "CUSTOM_UNFINISHED",
157
- `custom: measurements still running when the test ended: ${[...new Set(open.map((r) => JSON.stringify(r.name)))].join(", ")}`,
158
- "End every perf.start() with perf.end(), or check whether the test timed out during the measurement.",
159
- open.length
160
- );
161
- }
162
- }
163
- return [...this.#samples];
164
- }
165
- #close(running, outcome) {
166
- const duration = roundMs(Math.max(0, this.#opts.now() - running.startedAt));
167
- this.#measuring.delete(running);
168
- if (this.#opts.record && !this.#finished) {
169
- this.#samples.push({
170
- name: running.name,
171
- outcome,
172
- duration,
173
- endTime: Math.round(this.#opts.wallNow())
174
- });
175
- }
176
- return duration;
177
- }
178
- #unfinished(running) {
179
- if (!this.#opts.record) return;
180
- this.#samples.push({
181
- name: running.name,
182
- outcome: "unfinished",
183
- duration: null,
184
- endTime: null
185
- });
186
- }
187
- #issue(code, message, hint, count) {
188
- if (!this.#opts.record) return;
189
- this.#diag.add({ code, message, hint, ...count === void 0 ? {} : { count } });
190
- }
191
- };
192
-
193
77
  // src/collector/diagnostics.ts
194
78
  function createDiagnostics() {
195
79
  const entries = /* @__PURE__ */ new Map();
@@ -213,20 +97,6 @@ function errorText(error) {
213
97
  return String(error);
214
98
  }
215
99
 
216
- // src/collector/perf-api.ts
217
- function createPerfApi(timer, track) {
218
- const start = (name) => timer.start(name);
219
- const end = (name) => timer.end(name);
220
- return Object.freeze({
221
- measure: (name, fn) => timer.measure(name, fn),
222
- start,
223
- end,
224
- sampleStart: start,
225
- sampleEnd: end,
226
- track
227
- });
228
- }
229
-
230
100
  // src/collector/filters.ts
231
101
  function isKnownThirdPartyHost(host, hosts = KNOWN_THIRD_PARTY_HOSTS) {
232
102
  const name = host.toLowerCase().replace(/\.$/u, "");
@@ -260,6 +130,36 @@ function shouldTrack(req, measure) {
260
130
  return true;
261
131
  }
262
132
 
133
+ // src/collector/timing.ts
134
+ function roundMs(x) {
135
+ return Math.round(x * 10) / 10 + 0;
136
+ }
137
+ function partialTiming(timing) {
138
+ const { requestStart, responseStart } = timing;
139
+ const ttfb = responseStart - requestStart;
140
+ return {
141
+ requestStart: requestStart >= 0 ? roundMs(requestStart) : null,
142
+ ttfb: requestStart >= 0 && responseStart >= 0 && ttfb >= 0 ? roundMs(ttfb) : null
143
+ };
144
+ }
145
+ function computeTiming(timing, fallback) {
146
+ const browser = timing.responseEnd >= 0;
147
+ return {
148
+ startTime: Math.round(timing.startTime),
149
+ duration: roundMs(
150
+ browser ? timing.responseEnd : Math.max(0, fallback.finishedAtNode - fallback.startedAtNode)
151
+ ),
152
+ ...partialTiming(timing),
153
+ timeSource: browser ? "browser" : "node"
154
+ };
155
+ }
156
+ function pendingBudgetMs(input) {
157
+ const { pendingTimeoutMs, testTimeoutMs, sinceTeardownStartMs } = input;
158
+ if (testTimeoutMs === 0) return Math.max(0, pendingTimeoutMs);
159
+ const left = testTimeoutMs - sinceTeardownStartMs - PENDING_RESERVE_MS;
160
+ return Math.max(0, Math.min(pendingTimeoutMs, left));
161
+ }
162
+
263
163
  // src/collector/request-tracker.ts
264
164
  var NO_TIMING = {
265
165
  startTime: -1,
@@ -428,7 +328,7 @@ var RequestTracker = class {
428
328
  }
429
329
  #closedByClient(request, entry) {
430
330
  this.#settle(request);
431
- this.#sink.finished(failed(request, entry, chunkLV3O2BAT_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
331
+ this.#sink.finished(failed(request, entry, chunkBAOTUUTV_cjs.CONTEXT_CLOSED_FAILURE_TEXT, safeTiming(request)));
432
332
  }
433
333
  /** A request still in flight after the wait (05-REQ-13 step 4, 05-REQ-31). */
434
334
  #leftover(request, entry) {
@@ -524,7 +424,6 @@ var TestCollector = class {
524
424
  api;
525
425
  #opts;
526
426
  #diag = createDiagnostics();
527
- #timer;
528
427
  #trackers = /* @__PURE__ */ new Map();
529
428
  #requests = [];
530
429
  #pending = [];
@@ -536,11 +435,7 @@ var TestCollector = class {
536
435
  #draining;
537
436
  constructor(opts) {
538
437
  this.#opts = opts;
539
- this.#timer = new CustomTimer(
540
- { now: opts.now, wallNow: opts.wallNow, record: true },
541
- this.#diag
542
- );
543
- this.api = createPerfApi(this.#timer, (context) => {
438
+ this.api = createPerfApi((context) => {
544
439
  this.track(context);
545
440
  });
546
441
  const keep = (list, sample) => {
@@ -627,7 +522,6 @@ var TestCollector = class {
627
522
  }
628
523
  /** The sample batch of the test (05-REQ-15); call after drain(). */
629
524
  batch() {
630
- const custom = this.#timer.finish();
631
525
  if (this.#dropped > 0) {
632
526
  this.#diag.add({
633
527
  code: "COLLECTOR_SAMPLE_LIMIT_REACHED",
@@ -638,14 +532,13 @@ var TestCollector = class {
638
532
  this.#dropped = 0;
639
533
  }
640
534
  return {
641
- schemaVersion: 1,
535
+ schemaVersion: 2,
642
536
  collector: {
643
537
  name: COLLECTOR_NAME,
644
538
  version: this.#opts.version,
645
539
  browserName: this.#browserName ?? null
646
540
  },
647
541
  requests: [...this.#requests, ...this.#pending],
648
- custom,
649
542
  diagnostics: this.#diag.list()
650
543
  };
651
544
  }
@@ -654,10 +547,10 @@ var TestCollector = class {
654
547
  try {
655
548
  await this.drain();
656
549
  const body = JSON.stringify(this.batch());
657
- await testInfo.attach(chunkLV3O2BAT_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
550
+ await testInfo.attach(chunkBAOTUUTV_cjs.SAMPLES_ATTACHMENT_NAME, { body, contentType: "application/json" });
658
551
  } catch (error) {
659
552
  process.stderr.write(
660
- `COLLECTOR_ATTACH_FAILED: ${chunkLV3O2BAT_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
553
+ `COLLECTOR_ATTACH_FAILED: ${chunkBAOTUUTV_cjs.SAMPLES_ATTACHMENT_NAME} could not be attached to the test result: ${errorText(error)}
661
554
  `
662
555
  );
663
556
  }
@@ -675,47 +568,52 @@ function engineOf(context) {
675
568
  var now = () => performance.now();
676
569
  var wallNow = () => Date.now();
677
570
  function perfModeOn() {
678
- const mode = chunkLV3O2BAT_cjs.readModeState(process.env);
679
- if (!mode.ok) throw new chunkLV3O2BAT_cjs.ConfigError(mode.issues);
571
+ const mode = chunkBAOTUUTV_cjs.readModeState(process.env);
572
+ if (!mode.ok) throw new chunkBAOTUUTV_cjs.ConfigError(mode.issues);
680
573
  return mode.value !== null;
681
574
  }
682
- function passiveApi() {
683
- return createPerfApi(
684
- new CustomTimer({ now, wallNow, record: false }, createDiagnostics()),
685
- () => {
686
- }
687
- );
688
- }
575
+ var PASSIVE_API = createPerfApi(() => {
576
+ });
689
577
  function openBuffer(browserName, testInfo) {
690
- const state = chunkLV3O2BAT_cjs.getRegistered();
578
+ const state = chunkBAOTUUTV_cjs.getRegistered();
691
579
  if (state !== void 0 && !state.measuredProjects.includes(testInfo.project.name)) {
692
- return { collector: null, api: passiveApi() };
580
+ return { collector: null, api: PASSIVE_API };
693
581
  }
694
582
  const collector = new TestCollector({
695
- measure: (state?.config ?? chunkGCA73FFP_cjs.perfDefaults).measure,
696
- version: chunkLV3O2BAT_cjs.version,
583
+ measure: (state?.config ?? chunk2JO5HVPC_cjs.perfDefaults).measure,
584
+ version: chunkBAOTUUTV_cjs.version,
697
585
  browserName,
698
586
  testTimeout: () => testInfo.timeout,
699
587
  now,
700
588
  wallNow
701
589
  });
702
- for (const context of chunkLV3O2BAT_cjs.trackedContexts()) collector.track(context);
590
+ for (const context of chunkBAOTUUTV_cjs.trackedContexts()) collector.track(context);
703
591
  return { collector, api: collector.api };
704
592
  }
593
+ function skipInCheck(testInfo) {
594
+ const state = chunkBAOTUUTV_cjs.getRegistered();
595
+ if (state === void 0 || state.mode.mode !== "check") return;
596
+ if (!state.measuredProjects.includes(testInfo.project.name)) return;
597
+ const max = state.mode.maxTests ?? chunkBAOTUUTV_cjs.DEFAULT_MAX_TESTS;
598
+ if (!checkRunsTest(state.mode.runId, max, testInfo.project.name, testInfo.file)) {
599
+ testInfo.skip(true, "pw-perf check: only the first test of each file runs");
600
+ }
601
+ }
705
602
  var passiveFixtures = {
706
603
  perf: async ({}, use) => {
707
- await use(passiveApi());
604
+ await use(PASSIVE_API);
708
605
  }
709
606
  };
710
607
  var perfFixtures = {
711
608
  _perfBuffer: [
712
609
  async ({ browserName }, use, testInfo) => {
610
+ skipInCheck(testInfo);
713
611
  const buffer = openBuffer(browserName ?? null, testInfo);
714
612
  const { collector } = buffer;
715
- if (collector !== null) chunkLV3O2BAT_cjs.setActiveCollector(collector);
613
+ if (collector !== null) chunkBAOTUUTV_cjs.setActiveCollector(collector);
716
614
  await use(buffer);
717
615
  if (collector === null) return;
718
- if (chunkLV3O2BAT_cjs.activeCollector() === collector) chunkLV3O2BAT_cjs.setActiveCollector(void 0);
616
+ if (chunkBAOTUUTV_cjs.activeCollector() === collector) chunkBAOTUUTV_cjs.setActiveCollector(void 0);
719
617
  collector.markTeardownStart();
720
618
  await collector.attach(testInfo);
721
619
  },
@@ -737,7 +635,7 @@ var perfFixtures = {
737
635
  }
738
636
  };
739
637
  function withPerfFixtures(base2) {
740
- const wrapped = chunkLV3O2BAT_cjs.wrappedTests();
638
+ const wrapped = chunkBAOTUUTV_cjs.wrappedTests();
741
639
  if (wrapped.has(base2)) return base2;
742
640
  const extend = base2.extend;
743
641
  const result = extend.call(base2, perfModeOn() ? perfFixtures : passiveFixtures);
@@ -746,12 +644,12 @@ function withPerfFixtures(base2) {
746
644
  }
747
645
  function trackContext(context) {
748
646
  if (!perfModeOn()) return;
749
- const contexts = chunkLV3O2BAT_cjs.trackedContexts();
647
+ const contexts = chunkBAOTUUTV_cjs.trackedContexts();
750
648
  if (!contexts.has(context)) {
751
649
  contexts.add(context);
752
650
  context.once("close", () => contexts.delete(context));
753
651
  }
754
- chunkLV3O2BAT_cjs.activeCollector()?.track(context);
652
+ chunkBAOTUUTV_cjs.activeCollector()?.track(context);
755
653
  }
756
654
 
757
655
  exports.trackContext = trackContext;