testbeats 2.0.7 → 2.0.8
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/package.json +1 -1
- package/src/beats/beats.js +6 -17
- package/src/extensions/ci-info.extension.js +45 -15
- package/src/index.d.ts +1 -0
- package/src/targets/chat.js +6 -4
- package/src/targets/slack.js +13 -10
- package/src/targets/teams.js +9 -7
package/package.json
CHANGED
package/src/beats/beats.js
CHANGED
|
@@ -20,10 +20,14 @@ class Beats {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async publish() {
|
|
23
|
+
this.#setApiKey();
|
|
24
|
+
if (!this.config.api_key) {
|
|
25
|
+
logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal...');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
23
28
|
this.#setCIInfo();
|
|
24
29
|
this.#setProjectName();
|
|
25
30
|
this.#setRunName();
|
|
26
|
-
this.#setApiKey();
|
|
27
31
|
await this.#publishTestResults();
|
|
28
32
|
await this.#uploadAttachments();
|
|
29
33
|
this.#updateTitleLink();
|
|
@@ -45,13 +49,10 @@ class Beats {
|
|
|
45
49
|
|
|
46
50
|
#setRunName() {
|
|
47
51
|
this.config.run = this.config.run || process.env.TEST_BEATS_RUN || (this.ci && this.ci.build_name) || 'demo-run';
|
|
52
|
+
this.result.name = this.config.run;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
async #publishTestResults() {
|
|
51
|
-
if (!this.config.api_key) {
|
|
52
|
-
logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal...');
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
56
|
logger.info("🚀 Publishing results to TestBeats Portal...");
|
|
56
57
|
try {
|
|
57
58
|
const payload = this.#getPayload();
|
|
@@ -89,18 +90,6 @@ class Beats {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
#getAllFailedTestCases() {
|
|
93
|
-
const test_cases = [];
|
|
94
|
-
for (const suite of this.result.suites) {
|
|
95
|
-
for (const test of suite.cases) {
|
|
96
|
-
if (test.status === 'FAIL') {
|
|
97
|
-
test_cases.push(test);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return test_cases;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
93
|
#updateTitleLink() {
|
|
105
94
|
if (!this.test_run_id) {
|
|
106
95
|
return;
|
|
@@ -3,6 +3,8 @@ const { getCIInformation } = require('../helpers/ci');
|
|
|
3
3
|
const { getMetaDataText } = require("../helpers/metadata.helper");
|
|
4
4
|
const { STATUS, HOOK } = require("../helpers/constants");
|
|
5
5
|
|
|
6
|
+
const COMMON_BRANCH_NAMES = ['main', 'master', 'dev', 'develop', 'qa', 'test'];
|
|
7
|
+
|
|
6
8
|
class CIInfoExtension extends BaseExtension {
|
|
7
9
|
|
|
8
10
|
constructor(target, extension, result, payload, root_payload) {
|
|
@@ -17,23 +19,24 @@ class CIInfoExtension extends BaseExtension {
|
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
#setDefaultOptions() {
|
|
20
|
-
this.default_options.hook = HOOK.AFTER_SUMMARY
|
|
22
|
+
this.default_options.hook = HOOK.AFTER_SUMMARY;
|
|
21
23
|
this.default_options.condition = STATUS.PASS_OR_FAIL;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
#setDefaultInputs() {
|
|
25
27
|
this.default_inputs.title = '';
|
|
26
28
|
this.default_inputs.title_link = '';
|
|
27
|
-
this.default_inputs.
|
|
28
|
-
this.default_inputs.
|
|
29
|
+
this.default_inputs.show_repository_non_common = true;
|
|
30
|
+
this.default_inputs.show_repository = false;
|
|
31
|
+
this.default_inputs.show_repository_branch = false;
|
|
29
32
|
this.default_inputs.show_build = true;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
async run() {
|
|
33
36
|
this.ci = getCIInformation();
|
|
34
37
|
|
|
35
|
-
this
|
|
36
|
-
this
|
|
38
|
+
this.#setRepositoryElements();
|
|
39
|
+
this.#setBuildElements();
|
|
37
40
|
|
|
38
41
|
const repository_text = await getMetaDataText({ elements: this.repository_elements, target: this.target, extension: this.extension, result: this.result, default_condition: this.default_options.condition });
|
|
39
42
|
const build_text = await getMetaDataText({ elements: this.build_elements, target: this.target, extension: this.extension, result: this.result, default_condition: this.default_options.condition });
|
|
@@ -41,28 +44,55 @@ class CIInfoExtension extends BaseExtension {
|
|
|
41
44
|
this.attach();
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
setRepositoryElements() {
|
|
47
|
+
#setRepositoryElements() {
|
|
45
48
|
if (!this.ci) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
51
|
+
if (!this.ci.repository_url || !this.ci.repository_name || !this.ci.repository_ref) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
48
54
|
|
|
49
|
-
if (this.extension.inputs.show_repository
|
|
50
|
-
this
|
|
55
|
+
if (this.extension.inputs.show_repository) {
|
|
56
|
+
this.#setRepositoryElement();
|
|
57
|
+
}
|
|
58
|
+
if (this.extension.inputs.show_repository_branch) {
|
|
59
|
+
if (this.ci.repository_ref.includes('refs/pull')) {
|
|
60
|
+
this.#setPullRequestElement();
|
|
61
|
+
} else {
|
|
62
|
+
this.#setRepositoryBranchElement();
|
|
63
|
+
}
|
|
51
64
|
}
|
|
52
|
-
if (this.extension.inputs.show_repository_branch && this.
|
|
65
|
+
if (!this.extension.inputs.show_repository && !this.extension.inputs.show_repository_branch && this.extension.inputs.show_repository_non_common) {
|
|
53
66
|
if (this.ci.repository_ref.includes('refs/pull')) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.repository_elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
|
|
67
|
+
this.#setRepositoryElement();
|
|
68
|
+
this.#setPullRequestElement();
|
|
57
69
|
} else {
|
|
58
|
-
const branch_url = this.ci.repository_url + this.ci.repository_ref.replace('refs/heads/', '/tree/');
|
|
59
70
|
const branch_name = this.ci.repository_ref.replace('refs/heads/', '');
|
|
60
|
-
|
|
71
|
+
if (!COMMON_BRANCH_NAMES.includes(branch_name.toLowerCase())) {
|
|
72
|
+
this.#setRepositoryElement();
|
|
73
|
+
this.#setRepositoryBranchElement();
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
}
|
|
64
78
|
|
|
65
|
-
|
|
79
|
+
#setRepositoryElement() {
|
|
80
|
+
this.repository_elements.push({ label: 'Repository', key: this.ci.repository_name, value: this.ci.repository_url, type: 'hyperlink' });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#setPullRequestElement() {
|
|
84
|
+
const pr_url = this.ci.repository_url + this.ci.repository_ref.replace('refs/pull/', '/pull/');
|
|
85
|
+
const pr_name = this.ci.repository_ref.replace('refs/pull/', '').replace('/merge', '');
|
|
86
|
+
this.repository_elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#setRepositoryBranchElement() {
|
|
90
|
+
const branch_url = this.ci.repository_url + this.ci.repository_ref.replace('refs/heads/', '/tree/');
|
|
91
|
+
const branch_name = this.ci.repository_ref.replace('refs/heads/', '');
|
|
92
|
+
this.repository_elements.push({ label: 'Branch', key: branch_name, value: branch_url, type: 'hyperlink' });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#setBuildElements() {
|
|
66
96
|
if (!this.ci) {
|
|
67
97
|
return;
|
|
68
98
|
}
|
package/src/index.d.ts
CHANGED
package/src/targets/chat.js
CHANGED
|
@@ -4,6 +4,7 @@ const extension_manager = require('../extensions');
|
|
|
4
4
|
const { HOOK, STATUS } = require('../helpers/constants');
|
|
5
5
|
const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult');
|
|
6
6
|
const { getValidMetrics, getMetricValuesText } = require('../helpers/performance');
|
|
7
|
+
const logger = require('../utils/logger');
|
|
7
8
|
|
|
8
9
|
async function run({ result, target }) {
|
|
9
10
|
setTargetInputs(target);
|
|
@@ -14,6 +15,7 @@ async function run({ result, target }) {
|
|
|
14
15
|
} else {
|
|
15
16
|
await setFunctionalPayload({ result, target, payload, root_payload });
|
|
16
17
|
}
|
|
18
|
+
logger.info(`🔔 Publishing results to Chat...`);
|
|
17
19
|
return request.post({
|
|
18
20
|
url: target.inputs.url,
|
|
19
21
|
body: root_payload
|
|
@@ -144,9 +146,9 @@ async function setPerformancePayload({ result, target, payload, root_payload })
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
/**
|
|
147
|
-
*
|
|
149
|
+
*
|
|
148
150
|
* @param {object} param0
|
|
149
|
-
* @param {PerformanceTestResult} param0.result
|
|
151
|
+
* @param {PerformanceTestResult} param0.result
|
|
150
152
|
*/
|
|
151
153
|
async function setPerformanceMainBlock({ result, target, payload }) {
|
|
152
154
|
const title_text_with_emoji = getTitleTextWithEmoji({ result, target });
|
|
@@ -169,9 +171,9 @@ async function setPerformanceMainBlock({ result, target, payload }) {
|
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
/**
|
|
172
|
-
*
|
|
174
|
+
*
|
|
173
175
|
* @param {object} param0
|
|
174
|
-
* @param {PerformanceTestResult} param0.result
|
|
176
|
+
* @param {PerformanceTestResult} param0.result
|
|
175
177
|
*/
|
|
176
178
|
async function setTransactionBlock({ result, target, payload }) {
|
|
177
179
|
if (target.inputs.include_suites) {
|
package/src/targets/slack.js
CHANGED
|
@@ -2,12 +2,14 @@ const request = require('phin-retry');
|
|
|
2
2
|
const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helper');
|
|
3
3
|
const extension_manager = require('../extensions');
|
|
4
4
|
const { HOOK, STATUS } = require('../helpers/constants');
|
|
5
|
+
const logger = require('../utils/logger');
|
|
5
6
|
|
|
6
7
|
const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult');
|
|
7
8
|
const { getValidMetrics, getMetricValuesText } = require('../helpers/performance');
|
|
8
9
|
const TestResult = require('test-results-parser/src/models/TestResult');
|
|
9
10
|
|
|
10
11
|
|
|
12
|
+
|
|
11
13
|
const COLORS = {
|
|
12
14
|
GOOD: '#36A64F',
|
|
13
15
|
WARNING: '#ECB22E',
|
|
@@ -23,6 +25,7 @@ async function run({ result, target }) {
|
|
|
23
25
|
await setFunctionalPayload({ result, target, payload });
|
|
24
26
|
}
|
|
25
27
|
const message = getRootPayload({ result, target, payload });
|
|
28
|
+
logger.info(`🔔 Publishing results to Slack...`);
|
|
26
29
|
return request.post({
|
|
27
30
|
url: target.inputs.url,
|
|
28
31
|
body: message
|
|
@@ -142,10 +145,10 @@ function getFailureDetails(suite) {
|
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param {object} param0
|
|
147
|
-
* @param {PerformanceTestResult | TestResult} param0.result
|
|
148
|
-
* @returns
|
|
148
|
+
*
|
|
149
|
+
* @param {object} param0
|
|
150
|
+
* @param {PerformanceTestResult | TestResult} param0.result
|
|
151
|
+
* @returns
|
|
149
152
|
*/
|
|
150
153
|
function getRootPayload({ result, target, payload }) {
|
|
151
154
|
let color = COLORS.GOOD;
|
|
@@ -182,9 +185,9 @@ async function setPerformancePayload({ result, target, payload }) {
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
/**
|
|
185
|
-
*
|
|
186
|
-
* @param {object} param0
|
|
187
|
-
* @param {PerformanceTestResult} param0.result
|
|
188
|
+
*
|
|
189
|
+
* @param {object} param0
|
|
190
|
+
* @param {PerformanceTestResult} param0.result
|
|
188
191
|
*/
|
|
189
192
|
async function setPerformanceMainBlock({ result, target, payload }) {
|
|
190
193
|
let text = `*${getTitleText(result, target)}*\n`;
|
|
@@ -206,9 +209,9 @@ async function setPerformanceMainBlock({ result, target, payload }) {
|
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
/**
|
|
209
|
-
*
|
|
210
|
-
* @param {object} param0
|
|
211
|
-
* @param {PerformanceTestResult} param0.result
|
|
212
|
+
*
|
|
213
|
+
* @param {object} param0
|
|
214
|
+
* @param {PerformanceTestResult} param0.result
|
|
212
215
|
*/
|
|
213
216
|
async function setTransactionBlock({ result, target, payload }) {
|
|
214
217
|
if (target.inputs.include_suites) {
|
package/src/targets/teams.js
CHANGED
|
@@ -3,14 +3,15 @@ const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helpe
|
|
|
3
3
|
const { getValidMetrics, getMetricValuesText } = require('../helpers/performance');
|
|
4
4
|
const extension_manager = require('../extensions');
|
|
5
5
|
const { HOOK, STATUS } = require('../helpers/constants');
|
|
6
|
+
const logger = require('../utils/logger');
|
|
6
7
|
|
|
7
8
|
const TestResult = require('test-results-parser/src/models/TestResult');
|
|
8
9
|
const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* @param {object} param0
|
|
12
|
-
* @param {PerformanceTestResult | TestResult} param0.result
|
|
13
|
-
* @returns
|
|
12
|
+
* @param {object} param0
|
|
13
|
+
* @param {PerformanceTestResult | TestResult} param0.result
|
|
14
|
+
* @returns
|
|
14
15
|
*/
|
|
15
16
|
async function run({ result, target }) {
|
|
16
17
|
setTargetInputs(target);
|
|
@@ -22,6 +23,7 @@ async function run({ result, target }) {
|
|
|
22
23
|
await setFunctionalPayload({ result, target, payload, root_payload });
|
|
23
24
|
}
|
|
24
25
|
setRootPayload(root_payload, payload);
|
|
26
|
+
logger.info(`🔔 Publishing results to Teams...`);
|
|
25
27
|
return request.post({
|
|
26
28
|
url: target.inputs.url,
|
|
27
29
|
body: root_payload
|
|
@@ -209,8 +211,8 @@ function setRootPayload(root_payload, payload) {
|
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
/**
|
|
212
|
-
* @param {object} param0
|
|
213
|
-
* @param {PerformanceTestResult} param0.result
|
|
214
|
+
* @param {object} param0
|
|
215
|
+
* @param {PerformanceTestResult} param0.result
|
|
214
216
|
*/
|
|
215
217
|
async function setMainBlockForPerformance({ result, target, payload }) {
|
|
216
218
|
const total = result.transactions.length;
|
|
@@ -245,8 +247,8 @@ async function getFactMetrics({ metrics, target, result }) {
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
|
-
* @param {object} param0
|
|
249
|
-
* @param {PerformanceTestResult} param0.result
|
|
250
|
+
* @param {object} param0
|
|
251
|
+
* @param {PerformanceTestResult} param0.result
|
|
250
252
|
*/
|
|
251
253
|
async function setTransactionBlock({ result, target, payload }) {
|
|
252
254
|
if (target.inputs.include_suites) {
|