@bigbinary/neeto-playwright-reporter 1.0.2 → 1.2.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/index.cjs.js CHANGED
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ var require$$6 = require('fs');
3
4
  var require$$1 = require('util');
4
5
  var stream = require('stream');
5
6
  var require$$1$1 = require('path');
6
7
  var require$$3 = require('http');
7
8
  var require$$4 = require('https');
8
9
  var require$$0$1 = require('url');
9
- var require$$6 = require('fs');
10
10
  var require$$4$1 = require('assert');
11
11
  var require$$1$2 = require('tty');
12
12
  var require$$0$2 = require('os');
@@ -16,13 +16,13 @@ var childProcess = require('child_process');
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
19
+ var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
19
20
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
20
21
  var stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
21
22
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
22
23
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
23
24
  var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
24
25
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
25
- var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
26
26
  var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
27
27
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
28
28
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
@@ -18457,12 +18457,8 @@ const HEADERS_KEYS = {
18457
18457
  };
18458
18458
  const API_BASE_URL = "/api/v1";
18459
18459
 
18460
- const create$2 = (ciBuildId, history_id, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts`, {
18461
- attempt: payload,
18462
- });
18463
- const update$1 = (ciBuildId, history_id, id, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts/${id}`, {
18464
- attempt: payload,
18465
- });
18460
+ const create$2 = (ciBuildId, history_id, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts`, payload, { headers: { "Content-Type": "multipart/form-data" } });
18461
+ const update$1 = (ciBuildId, history_id, id, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities/${history_id}/attempts/${id}`, payload, { headers: { "Content-Type": "multipart/form-data" } });
18466
18462
  const attemptsApi = { create: create$2, update: update$1 };
18467
18463
 
