@plune-ai/playwright 0.2.6 → 0.2.8

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/README.md CHANGED
@@ -38,7 +38,7 @@ That is the whole setup. Options, if you want them:
38
38
  ```
39
39
 
40
40
  Keep the token out of this list: it comes from `PLUNE_TOKEN` or what `plune login` saved. Playwright
41
- writes every reporter's options into its JSON and blob reports, so a token set here travels with any
41
+ writes every reporter's options into its JSON report, so a token set here travels with any such
42
42
  report a CI job keeps as an artifact.
43
43
 
44
44
  ## From CI, without editing the config
package/dist/index.cjs CHANGED
@@ -152,7 +152,11 @@ function createClient(opts) {
152
152
  }
153
153
  if (res.ok) {
154
154
  if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
155
- return { ok: true, status: res.status, body: await res.json() };
155
+ try {
156
+ return { ok: true, status: res.status, body: await res.json() };
157
+ } catch {
158
+ return { ok: false, kind: "other", status: res.status, detail: "the answer was not JSON" };
159
+ }
156
160
  }
157
161
  const detail = scrub(await detailOf(res));
158
162
  const kind = classify(res.status);
@@ -248,6 +252,7 @@ var BATCH_DEFAULT = 100;
248
252
  var EXPECTED_MAX = 1e4;
249
253
  var KEY_MAX = 1024;
250
254
  var TITLE_MAX = 300;
255
+ var COUNTED = ["accepted", "duplicate", "conflict", "rejected"];
251
256
  function boundKey(key) {
252
257
  if (key.value.length <= KEY_MAX) return key;
253
258
  const digest = (0, import_crypto.createHash)("sha256").update(key.value).digest("hex").slice(0, 16);
@@ -358,11 +363,13 @@ async function startRun(passed, declared2) {
358
363
  "/v1/test-cases/resolve",
359
364
  { keys: part }
360
365
  );
361
- if (!out.ok) {
362
- log(`plune: could not look up test cases (${out.detail || out.kind}).`);
366
+ if (!out.ok || !Array.isArray(out.body?.results)) {
367
+ log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
363
368
  return;
364
369
  }
365
- for (const row of out.body.results) resolved.set(row.key.value, row.testCaseId);
370
+ for (const row of out.body.results) {
371
+ if (typeof row?.key?.value === "string") resolved.set(row.key.value, row.testCaseId);
372
+ }
366
373
  }
367
374
  }
368
375
  if (!offline) {
@@ -399,12 +406,13 @@ async function startRun(passed, declared2) {
399
406
  title: defaultRunTitle(),
400
407
  ...described
401
408
  });
402
- if (start.ok) {
409
+ if (start.ok && typeof start.body?.run?.id === "string") {
403
410
  runId = start.body.run.id;
404
411
  joined = start.status === 200;
405
412
  warnIfDropped(described, start.body.run, log);
406
413
  } else {
407
- log(`plune: could not start the run (${start.detail || start.kind}). Results will be written to ${fallbackPath}.`);
414
+ const why = start.ok ? "the answer had no run" : start.detail || start.kind;
415
+ log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
408
416
  }
409
417
  }
410
418
  function matchFor(result) {
@@ -439,15 +447,15 @@ async function startRun(passed, declared2) {
439
447
  discovered: batch,
440
448
  runId
441
449
  });
442
- if (!out.ok) {
450
+ if (!out.ok || !Array.isArray(out.body?.results)) {
443
451
  stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
444
452
  log(
445
- `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.detail || out.kind}).`
453
+ `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
446
454
  );
447
455
  return;
448
456
  }
449
- stats.offered += out.body.results.filter((r) => r.outcome === "queued").length;
450
- stats.created += out.body.results.filter((r) => r.outcome === "created").length;
457
+ stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
458
+ stats.created += out.body.results.filter((r) => r?.outcome === "created").length;
451
459
  }
452
460
  }
