@piwitests/reporter 0.71.0 → 0.73.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.
@@ -868,6 +868,8 @@ declare class ResourceLedger {
868
868
  * in use until then.
869
869
  */
870
870
  private onWait;
871
+ /** Tell the listeners of `onTestCallPage` the page a call of the test lands on, when it lands on one. */
872
+ private tellCallPage;
871
873
  /**
872
874
  * Mark an object, and the page, context and browser it belongs to, used now
873
875
  * by the call at `site`. A close that began before it did not end: the
@@ -2999,8 +2999,8 @@ function readPrivateFile(file) {
2999
2999
  const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
3000
3000
  try {
3001
3001
  const stat2 = fs3.fstatSync(fd);
3002
- const opened = untrustedReason(stat2);
3003
- if (opened) return { untrusted: opened };
3002
+ const opened2 = untrustedReason(stat2);
3003
+ if (opened2) return { untrusted: opened2 };
3004
3004
  return { text: fs3.readFileSync(fd, "utf8"), mode: stat2.mode };
3005
3005
  } finally {
3006
3006
  fs3.closeSync(fd);
@@ -3440,6 +3440,13 @@ function fulfillHeaders(responseHeaders, contentType) {
3440
3440
  if (contentType) headers["content-type"] = contentType;
3441
3441
  return headers;
3442
3442
  }
3443
+ function isMainFrameRequest(page, request) {
3444
+ try {
3445
+ return request.frame() === page.mainFrame();
3446
+ } catch {
3447
+ return false;
3448
+ }
3449
+ }
3443
3450
  function originOf(url) {
3444
3451
  try {
3445
3452
  const origin = new URL(url).origin;
@@ -3484,25 +3491,31 @@ async function installRouteRules(page, rules) {
3484
3491
  });
3485
3492
  return { state };
3486
3493
  }
3487
- async function installProbeInterception(page, item) {
3494
+ async function installProbeInterception(page, item, baseURL = null) {
3488
3495
  if (!isFaultAllowed(item.level ?? "client", item.fault)) {
3489
3496
  return { applied: () => false, appliedFault: () => null, serverError: () => false };
3490
3497
  }
3491
3498
  let applied = false;
3492
3499
  let appliedFault = null;
3493
3500
  let serverError = false;
3494
- let appOrigin = null;
3501
+ const appOrigins = /* @__PURE__ */ new Set();
3502
+ const baseOrigin = baseURL ? originOf(baseURL) : null;
3503
+ if (baseOrigin) appOrigins.add(baseOrigin);
3504
+ let firstOpened = false;
3495
3505
  const probeSecret = process.env[PIWI_PROBE_ENV.secret];
3496
- page.on("framenavigated", (frame) => {
3497
- if (frame === page.mainFrame()) {
3498
- const origin = originOf(page.url());
3499
- if (origin) appOrigin = origin;
3500
- }
3506
+ page.on("request", (request) => {
3507
+ if (firstOpened || !request.isNavigationRequest() || request.redirectedFrom()) return;
3508
+ if (!isMainFrameRequest(page, request)) return;
3509
+ const origin = originOf(request.url());
3510
+ if (!origin) return;
3511
+ firstOpened = true;
3512
+ appOrigins.add(origin);
3501
3513
  });
3502
3514
  const handle = async (route, startedAt) => {
3503
3515
  const request = route.request();
3504
3516
  if (item.level === "server") {
3505
- if (!probeSecret || appOrigin !== null && originOf(request.url()) !== appOrigin) {
3517
+ const origin = originOf(request.url());
3518
+ if (!probeSecret || origin === null || !appOrigins.has(origin)) {
3506
3519
  await route.fallback();
3507
3520
  return;
3508
3521
  }
@@ -3510,7 +3523,8 @@ async function installProbeInterception(page, item) {
3510
3523
  if (item.dependency) spec.dependency = item.dependency;
3511
3524
  try {
3512
3525
  const response = await route.fetch({
3513
- headers: { ...request.headers(), "x-piwi-probe": buildProbeHeader(probeSecret, spec) }
3526
+ headers: { ...request.headers(), "x-piwi-probe": buildProbeHeader(probeSecret, spec) },
3527
+ maxRedirects: 0
3514
3528
  });
3515
3529
  const trace = parseProbeTrace(response.headers()["x-piwi-trace"]);
3516
3530
  appliedFault = trace.appliedFault;
@@ -6069,6 +6083,7 @@ var FrameAcks = class {
6069
6083
  var import_node_module2 = require("module");
6070
6084
 
6071
6085
  // src/internal/capture/quiet-capture.ts
6086
+ var import_node_async_hooks = require("async_hooks");
6072
6087
  var import_node_module = require("module");
6073
6088
  var path8 = __toESM(require("path"));
6074
6089
 
@@ -6155,6 +6170,7 @@ function boxCaptureFrames(extraPrefixes = []) {
6155
6170
  function callMethod(target, prop, args) {
6156
6171
  return target[prop](...args);
6157
6172
  }
6173
+ var outsideCalls = import_node_async_hooks.AsyncResource.bind((run) => run());
6158
6174
  function internalCall(owner, run) {
6159
6175
  const wrap = owner?._wrapApiCall;
6160
6176
  if (typeof wrap !== "function") return run();
@@ -8479,7 +8495,9 @@ var RUN_CHANNEL_ENV = "PIWI_RUN_CHANNEL";
8479
8495
  var RUN_REF_ENV = "PIWI_RUN_REF";
8480
8496
  var TERMINAL_REF_PREFIX = "terminal-";
8481
8497
  var RUN_HOLDS = ["failure"];
8482
- var RUN_FEATURES = ["view-lane", "give-up", "front", "layers", "trace"];
8498
+ var RUN_FEATURES = ["view-lane", "give-up", "front", "layers", "trace", "positions"];
8499
+ var POSITIONS_PER_SECOND = 4;
8500
+ var MAX_POSITION_TITLE = 300;
8483
8501
  var MAX_WAITING_TITLE = 500;
8484
8502
  var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
8485
8503
  var RUN_TAKES = [
@@ -8644,6 +8662,8 @@ function parseHubToRun(line) {
8644
8662
  const layers = readLaneLayers(value.layers);
8645
8663
  return layers ? { type: "layers", layers } : null;
8646
8664
  }
8665
+ case "positions":
8666
+ return typeof value.on === "boolean" ? { type: "positions", on: value.on } : null;
8647
8667
  case "share": {
8648
8668
  if (typeof value.on !== "boolean") return null;
8649
8669
  return isInt2(value.after, 1) ? { type: "share", on: value.on, after: value.after } : { type: "share", on: value.on };
@@ -9831,13 +9851,14 @@ async function keptResponse(id) {
9831
9851
  var CLOSE_MS = 1e3;
9832
9852
  var test = null;
9833
9853
  var stop = null;
9854
+ var opened = [];
9834
9855
  var subscribers = /* @__PURE__ */ new Set();
9835
9856
  var pageListeners = /* @__PURE__ */ new Set();
9836
9857
  var pageTold;
9837
9858
  var source = null;
9838
9859
  var closingOf = /* @__PURE__ */ new WeakMap();
9839
9860
  function laneTestBegan(id) {
9840
- test = { id, fixture: null, seen: [] };
9861
+ test = { id, fixture: null, called: null };
9841
9862
  void sync();
9842
9863
  tellPage();
9843
9864
  }
@@ -9848,9 +9869,23 @@ function lanePage(page) {
9848
9869
  tellPage();
9849
9870
  }
9850
9871
  function laneSawPage(page) {
9851
- if (!test || test.seen.includes(page)) return;
9852
- test.seen.push(page);
9853
- if (!source) void sync();
9872
+ if (opened.includes(page)) return;
9873
+ opened.push(page);
9874
+ if (typeof page.once === "function") {
9875
+ page.once("close", () => {
9876
+ const at = opened.indexOf(page);
9877
+ if (at >= 0) opened.splice(at, 1);
9878
+ tellPage();
9879
+ });
9880
+ }
9881
+ if (!test) return;
9882
+ void sync();
9883
+ tellPage();
9884
+ }
9885
+ function laneCalled(page) {
9886
+ if (!test || test.called === page || !opened.includes(page)) return;
9887
+ test.called = page;
9888
+ void sync();
9854
9889
  tellPage();
9855
9890
  }
9856
9891
  async function laneTestEnded() {
@@ -9890,7 +9925,9 @@ function tellPage() {
9890
9925
  }
9891
9926
  if (page === pageTold) return;
9892
9927
  pageTold = page;
9893
- for (const listener of pageListeners) listener();
9928
+ outsideCalls(() => {
9929
+ for (const listener of pageListeners) listener();
9930
+ });
9894
9931
  }
9895
9932
  function restamp() {
9896
9933
  const kept = source?.latest;
@@ -9911,7 +9948,14 @@ function lanePageShown() {
9911
9948
  const own = open4(stop?.page ?? null);
9912
9949
  if (own) return own;
9913
9950
  if (!test) return null;
9914
- return open4(test.fixture) ?? test.seen.find((page) => !page.isClosed()) ?? null;
9951
+ return open4(test.fixture) ?? open4(test.called) ?? lastOpened();
9952
+ }
9953
+ function lastOpened() {
9954
+ for (let at = opened.length - 1; at >= 0; at--) {
9955
+ const page = opened[at];
9956
+ if (!page.isClosed()) return page;
9957
+ }
9958
+ return null;
9915
9959
  }
9916
9960
  function pacerOf(own) {
9917
9961
  return new LatestPacer({
@@ -9955,11 +9999,7 @@ function subscribeLane(sink) {
9955
9999
  return subscribers.has(own) && kept && !("refused" in kept) && current2(kept) ? kept : null;
9956
10000
  },
9957
10001
  refresh: () => {
9958
- for (const subscriber of subscribers) {
9959
- subscriber.last = null;
9960
- subscriber.pacer.close();
9961
- subscriber.pacer = pacerOf(subscriber);
9962
- }
10002
+ for (const subscriber of subscribers) forgetFrames(subscriber);
9963
10003
  if (source) source.latest = null;
9964
10004
  void source?.view.then((view3) => view3?.refresh());
9965
10005
  },
@@ -9989,14 +10029,22 @@ function asked() {
9989
10029
  shotMs: Math.min(...sinks.map((sink) => sink.shotMs))
9990
10030
  };
9991
10031
  }
10032
+ function forgetFrames(subscriber) {
10033
+ subscriber.last = null;
10034
+ subscriber.pacer.close();
10035
+ subscriber.pacer = pacerOf(subscriber);
10036
+ }
9992
10037
  function sync() {
9993
10038
  const page = subscribers.size ? lanePageShown() : null;
9994
10039
  const options = page ? asked() : null;
9995
10040
  const key = options ? JSON.stringify(options) : "";
9996
10041
  if (source && source.page === page && source.asked === key) return Promise.resolve();
9997
- const closed = source ? close(source) : Promise.resolve();
9998
- source = page && options ? open2(page, options, key) : null;
9999
- return closed;
10042
+ if (source && source.page !== page) for (const subscriber of subscribers) forgetFrames(subscriber);
10043
+ return outsideCalls(() => {
10044
+ const closed = source ? close(source) : Promise.resolve();
10045
+ source = page && options ? open2(page, options, key) : null;
10046
+ return closed;
10047
+ });
10000
10048
  }
10001
10049
  function close(shown2) {
10002
10050
  if (source === shown2) source = null;
@@ -10844,6 +10892,7 @@ function shownInFull(own) {
10844
10892
  return own.asked?.full ?? true;
10845
10893
  }
10846
10894
  var link = null;
10895
+ var unhearLane = null;
10847
10896
  var missing = null;
10848
10897
  var changes = /* @__PURE__ */ new Set();
10849
10898
  var shareTurn = Promise.resolve();
@@ -10949,6 +10998,7 @@ function openLiveView(worker, env = process.env, ci = detectCi(env)) {
10949
10998
  asked: null
10950
10999
  };
10951
11000
  if (link.sharing) connect(link);
11001
+ unhearLane = onLanePage(lanePageChanged);
10952
11002
  inspectSent.clear();
10953
11003
  filmstrip?.close();
10954
11004
  filmstrip = new LaneFilmstrip(watchedLane, (kept, test2) => {
@@ -10964,6 +11014,8 @@ function closeLiveView() {
10964
11014
  link = null;
10965
11015
  running = null;
10966
11016
  missing = null;
11017
+ unhearLane?.();
11018
+ unhearLane = null;
10967
11019
  filmstrip?.close();
10968
11020
  filmstrip = null;
10969
11021
  thumbPosts.queue = [];
@@ -11009,15 +11061,24 @@ async function stopSharing() {
11009
11061
  }
11010
11062
  function liveViewTestBegan(title, call, mayPause2 = false) {
11011
11063
  if (!link) return;
11012
- running = { title, page: null, call, mayPause: mayPause2, began: Date.now() };
11064
+ running = { title, call, mayPause: mayPause2, began: Date.now() };
11013
11065
  textGeneration++;
11014
11066
  filmstrip?.forget();
11015
11067
  thumbPosts.queue = [];
11068
+ lanePageChanged();
11016
11069
  }
11017
- function liveViewPage(page) {
11018
- if (!link || !running || running.page) return;
11019
- running.page = page;
11020
- if (link.viewers > 0 && active(link)) startView();
11070
+ function lanePageChanged() {
11071
+ const own = link;
11072
+ if (!own || !running || !active(own) || own.viewers === 0) return;
11073
+ const page = lanePageNow();
11074
+ if (view?.page === page) return;
11075
+ if (!view) {
11076
+ if (page) startView();
11077
+ } else if (!page) {
11078
+ void stopView();
11079
+ } else {
11080
+ moveView(own, page);
11081
+ }
11021
11082
  }
11022
11083
  async function liveViewTestEnded(status) {
11023
11084
  if (!running) return;
@@ -11343,14 +11404,15 @@ function startThumbPosts(own) {
11343
11404
  }
11344
11405
  function startView() {
11345
11406
  const own = link;
11346
- const page = running?.page ?? null;
11407
+ const page = running ? lanePageNow() : null;
11347
11408
  if (!own || !active(own) || view) return;
11348
11409
  if (!page || page.isClosed()) {
11349
11410
  void post(own, { type: "frame", ...own.id, refused: NO_PAGE });
11350
11411
  return;
11351
11412
  }
11352
- const live = () => view?.page === page && link === own && active(own) && own.viewers > 0;
11353
- const frames = subscribeLane({
11413
+ let frames = null;
11414
+ const live = () => !!frames && view?.frames === frames && link === own && active(own) && own.viewers > 0;
11415
+ frames = subscribeLane({
11354
11416
  get maxWidth() {
11355
11417
  return own.asked?.width ?? LIVE_FRAME_WIDTH;
11356
11418
  },
@@ -11375,14 +11437,26 @@ function startView() {
11375
11437
  if (live()) void post(own, { type: "frame", ...own.id, refused: why ?? TOO_HEAVY });
11376
11438
  }
11377
11439
  });
11378
- const onClose = () => {
11379
- if (view?.page === page) void stopView();
11380
- };
11440
+ const onClose = () => lanePageChanged();
11381
11441
  page.once("close", onClose);
11382
11442
  view = { page, frames, onClose, following: null };
11383
11443
  followCalls(own);
11384
11444
  applyLayers(own, /* @__PURE__ */ new Set());
11385
11445
  }
11446
+ function moveView(own, page) {
11447
+ const shown2 = view;
11448
+ if (!shown2) return;
11449
+ shown2.page.off("close", shown2.onClose);
11450
+ void shown2.following?.then((stop2) => stop2?.());
11451
+ shown2.following = null;
11452
+ forgetLog(own);
11453
+ shown2.page = page;
11454
+ page.once("close", shown2.onClose);
11455
+ textGeneration++;
11456
+ void stopInspect();
11457
+ followCalls(own);
11458
+ applyLayers(own, new Set((own.asked?.layers ?? []).filter((layer) => layer !== "text")));
11459
+ }
11386
11460
  function followCalls(own) {
11387
11461
  const shown2 = view;
11388
11462
  if (!shown2 || own !== link) return;
@@ -11394,7 +11468,7 @@ function followCalls(own) {
11394
11468
  page,
11395
11469
  running.began,
11396
11470
  (log) => {
11397
- if (view === shown2 && link === own && active(own) && own.viewers > 0) postLog(own, log);
11471
+ if (view === shown2 && shown2.page === page && link === own && active(own) && own.viewers > 0) postLog(own, log);
11398
11472
  },
11399
11473
  { source: source2, titleOf: layersTitleOf, secrets: knownSecrets }
11400
11474
  ).catch(() => null);
@@ -11570,6 +11644,11 @@ var pickingAt = false;
11570
11644
  var runName = "";
11571
11645
  var eventsOn = false;
11572
11646
  var testRunning = false;
11647
+ var runningTestId = null;
11648
+ var positionsOn = false;
11649
+ var positionToldAt = -Infinity;
11650
+ var pendingPosition = null;
11651
+ var positionTimer = null;
11573
11652
  var eventRate = new RateWindow(MAX_RUN_EVENT_RATE);
11574
11653
  var droppedEvents = 0;
11575
11654
  var agentTurn = Promise.resolve();
@@ -11592,7 +11671,7 @@ async function openRunChannel(worker, handlers, env = process.env) {
11592
11671
  if (socket || !channel || !ref) return false;
11593
11672
  const opening = net.connect(channel.path);
11594
11673
  opening.setEncoding("utf8");
11595
- const opened = await new Promise((resolve7) => {
11674
+ const opened2 = await new Promise((resolve7) => {
11596
11675
  const timer = setTimeout(() => resolve7(false), CONNECT_MS);
11597
11676
  opening.once("connect", () => {
11598
11677
  clearTimeout(timer);
@@ -11603,7 +11682,7 @@ async function openRunChannel(worker, handlers, env = process.env) {
11603
11682
  resolve7(false);
11604
11683
  });
11605
11684
  });
11606
- if (!opened || opening.destroyed) {
11685
+ if (!opened2 || opening.destroyed) {
11607
11686
  opening.destroy();
11608
11687
  return false;
11609
11688
  }
@@ -11612,6 +11691,9 @@ async function openRunChannel(worker, handlers, env = process.env) {
11612
11691
  shown = /* @__PURE__ */ new Set();
11613
11692
  runName = `piwi-${ref}-w${worker.workerIndex}`;
11614
11693
  eventsOn = false;
11694
+ positionsOn = false;
11695
+ positionToldAt = -Infinity;
11696
+ dropPendingPosition();
11615
11697
  layersAsked = /* @__PURE__ */ new Set();
11616
11698
  host = null;
11617
11699
  opening.unref();
@@ -11712,11 +11794,15 @@ function runChannelOpen() {
11712
11794
  function tellHub(message) {
11713
11795
  if (message.type === "test-begin") {
11714
11796
  testRunning = true;
11797
+ runningTestId = message.testId;
11798
+ dropPendingPosition();
11715
11799
  laneGeneration++;
11716
11800
  filmstrip2?.forget();
11717
11801
  }
11718
11802
  if (message.type === "test-end") {
11719
11803
  testRunning = false;
11804
+ runningTestId = null;
11805
+ dropPendingPosition();
11720
11806
  void unbind();
11721
11807
  }
11722
11808
  if (socket && !socket.destroyed) socket.write(`${JSON.stringify(message)}
@@ -11725,6 +11811,32 @@ function tellHub(message) {
11725
11811
  function tellActing(stop2, what) {
11726
11812
  if (held?.stop === stop2) tellHub({ type: "acting", stop: stop2, what });
11727
11813
  }
11814
+ function positionsWanted() {
11815
+ return positionsOn && testRunning && runningTestId !== null && runChannelOpen();
11816
+ }
11817
+ function tellPosition(title, place) {
11818
+ if (!positionsWanted()) return;
11819
+ pendingPosition = { title, place };
11820
+ if (positionTimer) return;
11821
+ const wait = positionToldAt + 1e3 / POSITIONS_PER_SECOND - performance.now();
11822
+ if (wait <= 0) return sendPendingPosition();
11823
+ positionTimer = setTimeout(sendPendingPosition, wait);
11824
+ positionTimer.unref?.();
11825
+ }
11826
+ function sendPendingPosition() {
11827
+ if (positionTimer) clearTimeout(positionTimer);
11828
+ positionTimer = null;
11829
+ const position = pendingPosition;
11830
+ pendingPosition = null;
11831
+ if (!position || !positionsWanted()) return;
11832
+ positionToldAt = performance.now();
11833
+ tellHub({ type: "position", testId: runningTestId, title: position.title, place: position.place });
11834
+ }
11835
+ function dropPendingPosition() {
11836
+ pendingPosition = null;
11837
+ if (positionTimer) clearTimeout(positionTimer);
11838
+ positionTimer = null;
11839
+ }
11728
11840
  function runEventsWanted() {
11729
11841
  return eventsOn && testRunning && runChannelOpen();
11730
11842
  }
@@ -12028,20 +12140,20 @@ function startView2(holding) {
12028
12140
  const started = (async () => {
12029
12141
  if (view2) await stopView2();
12030
12142
  const opening = openView2(page, holding.stop);
12031
- const opened = await answerWithin(opening, PAGE_ANSWER_MS, "late");
12032
- if (opened === "late") {
12143
+ const opened2 = await answerWithin(opening, PAGE_ANSWER_MS, "late");
12144
+ if (opened2 === "late") {
12033
12145
  void opening.then((late) => late?.close());
12034
12146
  return { ok: false, message: NO_ANSWER };
12035
12147
  }
12036
- if (!opened) return { ok: false, message: "The page could not be shown: it closed, or does not answer." };
12148
+ if (!opened2) return { ok: false, message: "The page could not be shown: it closed, or does not answer." };
12037
12149
  if (held !== holding || page.isClosed()) {
12038
- await within5(opened.close(), VIEW_END_MS2);
12150
+ await within5(opened2.close(), VIEW_END_MS2);
12039
12151
  return { ok: false, message: WENT_ON };
12040
12152
  }
12041
- view2 = opened;
12153
+ view2 = opened2;
12042
12154
  return {
12043
12155
  ok: true,
12044
- message: opened.screencast ? "The live view is on." : "The live view is on, as images of the page twice a second: the page's screencast is in use."
12156
+ message: opened2.screencast ? "The live view is on." : "The live view is on, as images of the page twice a second: the page's screencast is in use."
12045
12157
  };
12046
12158
  })().finally(() => {
12047
12159
  if (viewStarting?.started === started) viewStarting = null;
@@ -12062,8 +12174,8 @@ async function openView2(page, stop2) {
12062
12174
  if (ours(at)) tellHub({ type: "frame", stop: stop2, refused: why ?? TOO_HEAVY2 });
12063
12175
  }
12064
12176
  });
12065
- const opened = await subscription.ready();
12066
- if (!opened) {
12177
+ const opened2 = await subscription.ready();
12178
+ if (!opened2) {
12067
12179
  await subscription.close();
12068
12180
  return null;
12069
12181
  }
@@ -12073,7 +12185,7 @@ async function openView2(page, stop2) {
12073
12185
  page.once("close", onClose);
12074
12186
  return {
12075
12187
  stop: stop2,
12076
- screencast: opened.screencast,
12188
+ screencast: opened2.screencast,
12077
12189
  resend: subscription.resend,
12078
12190
  close: async () => {
12079
12191
  page.off("close", onClose);
@@ -12244,6 +12356,10 @@ function onMessage(message) {
12244
12356
  eventRate = new RateWindow(MAX_RUN_EVENT_RATE);
12245
12357
  droppedEvents = 0;
12246
12358
  return;
12359
+ case "positions":
12360
+ positionsOn = message.on;
12361
+ if (!message.on) dropPendingPosition();
12362
+ return;
12247
12363
  case "layers": {
12248
12364
  const before = layersAsked;
12249
12365
  layersAsked = new Set(message.layers);
@@ -12498,7 +12614,7 @@ function callPlace(frames, cwd = process.cwd(), windows = process.platform === "
12498
12614
  function callTitle(zone, channel) {
12499
12615
  const selector = typeof channel?.params?.selector === "string" ? ` ${channel.params.selector}` : "";
12500
12616
  const title = zone.title || `${zone.apiName || "call"}${selector}`;
12501
- return hideSecretsInText(hideTypedText(title)).slice(0, 300);
12617
+ return hideSecretsInText(hideTypedText(title)).slice(0, MAX_POSITION_TITLE);
12502
12618
  }
12503
12619
  function errorText(error) {
12504
12620
  const message = error instanceof Error ? error.message : String(error);
@@ -12512,6 +12628,10 @@ function watchCalls(playwright) {
12512
12628
  const titles = /* @__PURE__ */ new WeakMap();
12513
12629
  instrumentation.addListener({
12514
12630
  onApiCallBegin: (zone, channel) => {
12631
+ if (positionsWanted()) {
12632
+ const place = callPlace(zone.frames);
12633
+ if (place) tellPosition(callTitle(zone, channel), place);
12634
+ }
12515
12635
  if (!runEventsWanted()) return;
12516
12636
  begun.set(zone, Date.now());
12517
12637
  titles.set(zone, callTitle(zone, channel));
@@ -14328,16 +14448,16 @@ var PageReader = class {
14328
14448
  let session = this.sessions.get(page);
14329
14449
  if (!session) {
14330
14450
  session = internalCall(page, async () => {
14331
- const opened2 = await page.context().newCDPSession(page);
14332
- await opened2.send("Performance.enable", { timeDomain: "threadTicks" });
14333
- return opened2;
14451
+ const opened3 = await page.context().newCDPSession(page);
14452
+ await opened3.send("Performance.enable", { timeDomain: "threadTicks" });
14453
+ return opened3;
14334
14454
  }).catch(() => null);
14335
14455
  this.sessions.set(page, session);
14336
14456
  }
14337
- const opened = await session;
14338
- if (!opened) return null;
14457
+ const opened2 = await session;
14458
+ if (!opened2) return null;
14339
14459
  try {
14340
- const result = await internalCall(page, () => opened.send("Performance.getMetrics"));
14460
+ const result = await internalCall(page, () => opened2.send("Performance.getMetrics"));
14341
14461
  const values = new Map((result.metrics ?? []).map((metric) => [metric.name, metric.value]));
14342
14462
  const main = {
14343
14463
  cpuMs: Math.round((values.get("TaskDuration") ?? 0) * 1e3),
@@ -14345,7 +14465,7 @@ var PageReader = class {
14345
14465
  nodes: values.get("Nodes") ?? 0,
14346
14466
  listeners: values.get("JSEventListeners") ?? 0
14347
14467
  };
14348
- const elements = await this.countElements(page, opened);
14468
+ const elements = await this.countElements(page, opened2);
14349
14469
  if (elements !== null) main.elements = elements;
14350
14470
  return main;
14351
14471
  } catch {
@@ -14391,6 +14511,18 @@ var PERSISTENT_CALL = /launchPersistentContext$/;
14391
14511
  var CLOSE_TIMEOUT_MS = 5e3;
14392
14512
  var PAGE_READ_CAP = 50;
14393
14513
  var PAGE_READ_TIMEOUT_MS = 1e3;
14514
+ var callPageListeners = /* @__PURE__ */ new Set();
14515
+ function pageOfCall(object) {
14516
+ for (let owner = object; owner; owner = owner._parent) {
14517
+ if (owner._type === "Page") return owner;
14518
+ if (owner._type === "Frame" && owner._page) return owner._page;
14519
+ }
14520
+ return null;
14521
+ }
14522
+ function onTestCallPage(listener) {
14523
+ callPageListeners.add(listener);
14524
+ return () => callPageListeners.delete(listener);
14525
+ }
14394
14526
  var HOOK_PHASES = /* @__PURE__ */ new Set(["beforeAll", "afterAll", "beforeEach", "afterEach"]);
14395
14527
  var KIND_ORDER = { browser: 0, context: 1, page: 2, request: 3 };
14396
14528
  function relativePath(file, cwd = process.cwd(), windows = process.platform === "win32") {
@@ -14649,6 +14781,7 @@ var ResourceLedger = class {
14649
14781
  }
14650
14782
  if (options?.internal || !options?.frames?.length || TRAFFIC_TYPES.has(String(object._type))) return;
14651
14783
  if (CLOSE_METHODS.has(String(method))) return this.noteClosing(object);
14784
+ this.tellCallPage(object);
14652
14785
  const site = zoneSite(options);
14653
14786
  this.touch(object, site);
14654
14787
  if (result && typeof result.then === "function") {
@@ -14665,6 +14798,7 @@ var ResourceLedger = class {
14665
14798
  const id = info?.waitId;
14666
14799
  if (id === void 0) return;
14667
14800
  if (info?.phase === "before" && !options?.internal && options?.frames?.length) {
14801
+ this.tellCallPage(object);
14668
14802
  if (this.waits.size >= WAITS_CAP) this.waits.clear();
14669
14803
  const site = zoneSite(options);
14670
14804
  this.waits.set(id, { object, site });
@@ -14675,6 +14809,12 @@ var ResourceLedger = class {
14675
14809
  if (waited) this.touch(waited.object, waited.site);
14676
14810
  }
14677
14811
  }
14812
+ /** Tell the listeners of `onTestCallPage` the page a call of the test lands on, when it lands on one. */
14813
+ tellCallPage(object) {
14814
+ if (!callPageListeners.size) return;
14815
+ const page = pageOfCall(object);
14816
+ if (page) for (const listener of callPageListeners) this.guard(() => outsideCalls(() => listener(page)));
14817
+ }
14678
14818
  /**
14679
14819
  * Mark an object, and the page, context and browser it belongs to, used now
14680
14820
  * by the call at `site`. A close that began before it did not end: the
@@ -17018,7 +17158,7 @@ function instrumentPage(page) {
17018
17158
  laneSawPage(page);
17019
17159
  const probeSink = currentSink;
17020
17160
  if (probeSink?.probeItem && !probeSink.probeInterception) {
17021
- void installProbeInterception(page, probeSink.probeItem).then((interception) => {
17161
+ void installProbeInterception(page, probeSink.probeItem, probeSink.baseURL).then((interception) => {
17022
17162
  probeSink.probeInterception = interception;
17023
17163
  }).catch(() => {
17024
17164
  });
@@ -17714,13 +17854,16 @@ var piwiFixtures = {
17714
17854
  observeApiRequests(playwright, apiCallRecorder);
17715
17855
  openLiveView(workerInfo);
17716
17856
  if (liveViewOpen()) trackCalls(playwright);
17717
- if (await openRunChannel(workerInfo, runControl)) {
17857
+ const channel = await openRunChannel(workerInfo, runControl);
17858
+ if (channel) {
17718
17859
  watchCalls(playwright);
17719
17860
  trackCalls(playwright);
17720
17861
  }
17862
+ const unhearCallPages = liveViewOpen() || channel ? onTestCallPage((page) => laneCalled(page)) : () => void 0;
17721
17863
  try {
17722
17864
  await use();
17723
17865
  } finally {
17866
+ unhearCallPages();
17724
17867
  closeLiveView();
17725
17868
  closeRunChannel();
17726
17869
  stopResourceLedger();
@@ -17749,7 +17892,6 @@ var piwiFixtures = {
17749
17892
  await awaitFlakeConditions();
17750
17893
  await maybeStartCodeReach(page);
17751
17894
  lanePage(page);
17752
- liveViewPage(page);
17753
17895
  await use(page);
17754
17896
  const sink = currentSink;
17755
17897
  if (sink) await holdFailure(sink, page);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piwitests/reporter",
3
- "version": "0.71.0",
3
+ "version": "0.73.0",
4
4
  "description": "Playwright reporter that streams results, traces and HTML reports to a Piwi Dashboard instance",
5
5
  "url": "https://github.com/PiwiTests/piwi",
6
6
  "homepage": "https://piwitests.dev",