@browsermation/test 0.0.63-beta.9 → 0.0.64
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/dist/reporter/reporter.d.ts +6 -2
- package/dist/reporter.js +104 -20
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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.
|
|
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
|
}
|
|
@@ -54,6 +60,12 @@ var BrowsermationReporter = class {
|
|
|
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,12 +134,36 @@ 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) {
|
|
108
156
|
if (!this.apiToken) {
|
|
109
157
|
this.log("API token not set. Skipping sending data to Browsermation.");
|
|
110
158
|
return;
|
|
111
159
|
}
|
|
112
160
|
this.log(`Sending data to Browsermation: ${JSON.stringify(data)}`);
|
|
161
|
+
if (process.env.BM_REPORTER_ONLY_LOG_EVENTS) {
|
|
162
|
+
this.log(
|
|
163
|
+
"BM_REPORTER_ONLY_LOG_EVENTS is set to true. Skipping sending data to Browsermation."
|
|
164
|
+
);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
113
167
|
try {
|
|
114
168
|
const response = await fetch(this.browsermationURL, {
|
|
115
169
|
method: "POST",
|
|
@@ -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,29 +205,32 @@ var BrowsermationReporter = class {
|
|
|
140
205
|
async onBegin(_config, suite) {
|
|
141
206
|
const data = {
|
|
142
207
|
type: "begin",
|
|
143
|
-
timestamp: Date.
|
|
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
218
|
this.log(`${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
|
-
|
|
162
|
-
|
|
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.
|
|
165
|
-
hostname: (0, import_node_os.hostname)()
|
|
233
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
166
234
|
};
|
|
167
235
|
this.log(`${JSON.stringify(data)}
|
|
168
236
|
`);
|
|
@@ -173,28 +241,42 @@ var BrowsermationReporter = class {
|
|
|
173
241
|
id: test.id,
|
|
174
242
|
type: "test-start",
|
|
175
243
|
title: test.title,
|
|
176
|
-
file: test.location.file,
|
|
177
|
-
|
|
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
|
-
|
|
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
|
-
|
|
265
|
+
title_path: test.titlePath,
|
|
266
|
+
result: result.status,
|
|
192
267
|
status: result.status,
|
|
193
|
-
|
|
268
|
+
duration_in_ms: result.duration,
|
|
194
269
|
errors: stripAnsi(result.error?.message || ""),
|
|
195
|
-
timestamp: Date.
|
|
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
281
|
this.log(`${JSON.stringify(data)}
|
|
200
282
|
`);
|
|
@@ -203,9 +285,10 @@ var BrowsermationReporter = class {
|
|
|
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.
|
|
291
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
209
292
|
};
|
|
210
293
|
console.error(`${JSON.stringify(data)}
|
|
211
294
|
`);
|
|
@@ -214,7 +297,8 @@ var BrowsermationReporter = class {
|
|
|
214
297
|
async onExit() {
|
|
215
298
|
const data = {
|
|
216
299
|
type: "exit",
|
|
217
|
-
|
|
300
|
+
suite_run_id: this.suiteRunId,
|
|
301
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
218
302
|
};
|
|
219
303
|
this.log(`${JSON.stringify(data)}
|
|
220
304
|
`);
|