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

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,10 +1,12 @@
1
1
  import type { FullConfig, FullResult, Reporter, Suite, TestCase, TestError, TestResult } from '@playwright/test/reporter';
2
2
  export default class BrowsermationReporter implements Reporter {
3
+ browsermationURL: string;
3
4
  log(message: string): void;
4
5
  constructor(options?: {
5
- customOption?: string;
6
+ reportingURL?: string;
6
7
  });
7
8
  getCurrentBranch(): Promise<string>;
9
+ getCurrentRepo(): Promise<string>;
8
10
  sendData(data: Record<string, any>): Promise<void>;
9
11
  /**
10
12
  * 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
@@ -33,14 +33,17 @@ var regex = (({ onlyFirst = false } = {}) => {
33
33
  })();
34
34
  var stripAnsi = (str) => str.replace(regex, "");
35
35
  var BrowsermationReporter = class {
36
+ browsermationURL = "";
36
37
  log(message) {
37
38
  if (process.env.BM_REPORTER_LOGS) {
38
39
  console.log(message);
39
40
  }
40
41
  }
41
42
  constructor(options = {}) {
43
+ this.browsermationURL = options.reportingURL || process.env.BM_REPORTING_URL || "https://browsermation.com/api/v1/playwright/reporting";
44
+ this.log(`Using Browsermation reporting URL: ${this.browsermationURL}`);
42
45
  this.log(
43
- `my-awesome-reporter setup with customOption set to ${options.customOption}`
46
+ "Using API Token: " + (process.env.BM_API_TOKEN ? process.env.BM_API_TOKEN.slice(0, 4) + "****" : "not set")
44
47
  );
45
48
  }
46
49
  async getCurrentBranch() {
@@ -55,10 +58,25 @@ var BrowsermationReporter = class {
55
58
  });
56
59
  });
57
60
  }
61
+ async getCurrentRepo() {
62
+ return new Promise((resolve) => {
63
+ const { exec } = require("child_process");
64
+ exec(
65
+ "basename `git rev-parse --show-toplevel`",
66
+ (error, stdout) => {
67
+ if (error) {
68
+ resolve("unknown");
69
+ } else {
70
+ resolve(stdout.trim());
71
+ }
72
+ }
73
+ );
74
+ });
75
+ }
58
76
  async sendData(data) {
59
- const url = process.env.BM_REPORTING_URL || "https://browsermation.com/api/v1/playwright/reporting";
77
+ this.log(`Sending data to Browsermation: ${JSON.stringify(data)}`);
60
78
  try {
61
- await fetch(url, {
79
+ await fetch(this.browsermationURL, {
62
80
  method: "POST",
63
81
  headers: {
64
82
  Accept: "application/json",
@@ -84,8 +102,10 @@ var BrowsermationReporter = class {
84
102
  type: "begin",
85
103
  timestamp: Date.now(),
86
104
  hostname: (0, import_node_os.hostname)(),
87
- branch: await this.getCurrentBranch(),
88
- totalTests: suite.allTests().length
105
+ git_branch: await this.getCurrentBranch(),
106
+ git_repo: await this.getCurrentRepo(),
107
+ totalTests: suite.allTests().length,
108
+ cpus: (0, import_node_os.cpus)().length
89
109
  };
90
110
  this.log(`${JSON.stringify(data)}
91
111
  `);
@@ -110,7 +130,9 @@ var BrowsermationReporter = class {
110
130
  type: "test-start",
111
131
  title: test.title,
112
132
  file: test.location.file,
113
- timestamp: Date.now()
133
+ timestamp: Date.now(),
134
+ free_memory: (0, import_node_os.freemem)(),
135
+ total_memory: (0, import_node_os.totalmem)()
114
136
  };
115
137
  this.log(`${JSON.stringify(data)}
116
138
  `);
@@ -125,7 +147,9 @@ var BrowsermationReporter = class {
125
147
  status: result.status,
126
148
  duration: result.duration,
127
149
  errors: stripAnsi(result.error?.message || ""),
128
- timestamp: Date.now()
150
+ timestamp: Date.now(),
151
+ free_memory: (0, import_node_os.freemem)(),
152
+ total_memory: (0, import_node_os.totalmem)()
129
153
  };
130
154
  this.log(`${JSON.stringify(data)}
131
155
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browsermation/test",
3
- "version": "0.0.63-beta.1",
3
+ "version": "0.0.63-beta.3",
4
4
  "description": "The testing platform for Playwright by Browsermation.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",