testbeats 2.0.6 → 2.0.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testbeats",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
5
5
  "main": "src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -0,0 +1,47 @@
1
+ const path = require('path');
2
+ const { BaseExtension } = require("./base.extension");
3
+ const { STATUS, HOOK } = require("../helpers/constants");
4
+
5
+ class CustomExtension extends BaseExtension {
6
+
7
+ /**
8
+ * @param {import('..').CustomExtension} extension
9
+ */
10
+ constructor(target, extension, result, payload, root_payload) {
11
+ super(target, extension, result, payload, root_payload);
12
+ this.extension = extension;
13
+ this.#setDefaultOptions();
14
+ this.updateExtensionInputs();
15
+ }
16
+
17
+ #setDefaultOptions() {
18
+ this.default_options.hook = HOOK.END,
19
+ this.default_options.condition = STATUS.PASS_OR_FAIL;
20
+ }
21
+
22
+ async run() {
23
+ const params = this.#getParams();
24
+ if (typeof this.extension.inputs.load === 'string') {
25
+ const cwd = process.cwd();
26
+ const extension_runner = require(path.join(cwd, this.extension.inputs.load));
27
+ await extension_runner.run(params);
28
+ } else if (typeof this.extension.inputs.load === 'function') {
29
+ await this.extension.inputs.load(params);
30
+ } else {
31
+ throw `Invalid 'load' input in custom extension - ${this.extension.inputs.load}`;
32
+ }
33
+ }
34
+
35
+ #getParams() {
36
+ return {
37
+ target: this.target,
38
+ extension: this.extension,
39
+ payload: this.payload,
40
+ root_payload: this.root_payload,
41
+ result: this.result
42
+ }
43
+ }
44
+
45
+ }
46
+
47
+ module.exports = { CustomExtension }
@@ -4,11 +4,11 @@ const rp_analysis = require('./report-portal-analysis');
4
4
  const rp_history = require('./report-portal-history');
5
5
  const qc_test_summary = require('./quick-chart-test-summary');
6
6
  const percy_analysis = require('./percy-analysis');
7
- const custom = require('./custom');
8
7
  const metadata = require('./metadata');
9
8
  const { AIFailureSummaryExtension } = require('./ai-failure-summary.extension');
10
9
  const { SmartAnalysisExtension } = require('./smart-analysis.extension');
11
10
  const { CIInfoExtension } = require('./ci-info.extension');
11
+ const { CustomExtension } = require('./custom.extension');
12
12
  const { EXTENSION } = require('../helpers/constants');
13
13
  const { checkCondition } = require('../helpers/helper');
14
14
  const logger = require('../utils/logger');
