{"version":3,"file":"playwright/report-filename.mjs","sources":["../../../src/playwright/report-filename.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { replaceIllegalPathCharsAndSpace } from '@midscene/shared/utils';\n\n// Keep enough room below the common 255-byte filesystem component limit for\n// suffixes added later, such as `.html` or getReportFileName's timestamp/id.\nexport const MAX_PLAYWRIGHT_REPORT_TAG_BYTES = 200;\n\nconst playwrightReportPrefix = 'playwright-';\nconst compactHashLength = 10;\n\nfunction getCompactHash(value: string): string {\n  return createHash('sha256')\n    .update(value)\n    .digest('hex')\n    .slice(0, compactHashLength);\n}\n\nfunction truncateUtf8ByBytes(value: string, maxBytes: number): string {\n  let byteLength = 0;\n  let truncated = '';\n\n  for (const character of value) {\n    const characterBytes = Buffer.byteLength(character, 'utf8');\n    if (byteLength + characterBytes > maxBytes) {\n      break;\n    }\n    truncated += character;\n    byteLength += characterBytes;\n  }\n\n  return truncated;\n}\n\nexport function buildPlaywrightReportTag(\n  title: string,\n  uniqueSuffix?: string,\n  hashSource = title,\n): string {\n  const safeTitle = replaceIllegalPathCharsAndSpace(title).replace(\n    /[\\\\/]/g,\n    '-',\n  );\n  const titleHash = getCompactHash(hashSource);\n  const trailingSegments = uniqueSuffix\n    ? `-${titleHash}-${uniqueSuffix}`\n    : `-${titleHash}`;\n  const fixedBytes = Buffer.byteLength(\n    `${playwrightReportPrefix}${trailingSegments}`,\n    'utf8',\n  );\n  const titleByteBudget = MAX_PLAYWRIGHT_REPORT_TAG_BYTES - fixedBytes;\n\n  if (titleByteBudget < 0) {\n    throw new Error(\n      `Playwright report suffix exceeds the ${MAX_PLAYWRIGHT_REPORT_TAG_BYTES}-byte tag limit`,\n    );\n  }\n\n  const readableTitle = truncateUtf8ByBytes(safeTitle, titleByteBudget);\n  return `${playwrightReportPrefix}${readableTitle}${trailingSegments}`;\n}\n"],"names":["MAX_PLAYWRIGHT_REPORT_TAG_BYTES","playwrightReportPrefix","compactHashLength","getCompactHash","value","createHash","truncateUtf8ByBytes","maxBytes","byteLength","truncated","character","characterBytes","Buffer","buildPlaywrightReportTag","title","uniqueSuffix","hashSource","safeTitle","replaceIllegalPathCharsAndSpace","titleHash","trailingSegments","fixedBytes","titleByteBudget","Error","readableTitle"],"mappings":";;AAKO,MAAMA,kCAAkC;AAE/C,MAAMC,yBAAyB;AAC/B,MAAMC,oBAAoB;AAE1B,SAASC,eAAeC,KAAa;IACnC,OAAOC,WAAW,UACf,MAAM,CAACD,OACP,MAAM,CAAC,OACP,KAAK,CAAC,GAAGF;AACd;AAEA,SAASI,oBAAoBF,KAAa,EAAEG,QAAgB;IAC1D,IAAIC,aAAa;IACjB,IAAIC,YAAY;IAEhB,KAAK,MAAMC,aAAaN,MAAO;QAC7B,MAAMO,iBAAiBC,OAAO,UAAU,CAACF,WAAW;QACpD,IAAIF,aAAaG,iBAAiBJ,UAChC;QAEFE,aAAaC;QACbF,cAAcG;IAChB;IAEA,OAAOF;AACT;AAEO,SAASI,yBACdC,KAAa,EACbC,YAAqB,EACrBC,aAAaF,KAAK;IAElB,MAAMG,YAAYC,gCAAgCJ,OAAO,OAAO,CAC9D,UACA;IAEF,MAAMK,YAAYhB,eAAea;IACjC,MAAMI,mBAAmBL,eACrB,CAAC,CAAC,EAAEI,UAAU,CAAC,EAAEJ,cAAc,GAC/B,CAAC,CAAC,EAAEI,WAAW;IACnB,MAAME,aAAaT,OAAO,UAAU,CAClC,GAAGX,yBAAyBmB,kBAAkB,EAC9C;IAEF,MAAME,kBAAkBtB,kCAAkCqB;IAE1D,IAAIC,kBAAkB,GACpB,MAAM,IAAIC,MACR,CAAC,qCAAqC,EAAEvB,gCAAgC,eAAe,CAAC;IAI5F,MAAMwB,gBAAgBlB,oBAAoBW,WAAWK;IACrD,OAAO,GAAGrB,yBAAyBuB,gBAAgBJ,kBAAkB;AACvE"}