@browsermation/test 0.0.63-beta.2 → 0.0.63-beta.4

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,11 +1,14 @@
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>;
11
+ getCurrentRepo(): Promise<string>;
9
12
  sendData(data: Record<string, any>): Promise<void>;
10
13
  /**
11
14
  * onBegin() is called once with a root suite that contains all other suites and tests. Learn more about suites hierarchy.
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,9 +42,10 @@ 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
  );
48
50
  }
49
51
  async getCurrentBranch() {
@@ -58,18 +60,38 @@ var BrowsermationReporter = class {
58
60
  });
59
61
  });
60
62
  }
63
+ async getCurrentRepo() {
64
+ return new Promise((resolve) => {
65
+ const { exec } = require("child_process");
66
+ exec(
67
+ "basename `git rev-parse --show-toplevel`",
68
+ (error, stdout) => {
69
+ if (error) {
70
+ resolve("unknown");
71
+ } else {
72
+ resolve(stdout.trim());
73
+ }
74
+ }
75
+ );
76
+ });
77
+ }
61
78
  async sendData(data) {
62
79
  this.log(`Sending data to Browsermation: ${JSON.stringify(data)}`);
63
80
  try {
64
- await fetch(this.browsermationURL, {
81
+ const response = await fetch(this.browsermationURL, {
65
82
  method: "POST",
66
83
  headers: {
67
84
  Accept: "application/json",
68
85
  "Content-Type": "application/json",
69
- Authorization: `Bearer ${process.env.BM_API_TOKEN}`
86
+ Authorization: `Bearer ${this.apiToken}`
70
87
  },
71
88
  body: JSON.stringify(data)
72
89
  });
90
+ if (!response.ok) {
91
+ this.log(
92
+ `Failed to send data to Browsermation. Status: ${response.status} - ${response.statusText}`
93
+ );
94
+ }
73
95
  } catch (error) {
74
96
  console.error("Error sending data to Browsermation:", error);
75
97
  }
@@ -87,8 +109,10 @@ var BrowsermationReporter = class {
87
109
  type: "begin",
88
110
  timestamp: Date.now(),
89
111
  hostname: (0, import_node_os.hostname)(),
90
- branch: await this.getCurrentBranch(),
91
- totalTests: suite.allTests().length
112
+ git_branch: await this.getCurrentBranch(),
113
+ git_repo: await this.getCurrentRepo(),
114
+ totalTests: suite.allTests().length,
115
+ cpus: (0, import_node_os.cpus)().length
92
116
  };
93
117
  this.log(`${JSON.stringify(data)}
94
118
  `);
@@ -113,7 +137,9 @@ var BrowsermationReporter = class {
113
137
  type: "test-start",
114
138
  title: test.title,
115
139
  file: test.location.file,
116
- timestamp: Date.now()
140
+ timestamp: Date.now(),
141
+ free_memory: (0, import_node_os.freemem)(),
142
+ total_memory: (0, import_node_os.totalmem)()
117
143
  };
118
144
  this.log(`${JSON.stringify(data)}
119
145
  `);
@@ -128,7 +154,9 @@ var BrowsermationReporter = class {
128
154
  status: result.status,
129
155
  duration: result.duration,
130
156
  errors: stripAnsi(result.error?.message || ""),
131
- timestamp: Date.now()
157
+ timestamp: Date.now(),
158
+ free_memory: (0, import_node_os.freemem)(),
159
+ total_memory: (0, import_node_os.totalmem)()
132
160
  };
133
161
  this.log(`${JSON.stringify(data)}
134
162
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsermation/test",
3
- "version": "0.0.63-beta.2",
3
+ "version": "0.0.63-beta.4",
4
4
  "description": "The testing platform for Playwright by Browsermation.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",