@bigbinary/neeto-playwright-reporter 1.3.13 → 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,10 +15,10 @@ 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;
21
+ testAttemptIds: string[];
22
22
  constructor(options: ReporterOptionParams);
23
23
  onBegin: (config: FullConfig, rootSuite: Suite) => Promise<void>;
24
24
  onTestBegin: ({ id, title }: TestCase, { retry }: TestResult) => Promise<void>;
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));
@@ -18634,15 +18667,15 @@ class MyReporter {
18634
18667
  };
18635
18668
  this.onTestBegin = async ({ id, title }, { retry }) => {
18636
18669
  var _a, _b;
18670
+ this.retryAttemptStartedAt = new Date();
18637
18671
  this.unreportedAttemptCount++;
18638
18672
  consoleLogFormatted.invertBackground(MESSAGES.onTestBegin.startingTest(title));
18639
18673
  try {
18640
- this.retryAttemptStartedAt = new Date();
18641
18674
  while (!((_b = (_a = this.attempts) === null || _a === void 0 ? void 0 : _a[id]) === null || _b === void 0 ? void 0 : _b["0"]))
18642
18675
  await waitUntilTimeout(100); // Poll every 100 milliseconds
18643
18676
  const attemptsPayload = {
18644
18677
  status: "running",
18645
- started_at: new Date().toString(),
18678
+ started_at: this.retryAttemptStartedAt.toString(),
18646
18679
  shard: this.currentShard,
18647
18680
  };
18648
18681
  if (retry === 0) {
@@ -18657,6 +18690,7 @@ class MyReporter {
18657
18690
  [String(retry)]: attempt_id,
18658
18691
  },
18659
18692
  };
18693
+ this.testAttemptIds.push(`${history_id}-${attempt_id}`);
18660
18694
  }
18661
18695
  }
18662
18696
  catch (error) {
@@ -18698,7 +18732,8 @@ class MyReporter {
18698
18732
  return uploadToS3(file, direct_upload);
18699
18733
  }
18700
18734
  }));
18701
- while (!this.attempts[id][retry])
18735
+ while (!(this.attempts[id][retry] ||
18736
+ this.testAttemptIds.includes(`${id}-${this.attempts[id][retry]}`)))
18702
18737
  await waitUntilTimeout(100);
18703
18738
  this.testResultCalls.push(attemptsApi.update(this.ciBuildId, id, this.attempts[id][retry], testResult));
18704
18739
  }
@@ -18708,16 +18743,13 @@ class MyReporter {
18708
18743
  }
18709
18744
  finally {
18710
18745
  this.unreportedAttemptCount--;
18711
- retry === 0 && this.reportedTestCount++;
18712
18746
  consoleLogFormatted.invertBackground(MESSAGES.onTestEnd.reportedTest(title));
18713
18747
  }
18714
18748
  };
18715
18749
  this.onEnd = async ({ status, duration }) => {
18716
18750
  var _a, _b;
18717
18751
  try {
18718
- while (!(this.hasRunStarted &&
18719
- this.totalTestCount === this.reportedTestCount &&
18720
- this.unreportedAttemptCount === 0))
18752
+ while (!(this.hasRunStarted && this.unreportedAttemptCount === 0))
18721
18753
  await waitUntilTimeout(100);
18722
18754
  await Promise.allSettled(this.testResultCalls);
18723
18755
  await runsApi.update(this.ciBuildId, {
@@ -18730,8 +18762,8 @@ class MyReporter {
18730
18762
  }
18731
18763
  catch (error) {
18732
18764
  const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
18733
- consoleLogFormatted.error((_b = data === null || data === void 0 ? void 0 : data.error) !== null && _b !== void 0 ? _b : error.message);
18734
- 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);
18735
18767
  }
18736
18768
  finally {
18737
18769
  consoleLogFormatted.invertBackground(MESSAGES.onEnd.runReported);
@@ -18744,9 +18776,9 @@ class MyReporter {
18744
18776
  this.retryAttemptStartedAt = new Date();
18745
18777
  this.testResultCalls = [];
18746
18778
  this.totalTestCount = 0;
18747
- this.reportedTestCount = 0;
18748
18779
  this.unreportedAttemptCount = 0;
18749
18780
  this.hasRunStarted = false;
18781
+ this.testAttemptIds = [];
18750
18782
  process.on("unhandledRejection", error => {
18751
18783
  var _a, _b, _c;
18752
18784
  const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;