@supatest/cypress-reporter 0.0.5 → 0.0.6

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.cjs CHANGED
@@ -916,7 +916,6 @@ __export(index_exports, {
916
916
  });
917
917
  module.exports = __toCommonJS(index_exports);
918
918
  var import_node_fs = __toESM(require("fs"), 1);
919
- var import_node_os = __toESM(require("os"), 1);
920
919
  var import_node_path = __toESM(require("path"), 1);
921
920
 
922
921
  // ../node_modules/.pnpm/simple-git@3.27.0/node_modules/simple-git/dist/esm/index.js
@@ -5473,6 +5472,7 @@ var simpleGit = gitInstanceFactory;
5473
5472
  // ../reporter-core/dist/index.js
5474
5473
  var import_crypto = require("crypto");
5475
5474
  var import_fs = __toESM(require("fs"), 1);
5475
+ var import_os = __toESM(require("os"), 1);
5476
5476
  var import_fs2 = __toESM(require("fs"), 1);
5477
5477
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5478
5478
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -5584,12 +5584,16 @@ var SupatestApiClient = class {
5584
5584
  this.options.timeoutMs
5585
5585
  );
5586
5586
  try {
5587
+ const headers = {
5588
+ "Content-Type": "application/json",
5589
+ Authorization: `Bearer ${this.options.apiKey}`
5590
+ };
5591
+ if (this.options.projectId) {
5592
+ headers["X-Project-Id"] = this.options.projectId;
5593
+ }
5587
5594
  const response = await _fetch(url, {
5588
5595
  method,
5589
- headers: {
5590
- "Content-Type": "application/json",
5591
- Authorization: `Bearer ${this.options.apiKey}`
5592
- },
5596
+ headers,
5593
5597
  body: body ? JSON.stringify(body) : void 0,
5594
5598
  signal: controller.signal
5595
5599
  });
@@ -5613,6 +5617,10 @@ var SupatestApiClient = class {
5613
5617
  console.log(JSON.stringify(data, null, 2));
5614
5618
  }
5615
5619
  };
5620
+ var DEFAULT_API_URL = "https://code-api.supatest.ai";
5621
+ var DEFAULT_MAX_CONCURRENT_UPLOADS = 5;
5622
+ var DEFAULT_RETRY_ATTEMPTS = 3;
5623
+ var DEFAULT_TIMEOUT_MS = 3e4;
5616
5624
  var ErrorCollector = class {
5617
5625
  errors = [];
5618
5626
  recordError(category, message, context) {
@@ -5778,6 +5786,31 @@ async function getLocalGitInfo(rootDir) {
5778
5786
  return {};
5779
5787
  }
5780
5788
  }
5789
+ async function getGitInfoWithCI(rootDir) {
5790
+ const ciGitInfo = {
5791
+ branch: process.env.GITHUB_REF_NAME ?? process.env.GITHUB_HEAD_REF ?? process.env.CI_COMMIT_BRANCH ?? process.env.GITLAB_CI_COMMIT_BRANCH ?? process.env.GIT_BRANCH,
5792
+ commit: process.env.GITHUB_SHA ?? process.env.CI_COMMIT_SHA ?? process.env.GITLAB_CI_COMMIT_SHA ?? process.env.GIT_COMMIT,
5793
+ commitMessage: process.env.CI_COMMIT_MESSAGE ?? process.env.GITLAB_CI_COMMIT_MESSAGE,
5794
+ repo: process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH ?? process.env.GITLAB_CI_PROJECT_PATH ?? process.env.GIT_REPO,
5795
+ author: process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_NAME,
5796
+ authorEmail: process.env.GITLAB_USER_EMAIL,
5797
+ tag: process.env.GITHUB_REF_TYPE === "tag" ? process.env.GITHUB_REF_NAME : void 0
5798
+ };
5799
+ if (ciGitInfo.branch || ciGitInfo.commit) {
5800
+ return ciGitInfo;
5801
+ }
5802
+ const localGitInfo = await getLocalGitInfo(rootDir);
5803
+ return {
5804
+ branch: ciGitInfo.branch ?? localGitInfo.branch,
5805
+ commit: ciGitInfo.commit ?? localGitInfo.commit,
5806
+ commitMessage: ciGitInfo.commitMessage ?? localGitInfo.commitMessage,
5807
+ repo: ciGitInfo.repo ?? localGitInfo.repo,
5808
+ author: ciGitInfo.author ?? localGitInfo.author,
5809
+ authorEmail: ciGitInfo.authorEmail ?? localGitInfo.authorEmail,
5810
+ tag: ciGitInfo.tag ?? localGitInfo.tag,
5811
+ dirty: localGitInfo.dirty
5812
+ };
5813
+ }
5781
5814
  function hashKey(value) {
5782
5815
  return (0, import_crypto.createHash)("sha256").update(value).digest("hex").slice(0, 12);
5783
5816
  }
@@ -5886,6 +5919,24 @@ function getCIInfo() {
5886
5919
  }
5887
5920
  return void 0;
5888
5921
  }