18468
18464
  const ERRORS = {
@@ -18477,23 +18473,32 @@ const ERRORS = {
18477
18473
  onEnd: {
18478
18474
  failedToReportRunStatus: "Failed to report run status",
18479
18475
  },
18476
+ heartbeat: {
18477
+ stopped: "Run was stopped at the reporter",
18478
+ },
18480
18479
  };
18481
18480
 
18482
18481
  const MESSAGES = {
18483
18482
  onBegin: {
18484
- testStarted: "Test has started reporting to neetoPlaywrightReporter",
18483
+ testStarted: "Run has started reporting to neetoPlaywrightReporter",
18485
18484
  ciBuildId: (currentCiBuildId) => `CI BUILD ID: ${currentCiBuildId}`,
18486
18485
  totalShards: (totalShards) => `Total shards: ${totalShards}`,
18487
18486
  currentShard: (currentShard) => `Current shard: ${currentShard}`,
18488
18487
  },
18488
+ onTestBegin: {
18489
+ startingTest: (titlePath) => `Starting ${titlePath}`,
18490
+ },
18491
+ onTestEnd: {
18492
+ reportedTest: (title) => `Reported ${title} to neetoPlaywrightReporter`,
18493
+ },
18489
18494
  };
18490
18495
 
18491
18496
  const consoleLogFormatted = {
18492
- bold: (message) => console.log(console.log("\x1b[1m", message, "\x1b[0m")),
18493
- dim: (message) => console.log(console.log("\x1b[2m", message, "\x1b[0m")),
18494
- underline: (message) => console.log(console.log("\x1b[4m", message, "\x1b[0m")),
18495
- invertBackground: (message) => console.log(console.log("\x1b[7m", message, "\x1b[0m")),
18496
- hidden: (message) => console.log(console.log("\x1b[8m", message, "\x1b[0m")),
18497
+ bold: (message) => console.log("\x1b[1m", message, "\x1b[0m"),
18498
+ dim: (message) => console.log("\x1b[2m", message, "\x1b[0m"),
18499
+ underline: (message) => console.log("\x1b[4m", message, "\x1b[0m"),
18500
+ invertBackground: (message) => console.log("\x1b[7m", message, "\x1b[0m"),
18501
+ hidden: (message) => console.log("\x1b[8m", message, "\x1b[0m"),
18497
18502
  error: (message) => console.log("\u001b[31m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18498
18503
  warning: (message) => console.log("\u001b[33m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18499
18504
  };
@@ -18514,6 +18519,16 @@ const executeCommandLine = ({ command, messageOnError, shouldThrowError = false,
18514
18519
  const createShardObject = ({ currentShard = 0, status = "running", duration = null, }) => ({
18515
18520
  [currentShard]: { status, duration },
18516
18521
  });
18522
+ const convertBufferToBlob = (buffer, contentType) => new Blob([buffer], { type: contentType });
18523
+
18524
+ const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
18525
+ run: payload,
18526
+ });
18527
+ const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
18528
+ run: payload,
18529
+ });
18530
+ const heartbeat = (ciBuildId) => axios.get(`${API_BASE_URL}/reporter/runs/${ciBuildId}/heartbeat`);
18531
+ const runsApi = { create: create$1, update, heartbeat };
18517
18532
 
18518
18533
  const getDescribePath = ({ titlePath, title, project, spec, }) => titlePath.filter((item, index) => index !== 0 && item !== title && item !== project && item !== spec);
18519
18534
  const getCurrentCommitSha = () => executeCommandLine({
@@ -18533,6 +18548,15 @@ const getInitializerData = ({ rootDir }, rootSuite) => rootSuite.allTests().map(
18533
18548
  const describe = getDescribePath({ titlePath, title, spec, project });
18534
18549
  return { title, describe, project, spec, history_id };
18535
18550
  });
18551
+ const sendHeartBeatSignal = async (ciBuildId) => {
18552
+ try {
18553
+ await runsApi.heartbeat(ciBuildId);
18554
+ }
18555
+ catch (error) {
18556
+ consoleLogFormatted.error(ERRORS.heartbeat.stopped);
18557
+ process.exit(1);
18558
+ }
18559
+ };
18536
18560
 
18537
18561
  const setAuthHeaders = (projectKey) => {
18538
18562
  var _a;
@@ -18549,14 +18573,6 @@ function initializeAxios({ projectKey, baseURL, }) {
18549
18573
  setAuthHeaders(projectKey);
18550
18574
  }
18551
18575
 
18552
- const create$1 = (payload) => axios.post(`${API_BASE_URL}/reporter/runs`, {
18553
- run: payload,
18554
- });
18555
- const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/${ciBuildId}`, {
18556
- run: payload,
18557
- });
18558
- const runsApi = { create: create$1, update };
18559
-
18560
18576
  const create = (ciBuildId, payload) => axios.post(`${API_BASE_URL}/reporter/runs/${ciBuildId}/test_entities`, {
18561
18577
  test_entity: payload,
18562
18578
  });
@@ -18580,7 +18596,8 @@ class MyReporter {
18580
18596
  test_entities: getInitializerData(config, rootSuite),
18581
18597
  }));
18582
18598
  }
18583
- catch (_a) {
18599
+ catch (error) {
18600
+ consoleLogFormatted.error(error.message);
18584
18601
  throw new Error(ERRORS.onBegin.failedToInitializeRun);
18585
18602
  }
18586
18603
  consoleLogFormatted.underline(MESSAGES.onBegin.testStarted);
@@ -18589,33 +18606,51 @@ class MyReporter {
18589
18606
  consoleLogFormatted.dim(MESSAGES.onBegin.totalShards(shard.total));
18590
18607
  consoleLogFormatted.dim(MESSAGES.onBegin.currentShard(shard.current));
18591
18608
  }
18609
+ await sendHeartBeatSignal(this.ciBuildId);
18610
+ setInterval(async () => await sendHeartBeatSignal(this.ciBuildId), 60000);
18592
18611
  this.attempts = attempts;
18593
18612
  this.config = config;
18594
18613
  this.currentShard = shard === null || shard === void 0 ? void 0 : shard.current;
18595
18614
  };
18596
18615
  this.onTestBegin = async ({ id, title }, { retry }) => {
18616
+ consoleLogFormatted.invertBackground(MESSAGES.onTestBegin.startingTest(title));
18597
18617
  try {
18618
+ const formData = new FormData();
18619
+ formData.append("attempt[status]", "running");
18598
18620
  retry === 0 &&
18599
- (await attemptsApi.update(this.ciBuildId, id, this.attempts[id], {
18600
- status: "running",
18601
- }));
18621
+ (await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData));
18602
18622
  }
18603
- catch (_a) {
18623
+ catch (error) {
18624
+ consoleLogFormatted.error(error.message);
18604
18625
  consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
18605
18626
  }
18606
18627
  };
18607
- this.onTestEnd = async ({ id, title }, { status, duration, errors, retry }) => {
18628
+ this.onTestEnd = async ({ id, title }, { status, duration, errors, retry, attachments }) => {
18608
18629
  try {
18609
18630
  const testResult = {
18610
18631
  status,
18611
18632
  duration,
18612
18633
  log: errors.map(error => { var _a; return (_a = error.message) !== null && _a !== void 0 ? _a : ""; }).join("\n"),
18613
18634
  };
18635
+ consoleLogFormatted.underline(title);
18636
+ const formData = new FormData();
18637
+ attachments.map(({ name, path, body, contentType }) => {
18638
+ consoleLogFormatted.dim(`${name}: ${path}`);
18639
+ if (["screenshot", "video", "trace"].includes(name)) {
18640
+ const buffer = path ? require$$6__default["default"].readFileSync(path) : body;
18641
+ formData.append(`attempt[${name}s][]`, convertBufferToBlob(buffer, contentType));
18642
+ }
18643
+ });
18644
+ Object.entries(testResult).map(([resultKey, resultValue]) => {
18645
+ formData.append(`attempt[${resultKey}]`, resultValue.toString());
18646
+ });
18614
18647
  retry === 0
18615
- ? await attemptsApi.update(this.ciBuildId, id, this.attempts[id], testResult)
18616
- : await attemptsApi.create(this.ciBuildId, id, testResult);
18648
+ ? await attemptsApi.update(this.ciBuildId, id, this.attempts[id], formData)
18649
+ : await attemptsApi.create(this.ciBuildId, id, formData);
18650
+ consoleLogFormatted.invertBackground(MESSAGES.onTestEnd.reportedTest(title));
18617
18651
  }
18618
- catch (_a) {
18652
+ catch (error) {
18653
+ consoleLogFormatted.error(error.message);
18619
18654
  consoleLogFormatted.error(ERRORS.onTestBegin.failedToReportTest(title, id));
18620
18655
  }
18621
18656
  };
@@ -18629,7 +18664,8 @@ class MyReporter {
18629
18664
  }),
18630
18665
  });
18631
18666
  }
18632
- catch (_a) {
18667
+ catch (error) {
18668
+ consoleLogFormatted.error(error.message);
18633
18669
  throw new Error(ERRORS.onEnd.failedToReportRunStatus);
18634
18670
  }
18635
18671
  };