@browsermation/test 0.0.63-beta.3 → 0.0.63-beta.5

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.
@@ -1,9 +1,11 @@
1
1
  import type { FullConfig, FullResult, Reporter, Suite, TestCase, TestError, TestResult } from '@playwright/test/reporter';
2
2
  export default class BrowsermationReporter implements Reporter {
3
3
  browsermationURL: string;
4
+ apiToken: string;
4
5
  log(message: string): void;
5
6
  constructor(options?: {
6
7
  reportingURL?: string;
8
+ apiToken?: string;
7
9
  });
8
10
  getCurrentBranch(): Promise<string>;
9
11
  getCurrentRepo(): Promise<string>;
package/dist/reporter.js CHANGED
@@ -34,6 +34,7 @@ var regex = (({ onlyFirst = false } = {}) => {
34
34
  var stripAnsi = (str) => str.replace(regex, "");
35
35
  var BrowsermationReporter = class {
36
36
  browsermationURL = "";
37
+ apiToken = "";
37
38
  log(message) {
38
39
  if (process.env.BM_REPORTER_LOGS) {
39
40
  console.log(message);
@@ -41,10 +42,16 @@ var BrowsermationReporter = class {
41
42
  }
42
43
  constructor(options = {}) {
43
44
  this.browsermationURL = options.reportingURL || process.env.BM_REPORTING_URL || "https://browsermation.com/api/v1/playwright/reporting";
45
+ this.apiToken = options.apiToken || process.env.BM_API_TOKEN || "";
44
46
  this.log(`Using Browsermation reporting URL: ${this.browsermationURL}`);
45
47
  this.log(
46
- "Using API Token: " + (process.env.BM_API_TOKEN ? process.env.BM_API_TOKEN.slice(0, 4) + "****" : "not set")
48
+ "Using API Token: " + (this.apiToken ? this.apiToken.slice(0, 4) + "****" : "not set")
47
49
  );
50
+ if (!this.apiToken) {
51
+ console.warn(
52
+ "Warning: No API token set for Browsermation Reporter. Set BM_API_TOKEN environment variable or pass apiToken in reporter options."
53
+ );
54
+ }
48
55
  }
49
56
  async getCurrentBranch() {
50
57
  return new Promise((resolve) => {
@@ -74,17 +81,26 @@ var BrowsermationReporter = class {
74
81
  });
75
82
  }
76
83
  async sendData(data) {
84
+ if (!this.apiToken) {
85
+ this.log("API token not set. Skipping sending data to Browsermation.");
86
+ return;
87
+ }
77
88
  this.log(`Sending data to Browsermation: ${JSON.stringify(data)}`);
78
89
  try {
79
- await fetch(this.browsermationURL, {
90
+ const response = await fetch(this.browsermationURL, {
80
91
  method: "POST",
81
92
  headers: {
82
93
  Accept: "application/json",
83
94
  "Content-Type": "application/json",
84
- Authorization: `Bearer ${process.env.BM_API_TOKEN}`
95
+ Authorization: `Bearer ${this.apiToken}`
85
96
  },
86
97
  body: JSON.stringify(data)
87
98
  });
99
+ if (!response.ok) {
100
+ this.log(
101
+ `Failed to send data to Browsermation. Status: ${response.status} - ${response.statusText}`
102
+ );
103
+ }
88
104
  } catch (error) {
89
105
  console.error("Error sending data to Browsermation:", error);
90
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsermation/test",
3
- "version": "0.0.63-beta.3",
3
+ "version": "0.0.63-beta.5",
4
4
  "description": "The testing platform for Playwright by Browsermation.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",