@@ -51,7 +51,7 @@ function getExtensionRunner(extension, options) {
51
51
  case EXTENSION.PERCY_ANALYSIS:
52
52
  return percy_analysis;
53
53
  case EXTENSION.CUSTOM:
54
- return custom;
54
+ return new CustomExtension(options.target, extension, options.result, options.payload, options.root_payload);
55
55
  case EXTENSION.METADATA:
56
56
  return metadata;
57
57
  case EXTENSION.CI_INFO:
@@ -39,19 +39,19 @@ class SmartAnalysisExtension extends BaseExtension {
39
39
 
40
40
  const smart_analysis = [];
41
41
  if (execution_metrics.newly_failed) {
42
- smart_analysis.push(`⭕ NF: ${execution_metrics.newly_failed}`);
42
+ smart_analysis.push(`⭕ Newly Failed: ${execution_metrics.newly_failed}`);
43
43
  }
44
44
  if (execution_metrics.always_failing) {
45
- smart_analysis.push(`🔴 AF: ${execution_metrics.always_failing}`);
45
+ smart_analysis.push(`🔴 Always Failing: ${execution_metrics.always_failing}`);
46
46
  }
47
- if (execution_metrics.recurring_failures) {
48
- smart_analysis.push(`🟠 RF: ${execution_metrics.recurring_failures}`);
47
+ if (execution_metrics.recurring_errors) {
48
+ smart_analysis.push(`🟠 Recurring Errors: ${execution_metrics.recurring_errors}`);
49
49
  }
50
50
  if (execution_metrics.flaky) {
51
- smart_analysis.push(`🟡 FL: ${execution_metrics.flaky}`);
51
+ smart_analysis.push(`🟡 Flaky: ${execution_metrics.flaky}`);
52
52
  }
53
53
  if (execution_metrics.recovered) {
54
- smart_analysis.push(`🟢 RC: ${execution_metrics.recovered}`);
54
+ smart_analysis.push(`🟢 Recovered: ${execution_metrics.recovered}`);
55
55
  }
56
56
 
57
57
  this.text = smart_analysis.join(' | ');
package/src/helpers/ci.js CHANGED
@@ -7,6 +7,9 @@ function getCIInformation() {
7
7
  if (ENV.GITHUB_ACTIONS) {
8
8
  return getGitHubActionsInformation();
9
9
  }
10
+ if (ENV.GITLAB_CI) {
11
+ return getGitLabInformation();
12
+ }
10
13
  if (ENV.JENKINS_URL) {
11
14
  return getJenkinsInformation();
12
15
  }
@@ -26,6 +29,7 @@ function getGitHubActionsInformation() {
26
29
  build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID,
27
30
  build_number: ENV.GITHUB_RUN_NUMBER,
28
31
  build_name: ENV.GITHUB_WORKFLOW,
32
+ build_reason: ENV.GITHUB_EVENT_NAME,
29
33
  user: ENV.GITHUB_ACTOR,
30
34
  }
31
35
  }
@@ -41,6 +45,7 @@ function getAzureDevOpsInformation() {
41
45
  build_url: ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID,
42
46
  build_number: ENV.BUILD_BUILDNUMBER,
43
47
  build_name: ENV.BUILD_DEFINITIONNAME,
48
+ build_reason: ENV.BUILD_REASON,
44
49
  user: ENV.BUILD_REQUESTEDFOR
45
50
  }
46
51
  }
@@ -56,10 +61,27 @@ function getJenkinsInformation() {
56
61
  build_url: ENV.BUILD_URL,
57
62
  build_number: ENV.BUILD_NUMBER,
58
63
  build_name: ENV.JOB_NAME,
64
+ build_reason: ENV.BUILD_CAUSE,
59
65
  user: ENV.USER || ENV.USERNAME
60
66
  }
61
67
  }
62
68
 
69
+ function getGitLabInformation() {
70
+ return {
71
+ ci: 'GITLAB',
72
+ git: 'GITLAB',
73
+ repository_url: ENV.CI_PROJECT_URL,
74
+ repository_name: ENV.CI_PROJECT_NAME,
75
+ repository_ref: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME,
76
+ repository_commit_sha:ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA,
77
+ build_url: ENV.CI_JOB_URL,
78
+ build_number: ENV.CI_JOB_ID,
79
+ build_name: ENV.CI_JOB_NAME,
80
+ build_reason: ENV.CI_PIPELINE_SOURCE,
81
+ user: ENV.GITLAB_USER_LOGIN || ENV.CI_COMMIT_AUTHOR
82
+ }
83
+ }
84
+
63
85
  module.exports = {
64
86
  getCIInformation
65
87
  }
@@ -111,7 +111,7 @@ function getFailureDetails(suite) {
111
111
  for (let i = 0; i < cases.length; i++) {
112
112
  const test_case = cases[i];
113
113
  if (test_case.status === 'FAIL') {
114
- text += `<b>Test</b>: ${test_case.name}<br><b>Error</b>: ${truncate(test_case.failure, 150)}<br><br>`;
114
+ text += `<b>Test</b>: ${test_case.name}<br><b>Error</b>: ${truncate(test_case.failure ?? 'N/A', 150)}<br><br>`;
115
115
  }
116
116
  }
117
117
  return text;
@@ -22,7 +22,7 @@ async function run({ result, target }) {
22
22
  } else {
23
23
  await setFunctionalPayload({ result, target, payload });
24
24
  }
25
- const message = getRootPayload({ result, payload });
25
+ const message = getRootPayload({ result, target, payload });
26
26
  return request.post({
27
27
  url: target.inputs.url,
28
28
  body: message
@@ -66,12 +66,12 @@ function setMainBlock({ result, target, payload }) {
66
66
  });
67
67
  }
68
68
 
69
- function getTitleText(result, target) {
69
+ function getTitleText(result, target, {allowTitleLink = true} = {}) {
70
70
  let text = target.inputs.title ? target.inputs.title : result.name;
71
71
  if (target.inputs.title_suffix) {
72
72
  text = `${text} ${target.inputs.title_suffix}`;
73
73
  }
74
- if (target.inputs.title_link) {
74
+ if (allowTitleLink && target.inputs.title_link) {
75
75
  text = `<${target.inputs.title_link}|${text}>`;
76
76
  }
77
77
  return text;
@@ -129,7 +129,7 @@ function getFailureDetails(suite) {
129
129
  for (let i = 0; i < cases.length; i++) {
130
130
  const test_case = cases[i];
131
131
  if (test_case.status === 'FAIL') {
132
- text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure, 150)}\n\n`;
132
+ text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure ?? 'N/A', 150)}\n\n`;
133
133
  }
134
134
  }
135
135
  return {
@@ -147,7 +147,7 @@ function getFailureDetails(suite) {
147
147
  * @param {PerformanceTestResult | TestResult} param0.result
148
148
  * @returns
149
149
  */
150
- function getRootPayload({ result, payload }) {
150
+ function getRootPayload({ result, target, payload }) {
151
151
  let color = COLORS.GOOD;
152
152
  if (result.status !== 'PASS') {
153
153
  let somePassed = true;
@@ -166,7 +166,8 @@ function getRootPayload({ result, payload }) {
166
166
  "attachments": [
167
167
  {
168
168
  "color": color,
169
- "blocks": payload.blocks
169
+ "blocks": payload.blocks,
170
+ "fallback": `${getTitleText(result, target, {allowTitleLink: false})}\nResults: ${getResultText(result)}`,
170
171
  }
171
172
  ]
172
173
  };
@@ -183,7 +183,7 @@ function getFailureDetailsFactSets(suite) {
183
183
  },
184
184
  {
185
185
  "title": "Error:",
186
- "value": truncate(test_case.failure, 150)
186
+ "value": truncate(test_case.failure ?? 'N/A', 150)
187
187
  }
188
188
  ]
189
189
  });
@@ -1,29 +0,0 @@
1
- const path = require('path');
2
- const { HOOK, STATUS } = require('../helpers/constants');
3
-
4
- /**
5
- *
6
- * @param {object} param0
7
- * @param {import('../index').CustomExtension} param0.extension
8
- */
9
- async function run({ target, extension, payload, root_payload, result }) {
10
- if (typeof extension.inputs.load === 'string') {
11
- const cwd = process.cwd();
12
- const extension_runner = require(path.join(cwd, extension.inputs.load));
13
- await extension_runner.run({ target, extension, payload, root_payload, result });
14
- } else if (typeof extension.inputs.load === 'function') {
15
- await extension.inputs.load({ target, extension, payload, root_payload, result });
16
- } else {
17
- throw `Invalid 'load' input in custom extension - ${extension.inputs.load}`;
18
- }
19
- }
20
-
21
- const default_options = {
22
- hook: HOOK.END,
23
- condition: STATUS.PASS_OR_FAIL
24
- }
25
-
26
- module.exports = {
27
- run,
28
- default_options
29
- }