@piwitests/reporter 0.65.0 → 0.66.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/dist/cli/index.js CHANGED
@@ -602,8 +602,14 @@ function hasBlockingFindings(findings) {
602
602
  var import_node_child_process = require("child_process");
603
603
  var fs3 = __toESM(require("fs"));
604
604
  var import_node_module = require("module");
605
+ var os = __toESM(require("os"));
605
606
  var path5 = __toESM(require("path"));
606
607
  var COULD_NOT_START = 2;
608
+ function childExitCode(code, signal) {
609
+ if (code !== null) return code;
610
+ const number = signal ? os.constants.signals[signal] : void 0;
611
+ return number === void 0 ? COULD_NOT_START : 128 + number;
612
+ }
607
613
  function resolvePlaywrightCli(cwd = process.cwd()) {
608
614
  const require2 = (0, import_node_module.createRequire)(path5.join(cwd, "noop.js"));
609
615
  for (const id of ["playwright/cli", "@playwright/test/cli", "playwright/lib/cli/cli"]) {
@@ -658,7 +664,10 @@ function spawnPlaywright(playwrightArgs2, env, options = {}) {
658
664
  console.error(`${label}: could not start Playwright \u2014 ${err.message}`);
659
665
  done(COULD_NOT_START);
660
666
  });
661
- child.on("exit", (code) => done(code ?? COULD_NOT_START));
667
+ child.on("exit", (code, signal) => {
668
+ if (signal) console.error(`${label}: Playwright was stopped by ${signal}`);
669
+ done(childExitCode(code, signal));
670
+ });
662
671
  });
663
672
  }
