@bigbinary/neeto-playwright-reporter 1.1.0 → 1.2.1

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/index.cjs.js CHANGED
@@ -18464,6 +18464,7 @@ const attemptsApi = { create: create$2, update: update$1 };
18464
18464
  const ERRORS = {
18465
18465
  onBegin: {
18466
18466
  failedToGetCommitSha: "Failed to get current commit SHA.",
18467
+ failedToGetBranch: "Failed to get current branch.",
18467
18468
  failedToGetCommitMessage: "Failed to get current commit message.",
18468
18469
  failedToInitializeRun: "Failed to initialize run in reporter",
18469
18470
  },
@@ -18473,23 +18474,32 @@ const ERRORS = {
18473
18474
  onEnd: {
18474
18475
  failedToReportRunStatus: "Failed to report run status",
18475
18476
  },
18477
+ heartbeat: {
18478
+ stopped: "Run was stopped at the reporter",
18479
+ },
18476
18480
  };
18477
18481
 
18478
18482
  const MESSAGES = {
18479
18483
  onBegin: {
18480
- testStarted: "Test has started reporting to neetoPlaywrightReporter",
18484
+ testStarted: "Run has started reporting to neetoPlaywrightReporter",
18481
18485
  ciBuildId: (currentCiBuildId) => `CI BUILD ID: ${currentCiBuildId}`,
18482
18486
  totalShards: (totalShards) => `Total shards: ${totalShards}`,
18483
18487
  currentShard: (currentShard) => `Current shard: ${currentShard}`,
18484
18488
  },
18489
+ onTestBegin: {
18490
+ startingTest: (titlePath) => `Starting ${titlePath}`,
18491
+ },
18492
+ onTestEnd: {
18493
+ reportedTest: (title) => `Reported ${title} to neetoPlaywrightReporter`,
18494
+ },
18485
18495
  };
18486
18496
 
18487
18497
  const consoleLogFormatted = {
18488
- bold: (message) => console.log(console.log("\x1b[1m", message, "\x1b[0m")),
18489
- dim: (message) => console.log(console.log("\x1b[2m", message, "\x1b[0m")),
18490
- underline: (message) => console.log(console.log("\x1b[4m", message, "\x1b[0m")),
18491
- invertBackground: (message) => console.log(console.log("\x1b[7m", message, "\x1b[0m")),
18492
- hidden: (message) => console.log(console.log("\x1b[8m", message, "\x1b[0m")),
18498
+ bold: (message) => console.log("\x1b[1m", message, "\x1b[0m"),
18499
+ dim: (message) => console.log("\x1b[2m", message, "\x1b[0m"),
18500
+ underline: (message) => console.log("\x1b[4m", message, "\x1b[0m"),
18501
+ invertBackground: (message) => console.log("\x1b[7m", message, "\x1b[0m"),
18502
+ hidden: (message) => console.log("\x1b[8m", message, "\x1b[0m"),
18493
18503
  error: (message) => console.log("\u001b[31m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18494
18504
  warning: (message) => console.log("\u001b[33m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18495
18505
  };
@@ -18512,6 +18522,15 @@ const createShardObject = ({ currentShard = 0, status = "running", duration = nu
18512
18522
  });
18513
18523
  const convertBufferToBlob = (buffer, contentType) => new Blob([buffer], { type: contentType });
18514
18524
 
18525
+ const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
18526
+ run: payload,
18527
+ });
18528
+ const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
18529
+ run: payload,
18530
+ });
18531
+ const heartbeat = (ciBuildId) => axios.get(`${API_BASE_URL}/reporter/runs/${ciBuildId}/heartbeat`);
18532
+ const runsApi = { create: create$1, update, heartbeat };
18533
+
18515
18534
  const getDescribePath = ({ titlePath, title, project, spec, }) => titlePath.filter((item, index) => index !== 0 && item !== title && item !== project && item !== spec);
