@browsermation/test 0.0.63-beta.9 → 0.0.65

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,8 +1,10 @@
1
- import type { FullConfig, FullResult, Reporter, Suite, TestCase, TestError, TestResult } from '@playwright/test/reporter';
1
+ import type { FullConfig, FullProject, FullResult, Reporter, Suite, TestCase, TestError, TestResult } from '@playwright/test/reporter';
2
2
  export default class BrowsermationReporter implements Reporter {
3
3
  browsermationURL: string;
4
4
  apiToken: string;
5
+ suiteRunId: string | null;
5
6
  log(message: string): void;
7
+ logEvent(message: string): void;
6
8
  constructor(options?: {
7
9
  reportingURL?: string;
8
10
  apiToken?: string;
@@ -11,7 +13,9 @@ export default class BrowsermationReporter implements Reporter {
11
13
  getCurrentRepo(): Promise<string>;
12
14
  getLatestCommitId(): Promise<string>;
13
15
  getLatestCommitMessage(): Promise<string>;
14
- sendData(data: Record<string, any>): Promise<void>;
16
+ gitRemoteOriginUrl(): Promise<string>;
17
+ sendData(data: Record<string, any>): Promise<any>;
18
+ getProjectSuite(parent: Suite): FullProject | undefined;
15
19
  /**
16
20
  * onBegin() is called once with a root suite that contains all other suites and tests. Learn more about suites hierarchy.
17
21
  *
package/dist/reporter.js CHANGED
@@ -35,8 +35,14 @@ var stripAnsi = (str) => str.replace(regex, "");
35
35
  var BrowsermationReporter = class {
36
36
  browsermationURL = "";
37
37
  apiToken = "";
38
+ suiteRunId = null;
38
39
  log(message) {
39
- if (process.env.BM_REPORTER_LOGS) {
40
+ if (process.env.BM_REPORTER_DEBUG_LOGS) {
41
+ console.log(message);
42
+ }
43
+ }
44
+ logEvent(message) {
45
+ if (process.env.BM_REPORTER_ONLY_LOG_EVENTS) {
40
46
  console.log(message);
41
47
  }
42
48
  }
@@ -47,13 +53,19 @@ var BrowsermationReporter = class {
47
53
  this.log(
48
54
  "Using API Token: " + (this.apiToken ? this.apiToken.slice(0, 4) + "****" : "not set")
49
55
  );
50
- if (!this.apiToken) {
56
+ if (!this.apiToken && !process.env.BM_REPORTER_ONLY_LOG_EVENTS) {
51
57
  console.warn(
52
58
  "Warning: No API token set for Browsermation Reporter. Set BM_API_TOKEN environment variable or pass apiToken in reporter options."
53
59
  );
54
60
  }
55
61
  }
56
62
  async getCurrentBranch() {
63
+ if (process.env.BM_REPORTER_DISABLE_GIT_INFO) {
64
+ this.log(
65
+ "BM_REPORTER_DISABLE_GIT_INFO is set to true. Skipping git info."
66
+ );
67
+ return;
68
+ }
57
69
  return new Promise((resolve) => {
58
70
  const { exec } = require("child_process");
59
71
  exec("git rev-parse --abbrev-ref HEAD", (error, stdout) => {
@@ -66,6 +78,12 @@ var BrowsermationReporter = class {
66
78
  });
67
79
  }
68
80
  async getCurrentRepo() {
81
+ if (process.env.BM_REPORTER_DISABLE_GIT_INFO) {
82
+ this.log(
83
+ "BM_REPORTER_DISABLE_GIT_INFO is set to true. Skipping git info."
84
+ );
85
+ return;
86
+ }
69
87
  return new Promise((resolve) => {
70
88
  const { exec } = require("child_process");
71
89
  exec(
@@ -81,6 +99,12 @@ var BrowsermationReporter = class {
81
99
  });
82
100
  }
83
101
  async getLatestCommitId() {
102
+ if (process.env.BM_REPORTER_DISABLE_GIT_INFO) {
103
+ this.log(
104
+ "BM_REPORTER_DISABLE_GIT_INFO is set to true. Skipping git info."
105
+ );
106
+ return;
107
+ }
84
108
  return new Promise((resolve) => {
85
109
  const { exec } = require("child_process");
86
110
  exec("git rev-parse HEAD", (error, stdout) => {
@@ -93,6 +117,12 @@ var BrowsermationReporter = class {
93
117
  });
94
118
  }
95
119
  async getLatestCommitMessage() {
120
+ if (process.env.BM_REPORTER_DISABLE_GIT_INFO) {
121
+ this.log(
122
+ "BM_REPORTER_DISABLE_GIT_INFO is set to true. Skipping git info."
123
+ );
124
+ return;
125
+ }
96
126
  return new Promise((resolve) => {
97
127
  const { exec } = require("child_process");
98
128
  exec("git log -1 --pretty=%B", (error, stdout) => {
@@ -104,7 +134,31 @@ var BrowsermationReporter = class {
104
134
  });
105
135
  });
106
136
  }
137
+ async gitRemoteOriginUrl() {
138
+ if (process.env.BM_REPORTER_DISABLE_GIT_INFO) {
139
+ this.log(
140
+ "BM_REPORTER_DISABLE_GIT_INFO is set to true. Skipping git info."
141
+ );
142
+ return;
143
+ }
144
+ return new Promise((resolve) => {
145
+ const { exec } = require("child_process");
146
+ exec("git remote get-url origin", (error, stdout) => {
147
+ if (error) {
148
+ resolve("unknown");
149
+ } else {
150
+ resolve(stdout.trim());
151
+ }
152
+ });
153
+ });
154
+ }
107
155
  async sendData(data) {
156
+ if (process.env.BM_REPORTER_ONLY_LOG_EVENTS) {
157
+ this.log(
158
+ "BM_REPORTER_ONLY_LOG_EVENTS is set to true. Skipping sending data to Browsermation."
159
+ );
160
+ return;
161
+ }
108
162
  if (!this.apiToken) {
109
163
  this.log("API token not set. Skipping sending data to Browsermation.");
110
164
  return;
@@ -125,10 +179,21 @@ var BrowsermationReporter = class {
125
179
  `Failed to send data to Browsermation. Status: ${response.status} - ${response.statusText}`
126
180
  );
127
181
  }
182
+ return await response.json();
128
183
  } catch (error) {
129
184
  console.error("Error sending data to Browsermation:", error);
130
185
  }
131
186
  }
187
+ getProjectSuite(parent) {
188
+ let currentSuite = parent;
189
+ while (currentSuite.parent) {
190
+ if (currentSuite.project()) {
191
+ break;
192
+ }
193
+ currentSuite = currentSuite.parent;
194
+ }
195
+ return currentSuite.project();
196
+ }
132
197
  /**
133
198
  * onBegin() is called once with a root suite that contains all other suites and tests. Learn more about suites hierarchy.
134
199
  *
@@ -140,31 +205,34 @@ var BrowsermationReporter = class {
140
205
  async onBegin(_config, suite) {
141
206
  const data = {
142
207
  type: "begin",
143
- timestamp: Date.now(),
144
- hostname: (0, import_node_os.hostname)(),
208
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
145
209
  git_branch: await this.getCurrentBranch(),
146
210
  git_repo: await this.getCurrentRepo(),
147
211
  git_commit_id: await this.getLatestCommitId(),
148
212
  git_commit_message: await this.getLatestCommitMessage(),
213
+ git_remote_origin_url: await this.gitRemoteOriginUrl(),
149
214
  totalTests: suite.allTests().length,
150
- cpus: (0, import_node_os.cpus)().length,
151
215
  playwright_version: _config.version,
152
216
  node_version: process.version
153
217
  };
154
- this.log(`${JSON.stringify(data)}
218
+ this.logEvent(`${JSON.stringify(data)}
155
219
  `);
156
- await this.sendData(data);
220
+ const response = await this.sendData(data);
221
+ if (response?.data?.suite_run_id) {
222
+ this.suiteRunId = response.data.suite_run_id;
223
+ this.log(`Received suite_run_id: ${this.suiteRunId}`);
224
+ }
157
225
  }
158
226
  async onEnd(result) {
159
227
  const data = {
160
228
  type: "end",
161
- startTime: result.startTime,
162
- duration: result.duration,
229
+ suite_run_id: this.suiteRunId,
230
+ start_time: result.startTime,
231
+ duration_in_ms: result.duration,
163
232
  status: result.status,
164
- timestamp: Date.now(),
165
- hostname: (0, import_node_os.hostname)()
233
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
166
234
  };
167
- this.log(`${JSON.stringify(data)}
235
+ this.logEvent(`${JSON.stringify(data)}
168
236
  `);
169
237
  await this.sendData(data);
170
238
  }
@@ -173,50 +241,66 @@ var BrowsermationReporter = class {
173
241
  id: test.id,
174
242
  type: "test-start",
175
243
  title: test.title,
176
- file: test.location.file,
177
- timestamp: Date.now(),
244
+ file: test.location.file.replace(process.cwd(), ""),
245
+ hostname: (0, import_node_os.hostname)(),
246
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
178
247
  free_memory: (0, import_node_os.freemem)(),
179
248
  total_memory: (0, import_node_os.totalmem)(),
180
- project: test.parent.project.name
249
+ cpus: (0, import_node_os.cpus)().length,
250
+ cpu_architecture: process.arch,
251
+ retries: test.retries,
252
+ project_name: this.getProjectSuite(test.parent)?.name,
253
+ project_default_browser_type: this.getProjectSuite(test.parent)?.use.defaultBrowserType,
254
+ suite_title: test.parent.title
181
255
  };
182
- this.log(`${JSON.stringify(data)}
183
- `);
184
256
  await this.sendData(data);
185
257
  }
186
258
  async onTestEnd(test, result) {
187
259
  const data = {
188
260
  id: test.id,
261
+ suite_run_id: this.suiteRunId,
189
262
  type: "test-end",
263
+ project: test.parent.project.name,
190
264
  title: test.title,
191
- titlePath: test.titlePath,
265
+ title_path: test.titlePath,
266
+ result: result.status,
192
267
  status: result.status,
193
- duration: result.duration,
268
+ duration_in_ms: result.duration,
194
269
  errors: stripAnsi(result.error?.message || ""),
195
- timestamp: Date.now(),
270
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
196
271
  free_memory: (0, import_node_os.freemem)(),
197
- total_memory: (0, import_node_os.totalmem)()
272
+ total_memory: (0, import_node_os.totalmem)(),
273
+ cpu_architecture: process.arch,
274
+ cpus: (0, import_node_os.cpus)().length,
275
+ hostname: (0, import_node_os.hostname)(),
276
+ retries: test.retries,
277
+ retry_attempt: result.retry,
278
+ stderr: result.stderr.map((s) => stripAnsi(s.toString())).join("\n"),
279
+ stdout: result.stdout.map((s) => stripAnsi(s.toString())).join("\n")
198
280
  };
199
- this.log(`${JSON.stringify(data)}
281
+ this.logEvent(`${JSON.stringify(data)}
200
282
  `);
201
283
  await this.sendData(data);
202
284
  }
203
285
  async onError(error) {
204
286
  const data = {
205
287
  type: "error",
288
+ suite_run_id: this.suiteRunId,
206
289
  message: error.message,
207
290
  stack: error.stack,
208
- timestamp: Date.now()
291
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
209
292
  };
210
- console.error(`${JSON.stringify(data)}
293
+ this.logEvent(`${JSON.stringify(data)}
211
294
  `);
212
295
  await this.sendData(data);
213
296
  }
214
297
  async onExit() {
215
298
  const data = {
216
299
  type: "exit",
217
- timestamp: Date.now()
300
+ suite_run_id: this.suiteRunId,
301
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
218
302
  };
219
- this.log(`${JSON.stringify(data)}
303
+ this.logEvent(`${JSON.stringify(data)}
220
304
  `);
221
305
  await this.sendData(data);
222
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsermation/test",
3
- "version": "0.0.63-beta.9",
3
+ "version": "0.0.65",
4
4
  "description": "The testing platform for Playwright by Browsermation.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",