664
673
  function runPackageManager(command, args, cwd) {
@@ -797,10 +806,10 @@ var path8 = __toESM(require("path"));
797
806
 
798
807
  // src/internal/config/desktop.ts
799
808
  var fs4 = __toESM(require("fs"));
800
- var os = __toESM(require("os"));
809
+ var os2 = __toESM(require("os"));
801
810
  var path7 = __toESM(require("path"));
802
811
  function defaultDesktopConfigPath() {
803
- return path7.join(os.homedir(), ".piwi", "desktop.json");
812
+ return path7.join(os2.homedir(), ".piwi", "desktop.json");
804
813
  }
805
814
  function processAlive(pid) {
806
815
  try {
@@ -877,6 +886,35 @@ function detectCi(env) {
877
886
  );
878
887
  }
879
888
 
889
+ // ../core/src/rerun-args.ts
890
+ var RERUN_ARGS_ENV = "PIWI_RERUN_ARGS";
891
+ var WHITESPACE = /[ \t\r\n]/;
892
+ function splitRerunArgs(text) {
893
+ const words = [];
894
+ let word = "";
895
+ let inWord = false;
896
+ let quoted2 = false;
897
+ for (const ch of text) {
898
+ if (quoted2) {
899
+ if (ch === '"') quoted2 = false;
900
+ else word += ch;
901
+ } else if (ch === '"') {
902
+ quoted2 = true;
903
+ inWord = true;
904
+ } else if (WHITESPACE.test(ch)) {
905
+ if (inWord) words.push(word);
906
+ word = "";
907
+ inWord = false;
908
+ } else {
909
+ word += ch;
910
+ inWord = true;
911
+ }
912
+ }
913
+ if (quoted2) throw new Error("a double quote is not closed");
914
+ if (inWord) words.push(word);
915
+ return words;
916
+ }
917
+
880
918
  // src/internal/config/env.ts
881
919
  var DEFAULTS = {
882
920
  projectName: "default-project",
@@ -1115,6 +1153,7 @@ function resolveCliConnection(flags, env, dirs, command = "piwi") {
1115
1153
  var EXIT_OK2 = 0;
1116
1154
  var EXIT_RUN_FAILED = 1;
1117
1155
  var EXIT_ERROR2 = 2;
1156
+ var STOPPED_BY_SIGNAL = 128;
1118
1157
  var REQUEST_TIMEOUT_MS = 3e4;
1119
1158
  var USAGE2 = `
1120
1159
  piwi bug \u2014 a bug report's failing test, from the dashboard
@@ -1137,8 +1176,9 @@ Options:
1137
1176
 
1138
1177
  Exit codes: 0 printed or written (and, when run, the test behaved as its
1139
1178
  test.fail() expects: the bug reproduces), 1 the run did not (the bug may be
1140
- fixed, or a step no longer matches the page), 2 the report could not be read
1141
- or the file could not be written.
1179
+ fixed, or a step no longer matches the page), 2 the report could not be read,
1180
+ the file could not be written, or Playwright could not start or was stopped
1181
+ by a signal.
1142
1182
  `.trim();
1143
1183
  var VALUE_FLAGS = /* @__PURE__ */ new Set(["--out", "--server-url", "--api-key"]);
1144
1184
  function readOption2(argv, name) {
@@ -1275,6 +1315,7 @@ ${USAGE2}`);
1275
1315
  if (!args.run) return EXIT_OK2;
1276
1316
  const code = await runPlaywright(file, cwd, args.id, env);
1277
1317
  if (code === EXIT_ERROR2 && !resolvePlaywrightCli(cwd)) return EXIT_ERROR2;
1318
+ if (code >= STOPPED_BY_SIGNAL) return EXIT_ERROR2;
1278
1319
  if (code === 0) {
1279
1320
  console.error(
1280
1321
  args.mode === "commit" ? `piwi bug: the bug reproduces \u2014 the spec fails on it, as test.fail() expects. Commit ${shown}; remove test.fail() with the fix.` : "piwi bug: the spec passed \u2014 the bug does not show here."
@@ -3343,6 +3384,31 @@ function errorMessage(error) {
3343
3384
  return String(error);
3344
3385
  }
3345
3386
 
3387
+ // ../core/src/run-view.ts
3388
+ var MAX_VIEW_FRAME = 384 * 1024;
3389
+ var MAX_VIEW_FRAME_BASE64 = 4 * Math.ceil(MAX_VIEW_FRAME / 3);
3390
+
3391
+ // ../core/src/run-channel.ts
3392
+ var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
3393
+ var RUN_TAKES = [
3394
+ ...RUN_INTENTS,
3395
+ "requests",
3396
+ "mock",
3397
+ "locator",
3398
+ "view",
3399
+ "input",
3400
+ "input-clicks",
3401
+ "pick-at",
3402
+ "agent",
3403
+ "events",
3404
+ "bind",
3405
+ "end",
3406
+ "share"
3407
+ ];
3408
+ var MAX_KEPT_BODY = 256 * 1024;
3409
+ var MAX_REGION_SNAPSHOT = 1024 * 1024;
3410
+ var MAX_AGENT_SNAPSHOT = 1024 * 1024;
3411
+
3346
3412
  // src/internal/support/test-paths.ts
3347
3413
  var path12 = __toESM(require("path"));
3348
3414
 
@@ -4363,7 +4429,7 @@ ${USAGE4}`);
4363
4429
  // src/cli/flake.ts
4364
4430
  var import_node_child_process6 = require("child_process");
4365
4431
  var fs12 = __toESM(require("fs"));
4366
- var os2 = __toESM(require("os"));
4432
+ var os3 = __toESM(require("os"));
4367
4433
  var path17 = __toESM(require("path"));
4368
4434
 
4369
4435
  // ../core/src/error-parse.ts
@@ -4943,7 +5009,7 @@ function printHeader(plan, commit, estimate, budgetMs) {
4943
5009
  out.push("");
4944
5010
  const estimateText = estimate != null ? `up to ${formatDuration(estimate)}` : "unknown (no passing run on record)";
4945
5011
  out.push(`Estimate: ${estimateText} \xB7 budget ${formatDuration(budgetMs)}`);
4946
- out.push(`Lab \xB7 ${os2.hostname()} \xB7 HEAD ${short(commit)} \xB7 ${plan.test.project ?? "default project"} \xB7 retries off`);
5012
+ out.push(`Lab \xB7 ${os3.hostname()} \xB7 HEAD ${short(commit)} \xB7 ${plan.test.project ?? "default project"} \xB7 retries off`);
4947
5013
  if (commitsDiffer(commit, plan.failureCommit)) {
4948
5014
  out.push(`warning: this checkout is ${short(commit)}; the latest failure ran on ${short(plan.failureCommit)}.`);
4949
5015
  }
@@ -4984,7 +5050,7 @@ async function loadPlan(args, commit) {
4984
5050
  const params = new URLSearchParams({
4985
5051
  kind: args.verify ? "verify" : "reproduce",
4986
5052
  source: args.source ?? (process.env.CI ? "ci" : "cli"),
4987
- machine: os2.hostname(),
5053
+ machine: os3.hostname(),
4988
5054
  record: String(args.upload)
4989
5055
  });
4990
5056
  if (commit) params.set("commit", commit);
@@ -5047,7 +5113,7 @@ async function runFlake(argv, runner) {
5047
5113
  if (!args.json) {
5048
5114
  printHeader(plan, commit, estimate, args.budgetMs);
5049
5115
  }
5050
- const dir = fs12.mkdtempSync(path17.join(os2.tmpdir(), "piwi-flake-"));
5116
+ const dir = fs12.mkdtempSync(path17.join(os3.tmpdir(), "piwi-flake-"));
5051
5117
  const log = path17.join(dir, "playwright.log");
5052
5118
  let session;
5053
5119
  try {
@@ -5681,11 +5747,8 @@ function ensureGitignoreEntry(existing, entry = ".env") {
5681
5747
  var fs15 = __toESM(require("fs"));
5682
5748
  var path19 = __toESM(require("path"));
5683
5749
 
5684
- // ../core/src/skill-stamp.ts
5685
- var SKILL_VERSION_KEY = "piwi-version";
5686
- var SKILL_HASH_KEY = "piwi-hash";
5687
- var FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
5688
- function fnv32(input, seed) {
5750
+ // ../core/src/hash.ts
5751
+ function fnv1a32(input, seed = 2166136261) {
5689
5752
  let h = seed >>> 0;
5690
5753
  for (let i = 0; i < input.length; i++) {
5691
5754
  h ^= input.charCodeAt(i);
@@ -5693,8 +5756,13 @@ function fnv32(input, seed) {
5693
5756
  }
5694
5757
  return (h >>> 0).toString(16).padStart(8, "0");
5695
5758
  }
5759
+
5760
+ // ../core/src/skill-stamp.ts
5761
+ var SKILL_VERSION_KEY = "piwi-version";
5762
+ var SKILL_HASH_KEY = "piwi-hash";
5763
+ var FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
5696
5764
  function hash16(input) {
5697
- return fnv32(input, 2166136261) + fnv32(input, 16777619);
5765
+ return fnv1a32(input) + fnv1a32(input, 16777619);
5698
5766
  }
5699
5767
  function withoutHashLine(markdown) {
5700
5768
  return markdown.replace(new RegExp(`^${SKILL_HASH_KEY}:.*\\r?\\n`, "m"), "");
@@ -7322,7 +7390,9 @@ Behavior:
7322
7390
  --json Print the full resolution as JSON (select only)
7323
7391
  -h, --help Show this help
7324
7392
 
7325
- Exit codes: 0 ok, 1 the test run failed (run only), 2 could not resolve.
7393
+ Exit codes: 0 ok, 1 the test run failed (run only), 128 plus the signal's
7394
+ number when the runner stops Playwright (run only; 143 for SIGTERM),
7395
+ 2 could not resolve or Playwright could not start.
7326
7396
  `.trim();
7327
7397
  var IMPACT_KEY = "impact";
7328
7398
  var NOTHING_TO_RUN_ARGS = ["--pass-with-no-tests", "--grep-invert", "."];
@@ -8169,7 +8239,7 @@ async function runPreflight(argv, env = process.env, cwd = process.cwd()) {
8169
8239
 
8170
8240
  // src/cli/probe.ts
8171
8241
  var fs20 = __toESM(require("fs"));
8172
- var os3 = __toESM(require("os"));
8242
+ var os4 = __toESM(require("os"));
8173
8243
  var path24 = __toESM(require("path"));
8174
8244
  var EXIT_OK8 = 0;
8175
8245
  var EXIT_ERROR9 = 2;
@@ -8251,7 +8321,7 @@ async function runProbe(argv) {
8251
8321
  return EXIT_OK8;
8252
8322
  }
8253
8323
  console.error(`piwi probe: ${plan.items.length} pair(s) to probe (budget ${plan.budget}).`);
8254
- const dir = fs20.mkdtempSync(path24.join(os3.tmpdir(), "piwi-probe-"));
8324
+ const dir = fs20.mkdtempSync(path24.join(os4.tmpdir(), "piwi-probe-"));
8255
8325
  const planFile = path24.join(dir, "plan.json");
8256
8326
  const resultsFile = path24.join(dir, "results.jsonl");
8257
8327
  const runOutputFile = path24.join(dir, "run.json");
@@ -8451,8 +8521,51 @@ async function runQualityReport(argv) {
8451
8521
  }
8452
8522
  }
8453
8523
 
8454
- // src/cli/index.ts
8524
+ // src/cli/rerun.ts
8525
+ var EXIT_ERROR11 = 2;
8455
8526
  var USAGE13 = `
8527
+ piwi rerun \u2014 run the tests a CI re-run from the dashboard asked for
8528
+
8529
+ Usage:
8530
+ npx @piwitests/reporter rerun [--] [playwright args]
8531
+
8532
+ Runs playwright test with the arguments of ${RERUN_ARGS_ENV}, split as the
8533
+ dashboard quoted them and never read by a shell, followed by the arguments
8534
+ given here (after an optional --). Declare ${RERUN_ARGS_ENV} in the CI job: set and empty, the whole
8535
+ suite runs; unset, the command fails rather than run it.
8536
+
8537
+ Options:
8538
+ -h, --help Show this help (as the first argument only)
8539
+
8540
+ Exit codes: Playwright's own, 128 plus the signal's number when the runner
8541
+ stops Playwright (143 for SIGTERM), or 2 when ${RERUN_ARGS_ENV} is unset or
8542
+ cannot be read, or Playwright cannot start.
8543
+ `.trim();
8544
+ async function runRerun(argv, env = process.env) {
8545
+ if (argv[0] === "-h" || argv[0] === "--help") {
8546
+ console.log(USAGE13);
8547
+ return 0;
8548
+ }
8549
+ const text = env[RERUN_ARGS_ENV];
8550
+ if (text === void 0) {
8551
+ console.error(
8552
+ `piwi rerun: ${RERUN_ARGS_ENV} is not set. Declare it in the job (a pipeline variable or build parameter) so the dashboard's arguments reach it.`
8553
+ );
8554
+ return EXIT_ERROR11;
8555
+ }
8556
+ let words;
8557
+ try {
8558
+ words = splitRerunArgs(text);
8559
+ } catch (e) {
8560
+ console.error(`piwi rerun: ${RERUN_ARGS_ENV} cannot be read: ${e.message}.`);
8561
+ return EXIT_ERROR11;
8562
+ }
8563
+ const extra = argv[0] === "--" ? argv.slice(1) : argv;
8564
+ return spawnPlaywright([...words, ...extra], env, { command: "piwi rerun" });
8565
+ }
8566
+
8567
+ // src/cli/index.ts
8568
+ var USAGE14 = `
8456
8569
  piwi \u2014 companion commands for the Piwi Dashboard reporter
8457
8570
 
8458
8571
  Usage:
@@ -8466,6 +8579,7 @@ Commands:
8466
8579
  coverage Upload a unit-test (or other) coverage report of a commit (coverage upload)
8467
8580
  select Print the Playwright args for a saved test selection
8468
8581
  run Run a saved test selection with playwright test
8582
+ rerun Run the tests a CI re-run from the dashboard asked for (PIWI_RERUN_ARGS)
8469
8583
  probe Run the dashboard's probe plan and record what the suite noticed
8470
8584
  flake Make a flaky test fail on demand under its suspects' conditions, then verify the fix
8471
8585
  ai Manage committed natural-language AI-step artifacts
@@ -8494,6 +8608,8 @@ async function main() {
8494
8608
  return runSelect(rest);
8495
8609
  case "run":
8496
8610
  return runRun(rest);
8611
+ case "rerun":
8612
+ return runRerun(rest);
8497
8613
  case "probe":
8498
8614
  return runProbe(rest);
8499
8615
  case "flake":
@@ -8509,12 +8625,12 @@ async function main() {
8509
8625
  case void 0:
8510
8626
  case "-h":
8511
8627
  case "--help":
8512
- console.log(USAGE13);
8628
+ console.log(USAGE14);
8513
8629
  return 0;
8514
8630
  default:
8515
8631
  console.error(`piwi: unknown command "${command}"
8516
8632
  `);
8517
- console.error(USAGE13);
8633
+ console.error(USAGE14);
8518
8634
  return 2;
8519
8635
  }
8520
8636
  }
@@ -713,6 +713,31 @@ function resolveShardInfo(config, env = process.env) {
713
713
  var import_node_child_process = require("child_process");
714
714
  var import_node_util = require("util");
715
715
 
716
+ // ../core/src/run-view.ts
717
+ var MAX_VIEW_FRAME = 384 * 1024;
718
+ var MAX_VIEW_FRAME_BASE64 = 4 * Math.ceil(MAX_VIEW_FRAME / 3);
719
+
720
+ // ../core/src/run-channel.ts
721
+ var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
722
+ var RUN_TAKES = [
723
+ ...RUN_INTENTS,
724
+ "requests",
725
+ "mock",
726
+ "locator",
727
+ "view",
728
+ "input",
729
+ "input-clicks",
730
+ "pick-at",
731
+ "agent",
732
+ "events",
733
+ "bind",
734
+ "end",
735
+ "share"
736
+ ];
737
+ var MAX_KEPT_BODY = 256 * 1024;
738
+ var MAX_REGION_SNAPSHOT = 1024 * 1024;
739
+ var MAX_AGENT_SNAPSHOT = 1024 * 1024;
740
+
716
741
  // src/internal/support/test-paths.ts
717
742
  var path3 = __toESM(require("path"));
718
743
  function configDirFromConfig(config) {
package/dist/index.js CHANGED
@@ -1275,6 +1275,7 @@ var RUN_ORIGIN_KINDS = [
1275
1275
  "import"
1276
1276
  ];
1277
1277
  var RUN_ORIGIN_METADATA_KEY = "piwiOrigin";
1278
+ var RUN_REF_METADATA_KEY = "piwiRunRef";
1278
1279
  var RUN_ORIGIN_REF_MAX_LENGTH = 200;
1279
1280
  var RUN_ORIGIN_REF = /^[A-Za-z0-9._:/#@-]+$/;
1280
1281
  function isRunOriginKind(value) {
@@ -2885,7 +2886,7 @@ var FileHandler = class {
2885
2886
  }
2886
2887
  };
2887
2888
  function safeFileName(name) {
2888
- return name.replace(/[^\w.-]+/g, "-").replace(/^-+|-+$/g, "") || "attachment";
2889
+ return name.replace(/[^\w.-]+/g, "-").replace(/\.{2,}/g, ".").replace(/^[-.]+|[-.]+$/g, "") || "attachment";
2889
2890
  }
2890
2891
  function formatMiB(bytes) {
2891
2892
  return `${Math.round(bytes / (1024 * 1024) * 10) / 10} MiB`;
@@ -2990,6 +2991,11 @@ function resolveRunOrigin(env, warn) {
2990
2991
  const ref = parseRunOriginRef(env[PIWI_ORIGIN_ENV.ref]);
2991
2992
  return ref === void 0 ? { kind } : { kind, ref };
2992
2993
  }
2994
+ function resolveRunRef(env) {
2995
+ const kind = env[PIWI_ORIGIN_ENV.kind]?.trim();
2996
+ if (!kind || !isRunOriginKind(kind)) return void 0;
2997
+ return parseRunOriginRef(env[RUN_REF_ENV]);
2998
+ }
2993
2999
  function normalizeRef(ref) {
2994
3000
  return ref.replace(/^refs\/heads\//, "");
2995
3001
  }
@@ -3003,6 +3009,8 @@ var MetadataCollector = class {
3003
3009
  workingDir: configDirFromConfig(config),
3004
3010
  [RUN_ORIGIN_METADATA_KEY]: resolveRunOrigin(process.env, (message) => this.logger.warn(message))
3005
3011
  };
3012
+ const runRef = resolveRunRef(process.env);
3013
+ if (runRef) metadata[RUN_REF_METADATA_KEY] = runRef;
3006
3014
  if (options.projectDescription) metadata.projectDescription = options.projectDescription;
3007
3015
  if (options.relatedIssue) metadata.relatedIssue = options.relatedIssue;
3008
3016
  if (options.ciInfo) metadata.ciInfo = options.ciInfo;
@@ -3044,7 +3052,8 @@ var MetadataCollector = class {
3044
3052
  if (project) {
3045
3053
  const use = project.use ?? {};
3046
3054
  const config = { projectName: project.name };
3047
- if (use.browserName) config.browserName = use.browserName;
3055
+ const browserName = use.browserName ?? use.defaultBrowserType;
3056
+ if (browserName) config.browserName = browserName;
3048
3057
  if (use.channel) config.channel = use.channel;
3049
3058
  if (use.viewport) config.viewport = { width: use.viewport.width, height: use.viewport.height };
3050
3059
  if (use.deviceScaleFactor != null) config.deviceScaleFactor = use.deviceScaleFactor;
@@ -23665,7 +23674,8 @@ var piwiFixtures = {
23665
23674
  project: testInfo.project.name
23666
23675
  });
23667
23676
  if (role) {
23668
- const browserName = testInfo.project.use?.browserName ?? null;
23677
+ const use2 = testInfo.project.use;
23678
+ const browserName = use2?.browserName ?? use2?.defaultBrowserType ?? null;
23669
23679
  sink.flake = { plan, role, startedAt: Date.now(), browserName, conditions: null };
23670
23680
  }
23671
23681
  }
@@ -13585,7 +13585,8 @@ var piwiFixtures = {
13585
13585
  project: testInfo.project.name
13586
13586
  });
13587
13587
  if (role) {
13588
- const browserName = testInfo.project.use?.browserName ?? null;
13588
+ const use2 = testInfo.project.use;
13589
+ const browserName = use2?.browserName ?? use2?.defaultBrowserType ?? null;
13589
13590
  sink.flake = { plan, role, startedAt: Date.now(), browserName, conditions: null };
13590
13591
  }
13591
13592
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piwitests/reporter",
3
- "version": "0.65.0",
3
+ "version": "0.66.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",