@bigbinary/neeto-playwright-reporter 1.3.14 → 1.3.15

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.d.ts CHANGED
@@ -15,7 +15,6 @@ declare class MyReporter implements Reporter {
15
15
  retryAttemptStartedAt: Date;
16
16
  testResultCalls: Promise<unknown>[];
17
17
  totalTestCount: number;
18
- reportedTestCount: number;
19
18
  tags: string[] | string;
20
19
  unreportedAttemptCount: number;
21
20
  hasRunStarted: boolean;
package/index.js CHANGED
@@ -10,8 +10,8 @@ import require$$1$2 from 'tty';
10
10
  import require$$0$2 from 'os';
11
11
  import zlib from 'zlib';
12
12
  import EventEmitter from 'events';
13
- import childProcess from 'child_process';
14
13
  import crypto from 'crypto';
14
+ import childProcess from 'child_process';
15
15
 
16
16
  function bind(fn, thisArg) {
17
17
  return function wrap() {
@@ -18487,34 +18487,52 @@ const MESSAGES = {
18487
18487
  },
18488
18488
  };
18489
18489
 
18490
- const consoleLogFormatted = {
18491
- bold: (message) => console.log("\x1b[1m", message, "\x1b[0m"),
18492
- dim: (message) => console.log("\x1b[2m", message, "\x1b[0m"),
18493
- underline: (message) => console.log("\x1b[4m", message, "\x1b[0m"),
18494
- invertBackground: (message) => console.log("\x1b[7m", message, "\x1b[0m"),
18495
- hidden: (message) => console.log("\x1b[8m", message, "\x1b[0m"),
18496
- error: (message) => console.log("\u001b[31m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18497
- warning: (message) => console.log("\u001b[33m", "\x1b[1m", message, "\x1b[0m", "\u001b[0m"),
18498
- };
18499
- const executeCommandLine = ({ command, messageOnError, shouldThrowError = false, logLevel = "warning", }) => {
18500
- try {
18501
- return childProcess.execSync(command).toString().trim();
18502
- }
18503
- catch (err) {
18504
- if (shouldThrowError) {
18505
- throw err;
18506
- }
18507
- else {
18508
- consoleLogFormatted[logLevel](messageOnError);
18509
- }
18510
- }
18511
- };
18512
-
18513
18490
  const createShardObject = ({ currentShard = 0, status = "running", duration = null, }) => ({
18514
18491
  [currentShard]: { status, duration },
18515
18492
  });
18516
18493
  const waitUntilTimeout = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
18517
18494
 
18495
+ const LOG_LEVEL_FORMATTERS = {
18496
+ bold: "\x1b[1m",
18497
+ dim: "\x1b[2m",
18498
+ underline: "\x1b[4m",
18499
+ invertBackground: "\x1b[7m",
18500
+ hidden: "\x1b[8m",
18501
+ error: "\u001b[31m\x1b[1m",
18502
+ warning: "\u001b[33m\x1b[1m",
18503
+ };
18504
+
18505
+ class ConsoleLogFormatted {
18506
+ constructor() {
18507
+ this.LOG_LEVELS = {
18508
+ info: ["bold", "dim", "underline", "invertBackground", "hidden"],
18509
+ get warning() {
18510
+ return [...this.info, "warning"];
18511
+ },
18512
+ get error() {
18513
+ return [...this.warning, "error"];
18514
+ },
18515
+ };
18516
+ this.shouldPrintMessage = (type) => {
18517
+ var _a;
18518
+ const logLevel = ((_a = process.env.PLAYDASH_LOG_LEVEL) !== null && _a !== void 0 ? _a : "info");
18519
+ const validMethods = this.LOG_LEVELS[logLevel] || [];
18520
+ return validMethods.includes(type);
18521
+ };
18522
+ Object.entries(LOG_LEVEL_FORMATTERS).forEach(([logLevel, ansiFormatter]) => {
18523
+ this.createMethod(logLevel, ansiFormatter);
18524
+ });
18525
+ }
18526
+ createMethod(logLevel, ansiFormatter) {
18527
+ this[logLevel] = (message) => {
18528
+ if (this.shouldPrintMessage(logLevel)) {
18529
+ console.log(`${ansiFormatter}${message}\x1b[0m\u001b[0m`);
18530
+ }
18531
+ };
18532
+ }
18533
+ }
18534
+ var consoleLogFormatted = new ConsoleLogFormatted();
18535
+
18518
18536
  const getFileData = (file, contentType, filename) => {
18519
18537
  const byte_size = file.byteLength;
18520
18538
  const checksum = crypto.createHash("md5").update(file).digest("base64");
@@ -18530,6 +18548,20 @@ const update = (ciBuildId, payload) => axios.put(`${API_BASE_URL}/reporter/runs/
18530
18548
  const heartbeat = (ciBuildId) => axios.get(`${API_BASE_URL}/reporter/runs/${ciBuildId}/heartbeat`);
18531
18549
  const runsApi = { create: create$1, update, heartbeat };
18532
18550
 
18551
+ const executeCommandLine = ({ command, messageOnError, shouldThrowError = false, logLevel = "warning", }) => {
18552
+ try {
18553
+ return childProcess.execSync(command).toString().trim();
18554
+ }
18555
+ catch (err) {
18556
+ if (shouldThrowError) {
18557
+ throw err;
18558
+ }
18559
+ else {
18560
+ consoleLogFormatted[logLevel](messageOnError);
18561
+ }
18562
+ }
18563
+ };
18564
+
18533
18565
  const getDescribePath = ({ titlePath, title, project, spec, }) => titlePath.filter((item, index) => index !== 0 && item !== title && item !== project && item !== spec);
18534
18566
  const getCurrentCommitSha = () => executeCommandLine({
18535
18567
  command: "git rev-parse HEAD",
@@ -18595,7 +18627,7 @@ class MyReporter {
18595
18627
  this.currentShard = shard === null || shard === void 0 ? void 0 : shard.current;
18596
18628
  let attempts;
18597
18629
  this.totalTestCount = rootSuite.allTests().length;
18598
- consoleLogFormatted.bold("Started reporting to neetoPlaydash 🎭");
18630
+ consoleLogFormatted.bold("Started reporting to NeetoPlaydash 🎭");
18599
18631
  try {
18600
18632
  const runDetails = {
18601
18633
  commit_id: getCurrentCommitSha(),
@@ -18620,7 +18652,8 @@ class MyReporter {
18620
18652
  catch (error) {
18621
18653
  const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
18622
18654
  consoleLogFormatted.error((_b = data === null || data === void 0 ? void 0 : data.error) !== null && _b !== void 0 ? _b : error.message);
18623
- throw new Error(ERRORS.onBegin.failedToInitializeRun);
18655
+ consoleLogFormatted.error(ERRORS.onBegin.failedToInitializeRun);
18656
+ process.exit(1);
18624
18657
  }
18625
18658
  consoleLogFormatted.underline(MESSAGES.onBegin.testStarted);
18626
18659
  consoleLogFormatted.dim(MESSAGES.onBegin.ciBuildId(this.ciBuildId));
@@ -18710,16 +18743,13 @@ class MyReporter {
18710
18743
  }
18711
18744
  finally {
18712
18745
  this.unreportedAttemptCount--;
18713
- retry === 0 && this.reportedTestCount++;
18714
18746
  consoleLogFormatted.invertBackground(MESSAGES.onTestEnd.reportedTest(title));
18715
18747
  }
18716
18748
  };
18717
18749
  this.onEnd = async ({ status, duration }) => {
18718
18750
  var _a, _b;
18719
18751
  try {
18720
- while (!(this.hasRunStarted &&
18721
- this.totalTestCount === this.reportedTestCount &&
18722
- this.unreportedAttemptCount === 0))
18752
+ while (!(this.hasRunStarted && this.unreportedAttemptCount === 0))
18723
18753
  await waitUntilTimeout(100);
18724
18754
  await Promise.allSettled(this.testResultCalls);
18725
18755
  await runsApi.update(this.ciBuildId, {
@@ -18732,8 +18762,8 @@ class MyReporter {
18732
18762
  }
18733
18763
  catch (error) {
18734
18764
  const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
18735
- consoleLogFormatted.error((_b = data === null || data === void 0 ? void 0 : data.error) !== null && _b !== void 0 ? _b : error.message);
18736
- throw new Error(ERRORS.onEnd.failedToReportRunStatus);
18765
+ consoleLogFormatted.error((_b = data.error) !== null && _b !== void 0 ? _b : error.message);
18766
+ consoleLogFormatted.error(ERRORS.onEnd.failedToReportRunStatus);
18737
18767
  }
18738
18768
  finally {
18739
18769
  consoleLogFormatted.invertBackground(MESSAGES.onEnd.runReported);
@@ -18746,7 +18776,6 @@ class MyReporter {
18746
18776
  this.retryAttemptStartedAt = new Date();
18747
18777
  this.testResultCalls = [];
18748
18778
  this.totalTestCount = 0;
18749
- this.reportedTestCount = 0;
18750
18779
  this.unreportedAttemptCount = 0;
18751
18780
  this.hasRunStarted = false;
18752
18781
  this.testAttemptIds = [];