5922
+ function getBaseEnvironmentInfo() {
5923
+ return {
5924
+ os: {
5925
+ platform: import_os.default.platform(),
5926
+ release: import_os.default.release(),
5927
+ arch: import_os.default.arch()
5928
+ },
5929
+ node: {
5930
+ version: process.version
5931
+ },
5932
+ machine: {
5933
+ cpus: import_os.default.cpus().length,
5934
+ memory: import_os.default.totalmem(),
5935
+ hostname: import_os.default.hostname()
5936
+ },
5937
+ ci: getCIInfo()
5938
+ };
5939
+ }
5889
5940
  function registerInterruptHandler(client, getRunId) {
5890
5941
  let completed = false;
5891
5942
  const handler = async (signal) => {
@@ -5918,6 +5969,52 @@ function registerInterruptHandler(client, getRunId) {
5918
5969
  process.removeListener("SIGTERM", sigtermHandler);
5919
5970
  };
5920
5971
  }
5972
+ var TAG_PATTERNS = {
5973
+ owner: /@owner:([^\s@]+)/,
5974
+ priority: /@priority:(critical|high|medium|low)/i,
5975
+ feature: /@feature:([^\s@]+)/,
5976
+ ticketId: /@ticket:([^\s@]+)/,
5977
+ testType: /@test_type:(smoke|e2e|regression|integration|unit)/i
5978
+ };
5979
+ var KNOWN_KEYS = ["owner", "priority", "feature", "ticket", "test_type", "id", "slow", "flaky"];
5980
+ function parseTestMetadata(tags) {
5981
+ const metadata = {
5982
+ isSlow: false,
5983
+ isFlakyTagged: false,
5984
+ customMetadata: {}
5985
+ };
5986
+ for (const tag of tags) {
5987
+ const lowerTag = tag.toLowerCase();
5988
+ if (lowerTag === "@slow") {
5989
+ metadata.isSlow = true;
5990
+ } else if (lowerTag === "@flaky") {
5991
+ metadata.isFlakyTagged = true;
5992
+ }
5993
+ }
5994
+ for (const tag of tags) {
5995
+ for (const [key, pattern] of Object.entries(TAG_PATTERNS)) {
5996
+ const match = tag.match(pattern);
5997
+ if (match) {
5998
+ const value = match[1];
5999
+ if (key === "priority") {
6000
+ metadata.priority = value.toLowerCase();
6001
+ } else if (key === "testType") {
6002
+ metadata.testType = value.toLowerCase();
6003
+ } else {
6004
+ metadata[key] = value;
6005
+ }
6006
+ }
6007
+ }
6008
+ const customMatch = tag.match(/@([a-zA-Z][a-zA-Z0-9_-]*):([^\s@]+)/);
6009
+ if (customMatch) {
6010
+ const [, key, value] = customMatch;
6011
+ if (!KNOWN_KEYS.includes(key.toLowerCase())) {
6012
+ metadata.customMetadata[key] = value;
6013
+ }
6014
+ }
6015
+ }
6016
+ return metadata;
6017
+ }
5921
6018
  var AttachmentUploader = class {
5922
6019
  options;
5923
6020
  constructor(options) {
@@ -6013,7 +6110,6 @@ var AttachmentUploader = class {
6013
6110
  };
6014
6111
 
6015
6112
  // src/index.ts
6016
- var DEFAULT_API_URL = "https://code-api.supatest.ai";
6017
6113
  var SupatestCypressReporter = class {
6018
6114
  options;
6019
6115
  client;
@@ -6038,9 +6134,9 @@ var SupatestCypressReporter = class {
6038
6134
  apiKey: options.apiKey || process.env.SUPATEST_API_KEY || "",
6039
6135
  apiUrl: options.apiUrl || process.env.SUPATEST_API_URL || DEFAULT_API_URL,
6040
6136
  uploadAssets: options.uploadAssets ?? true,
6041
- maxConcurrentUploads: options.maxConcurrentUploads ?? 5,
6042
- retryAttempts: options.retryAttempts ?? 3,
6043
- timeoutMs: options.timeoutMs ?? 3e4,
6137
+ maxConcurrentUploads: options.maxConcurrentUploads ?? DEFAULT_MAX_CONCURRENT_UPLOADS,
6138
+ retryAttempts: options.retryAttempts ?? DEFAULT_RETRY_ATTEMPTS,
6139
+ timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
6044
6140
  dryRun: options.dryRun ?? process.env.SUPATEST_DRY_RUN === "true"
6045
6141
  };
6046
6142
  }
@@ -6059,6 +6155,7 @@ var SupatestCypressReporter = class {
6059
6155
  this.client = new SupatestApiClient({
6060
6156
  apiKey: this.options.apiKey,
6061
6157
  apiUrl: this.options.apiUrl,
6158
+ projectId: this.options.projectId,
6062
6159
  timeoutMs: this.options.timeoutMs,
6063
6160
  retryAttempts: this.options.retryAttempts,
6064
6161
  dryRun: this.options.dryRun
@@ -6264,25 +6361,7 @@ var SupatestCypressReporter = class {
6264
6361
  return tags;
6265
6362
  }
6266
6363
  parseTestMetadata(tags) {
6267
- const metadata = {
6268
- isSlow: false,
6269
- isFlakyTagged: false,
6270
- customMetadata: {}
6271
- };
6272
- for (const tag of tags) {
6273
- const lower = tag.toLowerCase();
6274
- if (lower === "@slow") metadata.isSlow = true;
6275
- if (lower === "@flaky") metadata.isFlakyTagged = true;
6276
- const ownerMatch = tag.match(/@owner:([^\s@]+)/i);
6277
- if (ownerMatch) metadata.owner = ownerMatch[1];
6278
- const priorityMatch = tag.match(/@priority:(critical|high|medium|low)/i);
6279
- if (priorityMatch) metadata.priority = priorityMatch[1].toLowerCase();
6280
- const featureMatch = tag.match(/@feature:([^\s@]+)/i);
6281
- if (featureMatch) metadata.feature = featureMatch[1];
6282
- const typeMatch = tag.match(/@test_type:(smoke|e2e|regression|integration|unit)/i);
6283
- if (typeMatch) metadata.testType = typeMatch[1].toLowerCase();
6284
- }
6285
- return metadata;
6364
+ return parseTestMetadata(tags);
6286
6365
  }
6287
6366
  buildAttachmentMeta(test, specResults) {
6288
6367
  const attachments = [];
@@ -6347,43 +6426,41 @@ var SupatestCypressReporter = class {
6347
6426
  filePath: attachments[i].path,
6348
6427
  contentType: attachments[i].meta.contentType
6349
6428
  }));
6350
- await this.uploader.uploadBatch(uploadItems, uploads);
6429
+ const results = await this.uploader.uploadBatch(uploadItems, uploads);
6430
+ const failures = results.filter((r) => !r.success);
6431
+ if (failures.length > 0) {
6432
+ failures.forEach((failure) => {
6433
+ const attachment = attachments.find(
6434
+ (_, i) => {
6435
+ var _a2;
6436
+ return ((_a2 = uploads[i]) == null ? void 0 : _a2.attachmentId) === failure.attachmentId;
6437
+ }
6438
+ );
6439
+ this.errorCollector.recordError(
6440
+ "ATTACHMENT_UPLOAD",
6441
+ failure.error || "Upload failed",
6442
+ {
6443
+ attachmentName: attachment == null ? void 0 : attachment.meta.name,
6444
+ filePath: attachment == null ? void 0 : attachment.path,
6445
+ error: failure.error
6446
+ }
6447
+ );
6448
+ });
6449
+ }
6351
6450
  } catch (error) {
6352
6451
  this.errorCollector.recordError("ATTACHMENT_SIGN", getErrorMessage2(error), { error });
6353
6452
  }
6354
6453
  }
6355
6454
  getEnvironmentInfo() {
6356
6455
  return {
6357
- os: {
6358
- platform: import_node_os.default.platform(),
6359
- release: import_node_os.default.release(),
6360
- arch: import_node_os.default.arch()
6361
- },
6362
- node: {
6363
- version: process.version
6364
- },
6365
- machine: {
6366
- cpus: import_node_os.default.cpus().length,
6367
- memory: import_node_os.default.totalmem(),
6368
- hostname: import_node_os.default.hostname()
6369
- },
6456
+ ...getBaseEnvironmentInfo(),
6370
6457
  cypress: {
6371
6458
  version: this.cypressVersion || "unknown"
6372
- },
6373
- ci: getCIInfo()
6459
+ }
6374
6460
  };
6375
6461
  }
6376
6462
  async getGitInfo() {
6377
- const ciGitInfo = {
6378
- branch: process.env.GITHUB_REF_NAME ?? process.env.CI_COMMIT_BRANCH ?? process.env.GIT_BRANCH,
6379
- commit: process.env.GITHUB_SHA ?? process.env.CI_COMMIT_SHA ?? process.env.GIT_COMMIT,
6380
- repo: process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH,
6381
- author: process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_NAME
6382
- };
6383
- if (ciGitInfo.branch || ciGitInfo.commit) {
6384
- return ciGitInfo;
6385
- }
6386
- return await getLocalGitInfo(this.rootDir);
6463
+ return getGitInfoWithCI(this.rootDir);
6387
6464
  }
6388
6465
  };
6389
6466
  function supatestPlugin(on, config, options = {}) {