@browsermation/test 0.0.63-beta.1 → 0.0.63-beta.11
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 +8 -1
- package/dist/reporter.js +90 -8
- package/package.json +1 -1
|
@@ -1,10 +1,17 @@
|
|
|
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;
|
|
4
|
+
apiToken: string;
|
|
3
5
|
log(message: string): void;
|
|
4
6
|
constructor(options?: {
|
|
5
|
-
|
|
7
|
+
reportingURL?: string;
|
|
8
|
+
apiToken?: string;
|
|
6
9
|
});
|
|
7
10
|
getCurrentBranch(): Promise<string>;
|
|
11
|
+
getCurrentRepo(): Promise<string>;
|
|
12
|
+
getLatestCommitId(): Promise<string>;
|
|
13
|
+
getLatestCommitMessage(): Promise<string>;
|
|
14
|
+
gitRemoteOriginUrl(): Promise<string>;
|
|
8
15
|
sendData(data: Record<string, any>): Promise<void>;
|
|
9
16
|
/**
|
|
10
17
|
* 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,15 +33,25 @@ var regex = (({ onlyFirst = false } = {}) => {
|
|
|
33
33
|
})();
|
|
34
34
|
var stripAnsi = (str) => str.replace(regex, "");
|
|
35
35
|
var BrowsermationReporter = class {
|
|
36
|
+
browsermationURL = "";
|
|
37
|
+
apiToken = "";
|
|
36
38
|
log(message) {
|
|
37
39
|
if (process.env.BM_REPORTER_LOGS) {
|
|
38
40
|
console.log(message);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
constructor(options = {}) {
|
|
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 || "";
|
|
46
|
+
this.log(`Using Browsermation reporting URL: ${this.browsermationURL}`);
|
|
42
47
|
this.log(
|
|
43
|
-
|
|
48
|
+
"Using API Token: " + (this.apiToken ? this.apiToken.slice(0, 4) + "****" : "not set")
|
|
44
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
|
+
}
|
|
45
55
|
}
|
|
46
56
|
async getCurrentBranch() {
|
|
47
57
|
return new Promise((resolve) => {
|
|
@@ -55,18 +65,78 @@ var BrowsermationReporter = class {
|
|
|
55
65
|
});
|
|
56
66
|
});
|
|
57
67
|
}
|
|
68
|
+
async getCurrentRepo() {
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const { exec } = require("child_process");
|
|
71
|
+
exec(
|
|
72
|
+
"basename `git rev-parse --show-toplevel`",
|
|
73
|
+
(error, stdout) => {
|
|
74
|
+
if (error) {
|
|
75
|
+
resolve("unknown");
|
|
76
|
+
} else {
|
|
77
|
+
resolve(stdout.trim());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async getLatestCommitId() {
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const { exec } = require("child_process");
|
|
86
|
+
exec("git rev-parse HEAD", (error, stdout) => {
|
|
87
|
+
if (error) {
|
|
88
|
+
resolve("unknown");
|
|
89
|
+
} else {
|
|
90
|
+
resolve(stdout.trim());
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async getLatestCommitMessage() {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
const { exec } = require("child_process");
|
|
98
|
+
exec("git log -1 --pretty=%B", (error, stdout) => {
|
|
99
|
+
if (error) {
|
|
100
|
+
resolve("unknown");
|
|
101
|
+
} else {
|
|
102
|
+
resolve(stdout.trim());
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async gitRemoteOriginUrl() {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const { exec } = require("child_process");
|
|
110
|
+
exec("git remote get-url origin", (error, stdout) => {
|
|
111
|
+
if (error) {
|
|
112
|
+
resolve("unknown");
|
|
113
|
+
} else {
|
|
114
|
+
resolve(stdout.trim());
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
58
119
|
async sendData(data) {
|
|
59
|
-
|
|
120
|
+
if (!this.apiToken) {
|
|
121
|
+
this.log("API token not set. Skipping sending data to Browsermation.");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.log(`Sending data to Browsermation: ${JSON.stringify(data)}`);
|
|
60
125
|
try {
|
|
61
|
-
await fetch(
|
|
126
|
+
const response = await fetch(this.browsermationURL, {
|
|
62
127
|
method: "POST",
|
|
63
128
|
headers: {
|
|
64
129
|
Accept: "application/json",
|
|
65
130
|
"Content-Type": "application/json",
|
|
66
|
-
Authorization: `Bearer ${
|
|
131
|
+
Authorization: `Bearer ${this.apiToken}`
|
|
67
132
|
},
|
|
68
133
|
body: JSON.stringify(data)
|
|
69
134
|
});
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
this.log(
|
|
137
|
+
`Failed to send data to Browsermation. Status: ${response.status} - ${response.statusText}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
70
140
|
} catch (error) {
|
|
71
141
|
console.error("Error sending data to Browsermation:", error);
|
|
72
142
|
}
|
|
@@ -84,8 +154,15 @@ var BrowsermationReporter = class {
|
|
|
84
154
|
type: "begin",
|
|
85
155
|
timestamp: Date.now(),
|
|
86
156
|
hostname: (0, import_node_os.hostname)(),
|
|
87
|
-
|
|
88
|
-
|
|
157
|
+
git_branch: await this.getCurrentBranch(),
|
|
158
|
+
git_repo: await this.getCurrentRepo(),
|
|
159
|
+
git_commit_id: await this.getLatestCommitId(),
|
|
160
|
+
git_commit_message: await this.getLatestCommitMessage(),
|
|
161
|
+
git_remote_origin_url: await this.gitRemoteOriginUrl(),
|
|
162
|
+
totalTests: suite.allTests().length,
|
|
163
|
+
cpus: (0, import_node_os.cpus)().length,
|
|
164
|
+
playwright_version: _config.version,
|
|
165
|
+
node_version: process.version
|
|
89
166
|
};
|
|
90
167
|
this.log(`${JSON.stringify(data)}
|
|
91
168
|
`);
|
|
@@ -110,7 +187,10 @@ var BrowsermationReporter = class {
|
|
|
110
187
|
type: "test-start",
|
|
111
188
|
title: test.title,
|
|
112
189
|
file: test.location.file,
|
|
113
|
-
timestamp: Date.now()
|
|
190
|
+
timestamp: Date.now(),
|
|
191
|
+
free_memory: (0, import_node_os.freemem)(),
|
|
192
|
+
total_memory: (0, import_node_os.totalmem)(),
|
|
193
|
+
project: test.parent.project.name
|
|
114
194
|
};
|
|
115
195
|
this.log(`${JSON.stringify(data)}
|
|
116
196
|
`);
|
|
@@ -125,7 +205,9 @@ var BrowsermationReporter = class {
|
|
|
125
205
|
status: result.status,
|
|
126
206
|
duration: result.duration,
|
|
127
207
|
errors: stripAnsi(result.error?.message || ""),
|
|
128
|
-
timestamp: Date.now()
|
|
208
|
+
timestamp: Date.now(),
|
|
209
|
+
free_memory: (0, import_node_os.freemem)(),
|
|
210
|
+
total_memory: (0, import_node_os.totalmem)()
|
|
129
211
|
};
|
|
130
212
|
this.log(`${JSON.stringify(data)}
|
|
131
213
|
`);
|