453
461
  async function flush() {
@@ -486,15 +494,16 @@ async function startRun(passed, declared2) {
486
494
  const out = await client.post(`/v1/runs/${runId}/results`, {
487
495
  results: part
488
496
  });
489
- if (out.ok) {
490
- stats.accepted += out.body.counts.accepted ?? 0;
491
- stats.duplicate += out.body.counts.duplicate ?? 0;
492
- stats.conflict += out.body.counts.conflict ?? 0;
493
- stats.rejected += out.body.counts.rejected ?? 0;
497
+ const counts = out.ok ? out.body?.counts : void 0;
498
+ const told = COUNTED.filter((k) => typeof counts?.[k] === "number");
499
+ if (told.length > 0) {
500
+ for (const k of told) stats[k] += counts[k];
494
501
  progress();
495
502
  continue;
496
503
  }
497
- if (out.kind === "auth") {
504
+ if (out.ok) {
505
+ log("plune: could not send results (the answer carried no counts).");
506
+ } else if (out.kind === "auth") {
498
507
  log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
499
508
  offline = true;
500
509
  } else if (out.kind === "conflict") {
@@ -552,7 +561,7 @@ async function startRun(passed, declared2) {
552
561
  ...reason !== void 0 ? { reason } : {}
553
562
  });
554
563
  if (!out.ok) log(`plune: could not close run ${runId} (${out.detail || out.kind}).`);
555
- else if (typeof out.body.detached === "number" && out.body.detached > 0) {
564
+ else if (typeof out.body?.detached === "number" && out.body.detached > 0) {
556
565
  log(`plune: ${out.body.detached} test case(s) marked detached \u2014 this full run no longer reports them.`);
557
566
  }
558
567
  }
@@ -579,12 +588,13 @@ function resultKey(testId, retry) {
579
588
  const plain = `${testId}#${retry}`;
580
589
  return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
581
590
  }
582
- function failureOf(attempt) {
591
+ function failureOf(attempt, home = (0, import_os2.homedir)()) {
583
592
  const error = chosen(attempt);
584
- const headline = error === void 0 ? void 0 : firstLine(error.text);
593
+ const line = error === void 0 ? void 0 : firstLine(machineless(error.text, attempt.repoRoot, home));
594
+ const headline = line !== void 0 && jsonBytes(line) <= HEADLINE_LIMIT ? line : void 0;
585
595
  const steps = chainOf(attempt.steps);
586
596
  const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
587
- const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && a.name !== "" && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => contentType === void 0 ? { name } : { name, contentType });
597
+ const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => ({ name: fileNameOf(name), ...contentType ? { contentType } : {} })).filter((a) => a.name !== "");
588
598
  const ciUrl = webLink(attempt.buildHref);
589
599
  const failure = {
590
600
  ...headline !== void 0 ? { headline } : {},
@@ -602,30 +612,38 @@ function repoRootOf(dir, stopAt) {
602
612
  }
603
613
  }
604
614
  function errorContextOf(attempt, home = (0, import_os2.homedir)()) {
605
- let text = (0, import_util.stripVTControlCharacters)(
606
- attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n")
607
- ).replaceAll("\x1B", "");
608
- const root = attempt.repoRoot === void 0 ? void 0 : pathIn(attempt.repoRoot);
609
- if (root !== void 0) text = text.replace(new RegExp(`${root.source}[\\\\/]`, root.flags), "");
615
+ const text = attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n");
616
+ return cut(machineless(text, attempt.repoRoot, home));
617
+ }
618
+ function machineless(raw, repoRoot, home) {
619
+ let text = (0, import_util.stripVTControlCharacters)(raw).replaceAll("\x1B", "");
620
+ const root = repoRoot === void 0 ? void 0 : pathIn(repoRoot);
621
+ if (root !== void 0) text = text.replace(new RegExp(`${PATH_START}${root.source}[\\\\/]+`, root.flags), "");
610
622
  const own = pathIn(home);
611
- if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
612
- if (attempt.repoRoot === void 0) text = text.replace(ANY_HOME, "~");
613
- return cut(text);
623
+ if (own !== void 0) text = text.replace(new RegExp(`${PATH_START}${own.source}(?![\\w.-])`, own.flags), "~");
624
+ if (repoRoot === void 0) text = text.replace(ANY_HOME, "~");
625
+ return text;
614
626
  }
627
+ var PATH_START = "(?<![\\w.~%/\\\\-])";
615
628
  var TEXT_LIMIT = 524288;
616
- var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]Users[\\/])[^\\/\s'"`:*?<>|]+/g;
629
+ var HEADLINE_LIMIT = 8 * 1024;
630
+ var jsonBytes = (text) => Buffer.byteLength(JSON.stringify(text)) - 2;
631
+ var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:(?:file|webpack|webpack-internal):(?:\\*\/){2,3})?(?:\\*\/home\\*\/|\\*\/Users\\*\/|[A-Za-z]:[\\/]+Users[\\/]+)[^\\/\s'"`:*?<>|]+/g;
617
632
  function pathIn(path3) {
618
633
  const parts = path3.split(/[\\/]+/);
619
634
  while (parts.length > 1 && parts.at(-1) === "") parts.pop();
620
635
  if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
621
- const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
622
- return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
636
+ const joined = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
637
+ const escaped = /^\/(?!\/)/.test(path3) ? joined.replace("[\\\\/]+", "\\\\*\\/") : joined;
638
+ const url = "(?:(?:file|webpack|webpack-internal):(?:\\\\*\\/){2,3})?";
639
+ return new RegExp(`${url}${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
623
640
  }
641
+ var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
624
642
  function cut(text) {
625
- if (Buffer.byteLength(text) <= TEXT_LIMIT) return text;
643
+ if (jsonBytes(text) <= TEXT_LIMIT) return text;
626
644
  const lines = text.split("\n");
627
- const size = lines.map((line) => Buffer.byteLength(line) + 1);
628
- const budget = TEXT_LIMIT - Buffer.byteLength(omitted(lines.length));
645
+ const size = lines.map((line) => jsonBytes(line) + 2);
646
+ const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
629
647
  let used = 0;
630
648
  let head = 0;
631
649
  let tail = lines.length;
@@ -637,6 +655,7 @@ var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
637
655
  var METADATA_TYPE = "application/plune.metadata+json";
638
656
  var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
639
657
  var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
658
+ var FRAME_MAX = 8192;
640
659
  var firstLine = (text) => (0, import_util.stripVTControlCharacters)(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
641
660
  function chosen({ status, errors }) {
642
661
  if (status === "timedOut") {
@@ -656,6 +675,7 @@ function placeOf(error, testFile) {
656
675
  const own = normal(testFile);
657
676
  let first;
658
677
  for (const line of (0, import_util.stripVTControlCharacters)(error.text).split("\n")) {
678
+ if (line.length > FRAME_MAX) continue;
659
679
  const frame = FRAME.exec(line);
660
680
  if (frame === null) continue;
661
681
  const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
@@ -666,7 +686,11 @@ function placeOf(error, testFile) {
666
686
  }
667
687
  function fileOf(raw) {
668
688
  if (!raw.startsWith("file://")) return raw;
669
- const path3 = decodeURIComponent(raw.slice("file://".length));
689
+ let path3 = raw.slice("file://".length);
690
+ try {
691
+ path3 = decodeURIComponent(path3);
692
+ } catch {
693
+ }
670
694
  return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
671
695
  }
672
696
  var normal = (path3) => import_path2.posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
@@ -681,13 +705,7 @@ function fromRoot(place, root) {
681
705
  return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
682
706
  }
683
707
  function webLink(href) {
684
- if (href === void 0) return void 0;
685
- try {
686
- const { protocol } = new URL(href);
687
- return protocol === "http:" || protocol === "https:" ? href : void 0;
688
- } catch {
689
- return void 0;
690
- }
708
+ return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
691
709
  }
692
710
 
693
711
  // src/index.ts
@@ -860,7 +878,7 @@ var PluneReporter = class {
860
878
  onTestEnd(test, result) {
861
879
  const session = this.open();
862
880
  this.chain = this.chain.then(async () => {
863
- (await session).add(pendingFrom(test, result, this.context));
881
+ await (await session).add(pendingFrom(test, result, this.context));
864
882
  }).catch((err) => this.giveUp(err));
865
883
  }
866
884
  async onEnd(_result) {
package/dist/index.js CHANGED
@@ -118,7 +118,11 @@ function createClient(opts) {
118
118
  }
119
119
  if (res.ok) {
120
120
  if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
121
- return { ok: true, status: res.status, body: await res.json() };
121
+ try {
122
+ return { ok: true, status: res.status, body: await res.json() };
123
+ } catch {
124
+ return { ok: false, kind: "other", status: res.status, detail: "the answer was not JSON" };
125
+ }
122
126
  }
123
127
  const detail = scrub(await detailOf(res));
124
128
  const kind = classify(res.status);
@@ -214,6 +218,7 @@ var BATCH_DEFAULT = 100;
214
218
  var EXPECTED_MAX = 1e4;
215
219
  var KEY_MAX = 1024;
216
220
  var TITLE_MAX = 300;
221
+ var COUNTED = ["accepted", "duplicate", "conflict", "rejected"];
217
222
  function boundKey(key) {
218
223
  if (key.value.length <= KEY_MAX) return key;
219
224
  const digest = createHash("sha256").update(key.value).digest("hex").slice(0, 16);
@@ -324,11 +329,13 @@ async function startRun(passed, declared2) {
324
329
  "/v1/test-cases/resolve",
325
330
  { keys: part }
326
331
  );
327
- if (!out.ok) {
328
- log(`plune: could not look up test cases (${out.detail || out.kind}).`);
332
+ if (!out.ok || !Array.isArray(out.body?.results)) {
333
+ log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
329
334
  return;
330
335
  }
331
- for (const row of out.body.results) resolved.set(row.key.value, row.testCaseId);
336
+ for (const row of out.body.results) {
337
+ if (typeof row?.key?.value === "string") resolved.set(row.key.value, row.testCaseId);
338
+ }
332
339
  }
333
340
  }
334
341
  if (!offline) {
@@ -365,12 +372,13 @@ async function startRun(passed, declared2) {
365
372
  title: defaultRunTitle(),
366
373
  ...described
367
374
  });
368
- if (start.ok) {
375
+ if (start.ok && typeof start.body?.run?.id === "string") {
369
376
  runId = start.body.run.id;
370
377
  joined = start.status === 200;
371
378
  warnIfDropped(described, start.body.run, log);
372
379
  } else {
373
- log(`plune: could not start the run (${start.detail || start.kind}). Results will be written to ${fallbackPath}.`);
380
+ const why = start.ok ? "the answer had no run" : start.detail || start.kind;
381
+ log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
374
382
  }
375
383
  }
376
384
  function matchFor(result) {
@@ -405,15 +413,15 @@ async function startRun(passed, declared2) {
405
413
  discovered: batch,
406
414
  runId
407
415
  });
408
- if (!out.ok) {
416
+ if (!out.ok || !Array.isArray(out.body?.results)) {
409
417
  stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
410
418
  log(
411
- `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.detail || out.kind}).`
419
+ `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
412
420
  );
413
421
  return;
414
422
  }
415
- stats.offered += out.body.results.filter((r) => r.outcome === "queued").length;
416
- stats.created += out.body.results.filter((r) => r.outcome === "created").length;
423
+ stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
424
+ stats.created += out.body.results.filter((r) => r?.outcome === "created").length;
417
425
  }
