@plune-ai/playwright 0.7.5 → 0.8.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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/index.ts
2
2
  import { readFileSync as readFileSync3 } from "fs";
3
3
  import { resolve as resolve2 } from "path";
4
- import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
4
+ import { stripVTControlCharacters as stripVTControlCharacters3 } from "util";
5
5
 
6
6
  // ../../dist/reporter-core.js
7
7
  import { createHash as createHash2, randomUUID } from "crypto";
@@ -407,7 +407,7 @@ function failureOf(attempt, home = homedir2()) {
407
407
  const headline = line !== void 0 && jsonBytes(line) <= HEADLINE_LIMIT ? line : void 0;
408
408
  const steps = chainOf(attempt.steps);
409
409
  const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
410
- 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 !== "");
410
+ const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && !a.name.startsWith("_") && !READ_NOT_KEPT.has(a.contentType ?? "")).map(({ name, contentType }) => ({ name: fileNameOf(name), ...contentType ? { contentType } : {} })).filter((a) => a.name !== "");
411
411
  const ciUrl = webLink(attempt.buildHref);
412
412
  const failure = {
413
413
  ...headline !== void 0 ? { headline } : {},
@@ -480,7 +480,7 @@ function cut(text) {
480
480
  return { text: [...lines.slice(0, head), omitted(tail - head), ...lines.slice(tail)].join("\n"), omitted: text.length - kept.length };
481
481
  }
482
482
  var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
483
- var METADATA_TYPE = "application/plune.metadata+json";
483
+ var READ_NOT_KEPT = /* @__PURE__ */ new Set(["application/plune.metadata+json", "application/plune.findings+json"]);
484
484
  var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
485
485
  var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
486
486
  var FRAME_MAX = 8192;
@@ -777,7 +777,7 @@ var TYPE_BY_EXTENSION = {
777
777
  ".jpeg": "image/jpeg",
778
778
  ".webp": "image/webp"
779
779
  };
780
- var METADATA_TYPE2 = "application/plune.metadata+json";
780
+ var READ_NOT_KEPT2 = /* @__PURE__ */ new Set(["application/plune.metadata+json", "application/plune.findings+json"]);
781
781
  var NAME_MAX = 200;
782
782
  function nameOf(file) {
783
783
  const own = file.name.split(/[\\/]/).pop()?.trim() || (file.path === void 0 ? "" : basename2(file.path));
@@ -843,8 +843,13 @@ function withoutTargets(result) {
843
843
  const { targets: _targets, traceUrl: _traceUrl, ...rest } = result;
844
844
  return rest;
845
845
  }
846
+ function withoutFindings(result) {
847
+ if (result.findings === void 0) return result;
848
+ const { findings: _findings, ...rest } = result;
849
+ return rest;
850
+ }
846
851
  function onDisk(deferred) {
847
- const result = withoutTargets(deferred);
852
+ const result = withoutFindings(withoutTargets(deferred));
848
853
  if (!("files" in result) || result.files === void 0) return result;
849
854
  const { files, ...rest } = result;
850
855
  const kept = files.filter((f) => f.path !== void 0).map(({ body: _body, ...file }) => file);
@@ -1294,7 +1299,7 @@ function fileSender(options) {
1294
1299
  if (item?.status !== "accepted" || typeof item.id !== "string" || typeof item.resultKey !== "string") continue;
1295
1300
  for (const file of filesByKey.get(item.resultKey) ?? []) {
1296
1301
  const type = mediaTypeOf(file.contentType) ?? (file.path === void 0 ? void 0 : TYPE_BY_EXTENSION[extname(file.path).toLowerCase()]);
1297
- if (type === void 0 || type === METADATA_TYPE2) continue;
1302
+ if (type === void 0 || READ_NOT_KEPT2.has(type)) continue;
1298
1303
  const kind = kindOf(type);
1299
1304
  if (kind !== "text" && file.path === void 0) continue;
1300
1305
  const name = nameOf(file);
@@ -1397,6 +1402,7 @@ async function startRun(passed, declared2) {
1397
1402
  let joined = false;
1398
1403
  let offline = token === "";
1399
1404
  let targetsRefused = false;
1405
+ let findingsRefused = false;
1400
1406
  let done = false;
1401
1407
  const shortened = /* @__PURE__ */ new Set();
1402
1408
  const specFiles = /* @__PURE__ */ new Map();
@@ -1668,6 +1674,7 @@ async function startRun(passed, declared2) {
1668
1674
  async function send(submissions, filesByKey) {
1669
1675
  for (const packedPart of packed(submissions)) {
1670
1676
  let part = targetsRefused ? packedPart.map(withoutTargets) : packedPart;
1677
+ if (findingsRefused) part = part.map(withoutFindings);
1671
1678
  if (offline) {
1672
1679
  defer(part);
1673
1680
  continue;
@@ -1678,12 +1685,22 @@ async function startRun(passed, declared2) {
1678
1685
  { results, ...configuration !== void 0 ? { configuration } : {} }
1679
1686
  );
1680
1687
  let out = await post(part);
1688
+ let withoutItsFindings = false;
1689
+ if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.findings !== void 0)) {
1690
+ withoutItsFindings = true;
1691
+ part = part.map(withoutFindings);
1692
+ out = await post(part);
1693
+ }
1681
1694
  if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.targets !== void 0 || r.traceUrl !== void 0)) {
1682
1695
  if (!targetsRefused) log("plune: the platform does not take targets or a trace link on a result yet \u2014 the results are sent without them.");
1683
1696
  targetsRefused = true;
1684
1697
  part = part.map(withoutTargets);
1685
1698
  out = await post(part);
1686
1699
  }
1700
+ if (withoutItsFindings && out.ok) {
1701
+ if (!findingsRefused) log("plune: the platform does not take findings on a result yet \u2014 the results are sent without them.");
1702
+ findingsRefused = true;
1703
+ }
1687
1704
  const counts = out.ok ? out.body?.counts : void 0;
1688
1705
  const told = COUNTED.filter((k) => typeof counts?.[k] === "number");
1689
1706
  if (told.length > 0) {
@@ -1866,6 +1883,62 @@ function resultKey(testId, retry) {
1866
1883
  return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
1867
1884
  }
1868
1885
 
1886
+ // src/findings.ts
1887
+ import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
1888
+ var FINDINGS_TYPE = "application/plune.findings+json";
1889
+ var FINDINGS_MAX = 20;
1890
+ var OMITTED_MAX = 1e5;
1891
+ var TEXT_MAX = 300;
1892
+ var METHOD = /^[A-Z]{1,16}$/;
1893
+ var PATH = /^\/(?!\/)[^?#]*$/;
1894
+ function clip(text, max = TEXT_MAX) {
1895
+ const cut2 = text.slice(0, max);
1896
+ return /[\ud800-\udbff]$/.test(cut2) ? cut2.slice(0, -1) : cut2;
1897
+ }
1898
+ var SEPARATORS = String.raw`\s"'\x60<>`;
1899
+ var SEPARATOR = new RegExp(`[${SEPARATORS}]`);
1900
+ var TOKEN = new RegExp(`[^${SEPARATORS}]+`, "g");
1901
+ var isCount = (value2, min, max) => typeof value2 === "number" && Number.isInteger(value2) && value2 >= min && value2 <= max;
1902
+ var isText = (value2) => typeof value2 === "string" && value2.length >= 1 && value2.length <= TEXT_MAX;
1903
+ function toWire(raw, steps) {
1904
+ if (typeof raw !== "object" || raw === null) return void 0;
1905
+ const { items, omitted: omitted2 } = raw;
1906
+ if (!Array.isArray(items)) return void 0;
1907
+ const kept = [];
1908
+ let dropped = isCount(omitted2, 0, OMITTED_MAX) ? omitted2 : 0;
1909
+ for (const item of items) {
1910
+ const finding = kept.length < FINDINGS_MAX ? wireItem(item, steps) : void 0;
1911
+ if (finding === void 0) dropped += 1;
1912
+ else kept.push(finding);
1913
+ }
1914
+ return { items: kept, omitted: Math.min(OMITTED_MAX, dropped) };
1915
+ }
1916
+ function wireItem(item, steps) {
1917
+ if (typeof item !== "object" || item === null) return void 0;
1918
+ const { kind, text, method, path: path3, status, durationMs, at } = item;
1919
+ if (typeof at !== "number" || !Number.isFinite(at)) return void 0;
1920
+ const index = steps.findIndex((s) => s.start <= at && at < s.end);
1921
+ const title = index === -1 ? "" : clip(steps[index].title);
1922
+ const step = title === "" ? {} : { step: { index: index + 1, title } };
1923
+ if (kind === "console" || kind === "page_error") {
1924
+ return isText(text) ? { kind, text, ...step } : void 0;
1925
+ }
1926
+ if (kind !== "request_failed" && kind !== "request_slow") return void 0;
1927
+ if (typeof method !== "string" || !METHOD.test(method)) return void 0;
1928
+ if (!isText(path3) || !PATH.test(path3)) return void 0;
1929
+ if (status !== void 0 && !isCount(status, 100, 599)) return void 0;
1930
+ if (durationMs !== void 0 && !isCount(durationMs, 0, Number.MAX_SAFE_INTEGER))
1931
+ return void 0;
1932
+ return {
1933
+ kind,
1934
+ method,
1935
+ path: path3,
1936
+ ...status !== void 0 ? { status } : {},
1937
+ ...durationMs !== void 0 ? { durationMs } : {},
1938
+ ...step
1939
+ };
1940
+ }
1941
+
1869
1942
  // src/index.ts
1870
1943
  var SOURCE = "playwright";
1871
1944
  function fileOf2(test) {
@@ -1890,22 +1963,42 @@ function keysFor(test) {
1890
1963
  { kind: "path-title", value: pathTitleOf(test) }
1891
1964
  ];
1892
1965
  }
1893
- var METADATA_TYPE3 = "application/plune.metadata+json";
1894
- var TOKEN = /@P([A-Za-z0-9_-]+)/;
1966
+ var METADATA_TYPE = "application/plune.metadata+json";
1967
+ var TOKEN2 = /@P([A-Za-z0-9_-]+)/;
1895
1968
  function metadataOf(result) {
1896
- const found = result.attachments.find((a) => a.contentType === METADATA_TYPE3);
1969
+ const found = result.attachments.find((a) => a.contentType === METADATA_TYPE);
1897
1970
  if (found === void 0) return void 0;
1898
1971
  try {
1899
- const raw = found.body !== void 0 ? found.body.toString("utf8") : found.path !== void 0 ? readFileSync3(found.path, "utf8") : void 0;
1972
+ const raw = textOfAttachment(found);
1900
1973
  return raw === void 0 ? void 0 : JSON.parse(raw);
1901
1974
  } catch {
1902
1975
  return void 0;
1903
1976
  }
1904
1977
  }
1978
+ function textOfAttachment(found) {
1979
+ if (found.body !== void 0) return found.body.toString("utf8");
1980
+ return found.path !== void 0 ? readFileSync3(found.path, "utf8") : void 0;
1981
+ }
1982
+ function findingsOf(result) {
1983
+ const found = result.attachments.find((a) => a.contentType === FINDINGS_TYPE);
1984
+ if (found === void 0) return void 0;
1985
+ try {
1986
+ const raw = textOfAttachment(found);
1987
+ if (raw === void 0) return void 0;
1988
+ const steps = (result.steps ?? []).filter((step) => step.category === "test.step").map((step, i, all) => {
1989
+ const start = step.startTime.getTime();
1990
+ const end = step.duration >= 0 ? start + step.duration : all[i + 1]?.startTime.getTime() ?? Infinity;
1991
+ return { title: step.title, start, end };
1992
+ });
1993
+ return toWire(JSON.parse(raw), steps);
1994
+ } catch {
1995
+ return void 0;
1996
+ }
1997
+ }
1905
1998
  function statedIdOf(test, metadata, mapped) {
1906
1999
  const annotation = test.annotations.find((a) => a.type === "PluneId")?.description;
1907
2000
  if (annotation !== void 0 && annotation !== "") return annotation;
1908
- const token = TOKEN.exec(test.title)?.[1];
2001
+ const token = TOKEN2.exec(test.title)?.[1];
1909
2002
  if (token !== void 0) return token;
1910
2003
  if (metadata?.id !== void 0 && metadata.id !== "") return metadata.id;
1911
2004
  return mapped;
@@ -1936,7 +2029,7 @@ function textOf(error) {
1936
2029
  const lines = error.stack?.split("\n") ?? [];
1937
2030
  const at = lines.findIndex((line) => line.startsWith(" at "));
1938
2031
  const tokens = [(at === -1 ? lines : lines.slice(0, at)).join("\n") || message];
1939
- if (error.snippet) tokens.push("", stripVTControlCharacters2(error.snippet));
2032
+ if (error.snippet) tokens.push("", stripVTControlCharacters3(error.snippet));
1940
2033
  if (at !== -1) tokens.push(lines.slice(at).join("\n"));
1941
2034
  if (error.cause) tokens.push(`[cause]: ${textOf(error.cause)}`);
1942
2035
  return tokens.join("\n");
@@ -1973,6 +2066,7 @@ function pendingFrom(test, result, ctx, ids = {}) {
1973
2066
  const errorContext = errorContextFields(attempt);
1974
2067
  const failure = NOT_FAILED.has(result.status) ? void 0 : failureOf(attempt);
1975
2068
  const files = filesOf(attempt);
2069
+ const findings = result.status === "passed" ? void 0 : findingsOf(result);
1976
2070
  const startedAt = result.startTime;
1977
2071
  return {
1978
2072
  resultKey: resultKey(test.id, result.retry),
@@ -2005,7 +2099,10 @@ function pendingFrom(test, result, ctx, ids = {}) {
2005
2099
  ...errorContext,
2006
2100
  ...failure !== void 0 ? { failure } : {},
2007
2101
  // Every attempt's, a passed one's too; the core uploads the screenshots and the text files once the result is stored.
2008
- ...files.length > 0 ? { files } : {}
2102
+ ...files.length > 0 ? { files } : {},
2103
+ // Only with an attempt that did not pass: the run page shows what the browser reported under a failure,
2104
+ // and nowhere else. Each attempt carries its own attachment, so a retry sends its own findings.
2105
+ ...findings !== void 0 ? { findings } : {}
2009
2106
  };
2010
2107
  }
2011
2108
  var PluneReporter = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plune-ai/playwright",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "description": "Report Playwright results to Plune — a reporter and, later, a test importer.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -19,6 +19,11 @@
19
19
  "types": "./dist/index.d.ts",
20
20
  "import": "./dist/index.js",
21
21
  "require": "./dist/index.cjs"
22
+ },
23
+ "./fixture": {
24
+ "types": "./dist/fixture.d.ts",
25
+ "import": "./dist/fixture.js",
26
+ "require": "./dist/fixture.cjs"
22
27
  }
23
28
  },
24
29
  "files": [
@@ -38,7 +43,7 @@
38
43
  "tsup": "^8.0.0",
39
44
  "typescript": "^5.4.0",
40
45
  "vitest": "^1.6.0",
41
- "@plune-ai/cli": "0.39.8"
46
+ "@plune-ai/cli": "0.39.10"
42
47
  },
43
48
  "repository": {
44
49
  "type": "git",