18516
18535
  const getCurrentCommitSha = () => executeCommandLine({
18517
18536
  command: "git rev-parse HEAD",
@@ -18521,6 +18540,10 @@ const getCurrentCommitMessage = () => executeCommandLine({
18521
18540
  command: "git show-branch --no-name HEAD",
18522
18541
  messageOnError: ERRORS.onBegin.failedToGetCommitMessage,
18523
18542
  });
18543
+ const getCurrentBranch = () => executeCommandLine({
18544
+ command: "git branch --show-current",
18545
+ messageOnError: ERRORS.onBegin.failedToGetBranch,
18546
+ });
18524
18547
  const getInitializerData = ({ rootDir }, rootSuite) => rootSuite.allTests().map(test => {
18525
18548
  var _a;
18526
18549
  const { title, parent, id: history_id, location: { file }, } = test;
@@ -18530,6 +18553,15 @@ const getInitializerData = ({ rootDir }, rootSuite) => rootSuite.allTests().map(
18530
18553
  const describe = getDescribePath({ titlePath, title, spec, project });
18531
18554
  return { title, describe, project, spec, history_id };
18532
18555
  });
18556
+ const sendHeartBeatSignal = async (ciBuildId) => {
18557
+ try {
18558
+ await runsApi.heartbeat(ciBuildId);
18559
+ }
18560
+ catch (error) {
18561
+ consoleLogFormatted.error(ERRORS.heartbeat.stopped);
18562
+ process.exit(1);
18563
+ }
18564
+ };
18533
18565
 
18534
18566
  const setAuthHeaders = (projectKey) => {
18535
18567
  var _a;
@@ -18546,14 +18578,6 @@ function initializeAxios({ projectKey, baseURL, }) {
18546
18578
  setAuthHeaders(projectKey);
18547
18579
  }
18548
18580
 
18549
- const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
18550
- run: payload,
18551
- });
18552
- const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
18553
- run: payload,
18554
- });
18555
- const runsApi = { create: create$1, update };
18556
-
18557
18581
  const create = (ciBuildId, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities`, {
18558
18582
  test_entity: payload,
18559
18583
  });
@@ -18568,6 +18592,7 @@ class MyReporter {
18568
18592
  const runDetails = {
18569
18593
  commit_id: getCurrentCommitSha(),
18570
18594
  commit_name: getCurrentCommitMessage(),
18595
+ branch: getCurrentBranch(),
18571
18596
  ci_build_id: this.ciBuildId,
18572
18597
  configuration: config,
18573
18598
  shards: createShardObject({ currentShard: shard === null || shard === void 0 ? void 0 : shard.current }),
@@ -18578,7 +18603,7 @@ class MyReporter {
18578
18603
  }));
18579
18604
  }
18580
18605
  catch (error) {
18581
- consoleLogFormatted.error(error);
18606
+ consoleLogFormatted.error(error.message);
18582
18607
  throw new Error(ERRORS.onBegin.failedToInitializeRun);
18583
18608
  }
18584
18609
  consoleLogFormatted.underline(MESSAGES.onBegin.testStarted);
@@ -18587,25 +18612,32 @@ class MyReporter {
18587
18612
  consoleLogFormatted.dim(MESSAGES.onBegin.totalShards(shard.total));
18588
18613
  consoleLogFormatted.dim(MESSAGES.onBegin.currentShard(shard.current));
18589
18614
  }
18615
+ await sendHeartBeatSignal(this.ciBuildId);
18616
+ setInterval(async () => await sendHeartBeatSignal(this.ciBuildId), 60000);
18590
18617
  this.attempts = attempts;
18591
18618
  this.config = config;
18592
18619
  this.currentShard = shard === null || shard === void 0 ? void 0 : shard.current;
18593
18620
  };
18594
18621
  this.onTestBegin = async ({ id, title }, { retry }) => {
18622
+ consoleLogFormatted.invertBackground(MESSAGES.onTestBegin.startingTest(title));
18595
18623
  try {
18596
18624
  const formData = new FormData();
18597
18625
  formData.append("attempt[status]", "running");
18626
+ formData.append("attempt[started_at]", new Date().toString());
18598
18627
  retry === 0 &&
18599
18628
  (await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData));
18600
18629
  }
18601
18630
  catch (error) {
18631
+ consoleLogFormatted.error(error.message);
18602
18632
  consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
18603
- console.log(error);
18604
18633
  }
18605
18634
  };
18606
- this.onTestEnd = async ({ id, title }, { status, duration, errors, retry, attachments }) => {
18635
+ this.onTestEnd = async (testCase, { status, duration, errors, retry, attachments }) => {
18636
+ const { id, title, expectedStatus } = testCase;
18607
18637
  try {
18608
18638
  const testResult = {
18639
+ outcome: testCase.outcome(),
18640
+ expected_status: expectedStatus,
18609
18641
  status,
18610
18642
  duration,
18611
18643
  log: errors.map(error => { var _a; return (_a = error.message) !== null && _a !== void 0 ? _a : ""; }).join("\n"),
@@ -18622,13 +18654,16 @@ class MyReporter {
18622
18654
  Object.entries(testResult).map(([resultKey, resultValue]) => {
18623
18655
  formData.append(`attempt[${resultKey}]`, resultValue.toString());
18624
18656
  });
18657
+ retry !== 0 &&
18658
+ formData.append("attempt[started_at]", new Date().toString());
18625
18659
  retry === 0
18626
18660
  ? await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData)
18627
18661
  : await attemptsApi.create(this.ciBuildId, id, formData);
18662
+ consoleLogFormatted.invertBackground(MESSAGES.onTestEnd.reportedTest(title));
18628
18663
  }
18629
18664
  catch (error) {
18665
+ consoleLogFormatted.error(error.message);
18630
18666
  consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
18631
- console.log(error);
18632
18667
  }
18633
18668
  };
18634
18669
  this.onEnd = async ({ status, duration }) => {
@@ -18642,7 +18677,7 @@ class MyReporter {
18642
18677
  });
18643
18678
  }
18644
18679
  catch (error) {
18645
- console.log(error);
18680
+ consoleLogFormatted.error(error.message);
18646
18681
  throw new Error(ERRORS.onEnd.failedToReportRunStatus);
18647
18682
  }
18648
18683
  };