418
426
  }
419
427
  async function flush() {
@@ -452,15 +460,16 @@ async function startRun(passed, declared2) {
452
460
  const out = await client.post(`/v1/runs/${runId}/results`, {
453
461
  results: part
454
462
  });
455
- if (out.ok) {
456
- stats.accepted += out.body.counts.accepted ?? 0;
457
- stats.duplicate += out.body.counts.duplicate ?? 0;
458
- stats.conflict += out.body.counts.conflict ?? 0;
459
- stats.rejected += out.body.counts.rejected ?? 0;
463
+ const counts = out.ok ? out.body?.counts : void 0;
464
+ const told = COUNTED.filter((k) => typeof counts?.[k] === "number");
465
+ if (told.length > 0) {
466
+ for (const k of told) stats[k] += counts[k];
460
467
  progress();
461
468
  continue;
462
469
  }
463
- if (out.kind === "auth") {
470
+ if (out.ok) {
471
+ log("plune: could not send results (the answer carried no counts).");
472
+ } else if (out.kind === "auth") {
464
473
  log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
465
474
  offline = true;
466
475
  } else if (out.kind === "conflict") {
@@ -518,7 +527,7 @@ async function startRun(passed, declared2) {
518
527
  ...reason !== void 0 ? { reason } : {}
519
528
  });
520
529
  if (!out.ok) log(`plune: could not close run ${runId} (${out.detail || out.kind}).`);
521
- else if (typeof out.body.detached === "number" && out.body.detached > 0) {
530
+ else if (typeof out.body?.detached === "number" && out.body.detached > 0) {
522
531
  log(`plune: ${out.body.detached} test case(s) marked detached \u2014 this full run no longer reports them.`);
523
532
  }
524
533
  }
@@ -545,12 +554,13 @@ function resultKey(testId, retry) {
545
554
  const plain = `${testId}#${retry}`;
546
555
  return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
547
556
  }
548
- function failureOf(attempt) {
557
+ function failureOf(attempt, home = homedir2()) {
549
558
  const error = chosen(attempt);
550
- const headline = error === void 0 ? void 0 : firstLine(error.text);
559
+ const line = error === void 0 ? void 0 : firstLine(machineless(error.text, attempt.repoRoot, home));
560
+ const headline = line !== void 0 && jsonBytes(line) <= HEADLINE_LIMIT ? line : void 0;
551
561
  const steps = chainOf(attempt.steps);
552
562
  const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
553
- const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && a.name !== "" && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => contentType === void 0 ? { name } : { name, contentType });
563
+ const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => ({ name: fileNameOf(name), ...contentType ? { contentType } : {} })).filter((a) => a.name !== "");
554
564
  const ciUrl = webLink(attempt.buildHref);
555
565
  const failure = {
556
566
  ...headline !== void 0 ? { headline } : {},
@@ -568,30 +578,38 @@ function repoRootOf(dir, stopAt) {
568
578
  }
569
579
  }
570
580
  function errorContextOf(attempt, home = homedir2()) {
571
- let text = stripVTControlCharacters(
572
- attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n")
573
- ).replaceAll("\x1B", "");
574
- const root = attempt.repoRoot === void 0 ? void 0 : pathIn(attempt.repoRoot);
575
- if (root !== void 0) text = text.replace(new RegExp(`${root.source}[\\\\/]`, root.flags), "");
581
+ const text = attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n");
582
+ return cut(machineless(text, attempt.repoRoot, home));
583
+ }
584
+ function machineless(raw, repoRoot, home) {
585
+ let text = stripVTControlCharacters(raw).replaceAll("\x1B", "");
586
+ const root = repoRoot === void 0 ? void 0 : pathIn(repoRoot);
587
+ if (root !== void 0) text = text.replace(new RegExp(`${PATH_START}${root.source}[\\\\/]+`, root.flags), "");
576
588
  const own = pathIn(home);
577
- if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
578
- if (attempt.repoRoot === void 0) text = text.replace(ANY_HOME, "~");
579
- return cut(text);
589
+ if (own !== void 0) text = text.replace(new RegExp(`${PATH_START}${own.source}(?![\\w.-])`, own.flags), "~");
590
+ if (repoRoot === void 0) text = text.replace(ANY_HOME, "~");
591
+ return text;
580
592
  }
593
+ var PATH_START = "(?<![\\w.~%/\\\\-])";
581
594
  var TEXT_LIMIT = 524288;
582
- var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]Users[\\/])[^\\/\s'"`:*?<>|]+/g;
595
+ var HEADLINE_LIMIT = 8 * 1024;
596
+ var jsonBytes = (text) => Buffer.byteLength(JSON.stringify(text)) - 2;
597
+ var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:(?:file|webpack|webpack-internal):(?:\\*\/){2,3})?(?:\\*\/home\\*\/|\\*\/Users\\*\/|[A-Za-z]:[\\/]+Users[\\/]+)[^\\/\s'"`:*?<>|]+/g;
583
598
  function pathIn(path3) {
584
599
  const parts = path3.split(/[\\/]+/);
585
600
  while (parts.length > 1 && parts.at(-1) === "") parts.pop();
586
601
  if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
587
- const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
588
- return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
602
+ const joined = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
603
+ const escaped = /^\/(?!\/)/.test(path3) ? joined.replace("[\\\\/]+", "\\\\*\\/") : joined;
604
+ const url = "(?:(?:file|webpack|webpack-internal):(?:\\\\*\\/){2,3})?";
605
+ return new RegExp(`${url}${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
589
606
  }
607
+ var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
590
608
  function cut(text) {
591
- if (Buffer.byteLength(text) <= TEXT_LIMIT) return text;
609
+ if (jsonBytes(text) <= TEXT_LIMIT) return text;
592
610
  const lines = text.split("\n");
593
- const size = lines.map((line) => Buffer.byteLength(line) + 1);
594
- const budget = TEXT_LIMIT - Buffer.byteLength(omitted(lines.length));
611
+ const size = lines.map((line) => jsonBytes(line) + 2);
612
+ const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
595
613
  let used = 0;
596
614
  let head = 0;
597
615
  let tail = lines.length;
@@ -603,6 +621,7 @@ var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
603
621
  var METADATA_TYPE = "application/plune.metadata+json";
604
622
  var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
605
623
  var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
624
+ var FRAME_MAX = 8192;
606
625
  var firstLine = (text) => stripVTControlCharacters(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
607
626
  function chosen({ status, errors }) {
608
627
  if (status === "timedOut") {
@@ -622,6 +641,7 @@ function placeOf(error, testFile) {
622
641
  const own = normal(testFile);
623
642
  let first;
624
643
  for (const line of stripVTControlCharacters(error.text).split("\n")) {
644
+ if (line.length > FRAME_MAX) continue;
625
645
  const frame = FRAME.exec(line);
626
646
  if (frame === null) continue;
627
647
  const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
@@ -632,7 +652,11 @@ function placeOf(error, testFile) {
632
652
  }
633
653
  function fileOf(raw) {
634
654
  if (!raw.startsWith("file://")) return raw;
635
- const path3 = decodeURIComponent(raw.slice("file://".length));
655
+ let path3 = raw.slice("file://".length);
656
+ try {
657
+ path3 = decodeURIComponent(path3);
658
+ } catch {
659
+ }
636
660
  return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
637
661
  }
638
662
  var normal = (path3) => posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
@@ -647,13 +671,7 @@ function fromRoot(place, root) {
647
671
  return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
648
672
  }
649
673
  function webLink(href) {
650
- if (href === void 0) return void 0;
651
- try {
652
- const { protocol } = new URL(href);
653
- return protocol === "http:" || protocol === "https:" ? href : void 0;
654
- } catch {
655
- return void 0;
656
- }
674
+ return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
657
675
  }
658
676
 
659
677
  // src/index.ts
@@ -826,7 +844,7 @@ var PluneReporter = class {
826
844
  onTestEnd(test, result) {
827
845
  const session = this.open();
828
846
  this.chain = this.chain.then(async () => {
829
- (await session).add(pendingFrom(test, result, this.context));
847
+ await (await session).add(pendingFrom(test, result, this.context));
830
848
  }).catch((err) => this.giveUp(err));
831
849
  }
832
850
  async onEnd(_result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plune-ai/playwright",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Report Playwright results to Plune — a reporter and, later, a test importer.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -38,7 +38,7 @@
38
38
  "tsup": "^8.0.0",
39
39
  "typescript": "^5.4.0",
40
40
  "vitest": "^1.6.0",
41
- "@plune-ai/cli": "0.14.0"
41
+ "@plune-ai/cli": "0.14.2"
42
42
  },
43
43
  "repository": {
44
44
  "type": "git",