@testomatio/reporter 1.4.11-beta-bitbucket-pipe → 1.4.12-beta-bitbucket-pipe

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.
@@ -24,7 +24,7 @@ class BitbucketPipe {
24
24
  this.tests = [];
25
25
  // Bitbucket PAT looks like bbpat-*****
26
26
  this.token = params.BITBUCKET_PAT || process.env.BITBUCKET_PAT || this.ENV.BITBUCKET_PAT;
27
- this.hiddenCommentData = `<!--- testomat.io report ${process.env.BITBUCKET_STEP_NAME || ''} -->`;
27
+ this.hiddenCommentData = `Testomat.io report: ${process.env.BITBUCKET_BRANCH || ''}`;
28
28
 
29
29
  debug(
30
30
  chalk.yellow('Bitbucket Pipe:'),
@@ -47,6 +47,11 @@ class BitbucketPipe {
47
47
  debug('Bitbucket Pipe: Enabled');
48
48
  }
49
49
 
50
+ async cleanLog(log) {
51
+ const stripAnsi = (await import('strip-ansi')).default;
52
+ return stripAnsi(log);
53
+ }
54
+
50
55
  // Prepare the run (if needed)
51
56
  async prepareRun() {}
52
57
 
@@ -71,6 +76,12 @@ class BitbucketPipe {
71
76
 
72
77
  if (runParams.tests) runParams.tests.forEach(t => this.addTest(t));
73
78
 
79
+ // Clean up the logs from ANSI codes
80
+ for (let i = 0; i < this.tests.length; i++) {
81
+ this.tests[i].message = await this.cleanLog(this.tests[i].message || '');
82
+ this.tests[i].stack = await this.cleanLog(this.tests[i].stack || '');
83
+ }
84
+
74
85
  // Create a comment on Bitbucket
75
86
  const passedCount = this.tests.filter(t => t.status === 'passed').length;
76
87
  const failedCount = this.tests.filter(t => t.status === 'failed').length;
@@ -79,15 +90,15 @@ class BitbucketPipe {
79
90
  // Constructing the table
80
91
  let summary = `${this.hiddenCommentData}
81
92
 
82
- | [![Testomat.io Report](${testomatLogoURL})](https://testomat.io) | ${statusEmoji(
93
+ | ![Testomat.io Report](${testomatLogoURL}) | ${statusEmoji(
83
94
  runParams.status,
84
95
  )} ${runParams.status.toUpperCase()} ${statusEmoji(runParams.status)} |
85
96
  | --- | --- |
86
- | Tests | ✔️ **${this.tests.length}** tests run |
87
- | Summary | ${statusEmoji('failed')} **${failedCount}** failed; ${statusEmoji(
97
+ | **Tests** | ✔️ **${this.tests.length}** tests run |
98
+ | **Summary** | ${statusEmoji('failed')} **${failedCount}** failed; ${statusEmoji(
88
99
  'passed',
89
100
  )} **${passedCount}** passed; **${statusEmoji('skipped')}** ${skippedCount} skipped |
90
- | Duration | 🕐 **${humanizeDuration(
101
+ | **Duration** | 🕐 **${humanizeDuration(
91
102
  parseInt(
92
103
  this.tests.reduce((a, t) => a + (t.run_time || 0), 0),
93
104
  10,
@@ -98,61 +109,62 @@ class BitbucketPipe {
98
109
  )}** |
99
110
  `;
100
111
 
101
- if (this.ENV.BITBUCKET_STEP_NAME && this.ENV.BITBUCKET_STEP_UUID) {
112
+ if (this.ENV.BITBUCKET_BRANCH && this.ENV.BITBUCKET_COMMIT) {
102
113
  // eslint-disable-next-line max-len
103
- summary += `| Job | 👷 [${this.ENV.BITBUCKET_STEP_UUID}](${this.ENV.BITBUCKET_PIPELINE_STEP_URL})<br>Name: **${this.ENV.BITBUCKET_STEP_NAME}** | `;
114
+ summary += `| **Job** | 👷 [Run: ${this.ENV.BITBUCKET_COMMIT}](https://bitbucket.org/${this.ENV.BITBUCKET_REPO_FULL_NAME}/pipelines/results/${this.ENV.BITBUCKET_BUILD_NUMBER}") Branch: **${this.ENV.BITBUCKET_BRANCH}** |`;
104
115
  }
105
116
 
106
117
  const failures = this.tests
107
118
  .filter(t => t.status === 'failed')
108
119
  .slice(0, 20)
109
120
  .map(t => {
110
- let text = `#### ${statusEmoji('failed')} ${fullName(t)} `;
111
- text += '\n\n';
112
- if (t.message)
121
+ let text = `${statusEmoji('failed')} ${fullName(t)}\n`;
122
+ if (t.message) {
113
123
  text += `> ${t.message
114
124
  .replace(/[^\x20-\x7E]/g, '')
115
125
  .replace(ansiRegExp(), '')
116
126
  .trim()}\n`;
117
- if (t.stack) text += `\`\`\`diff\n${t.stack.replace(ansiRegExp(), '').trim()}\n\`\`\`\n`;
118
-
127
+ }
128
+ if (t.stack) {
129
+ text += `\n\`\`\`diff\n${t.stack
130
+ .replace(ansiRegExp(), '')
131
+ .replace(
132
+ /^[\s\S]*################\[ Failure \]################/g,
133
+ '################[ Failure ]################',
134
+ )
135
+ .trim()}\n\`\`\`\n`;
136
+ }
119
137
  if (t.artifacts && t.artifacts.length && !this.ENV.TESTOMATIO_PRIVATE_ARTIFACTS) {
120
138
  t.artifacts
121
139
  .filter(f => !!f)
122
- .filter(f => f.endsWith('.png'))
123
140
  .forEach(f => {
124
141
  if (f.endsWith('.png')) {
125
- text += `![](${f})\n`;
126
- return text;
142
+ text += `![Image](${f})\n`;
143
+ } else {
144
+ text += `[📄 ${path.basename(f)}](${f})\n`;
127
145
  }
128
- text += `[📄 ${path.basename(f)}](${f})\n`;
129
- return text;
130
146
  });
131
147
  }
132
-
133
- text += '\n---\n';
134
-
148
+ text += `\n---\n`;
135
149
  return text;
136
150
  });
137
151
 
138
152
  let body = summary;
139
153
 
140
154
  if (failures.length) {
141
- body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h3></summary>\n\n${failures.join('\n')}\n`;
142
- if (failures.length > 20) {
143
- body += '\n> Notice\n> Only first 20 failures shown*';
155
+ body += `\n🟥 **Failures (${failures.length})**\n\n* ${failures.join('\n* ')}\n`;
156
+ if (failures.length > 10) {
157
+ body += `\n> Notice: Only the first 10 failures are shown.`;
144
158
  }
145
- body += '\n\n</details>';
146
159
  }
147
160
 
148
161
  if (this.tests.length > 0) {
149
- body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
162
+ body += `\n\n**🐢 Slowest Tests**\n\n`;
150
163
  body += this.tests
151
164
  .sort((a, b) => b.run_time - a.run_time)
152
165
  .slice(0, 5)
153
- .map(t => `* ${fullName(t)} (${humanizeDuration(parseFloat(t.run_time))})`)
166
+ .map(t => `* **${fullName(t)}** (${humanizeDuration(parseFloat(t.run_time))})`)
154
167
  .join('\n');
155
- body += '\n</details>';
156
168
  }
157
169
 
158
170
  // Construct Bitbucket API URL for comments
@@ -164,6 +176,7 @@ class BitbucketPipe {
164
176
 
165
177
  // Add current report
166
178
  debug(`Adding comment via URL: ${commentsRequestURL}`);
179
+ debug(`Final Bitbucket API call body: ${body}`);
167
180
 
168
181
  try {
169
182
  const addCommentResponse = await axios.post(
@@ -179,7 +192,7 @@ class BitbucketPipe {
179
192
 
180
193
  const commentID = addCommentResponse.data.id;
181
194
  // eslint-disable-next-line max-len
182
- const commentURL = `${this.ENV.BITBUCKET_REPO_URL}/pull-requests/${this.ENV.BITBUCKET_PR_ID}#comment-${commentID}`;
195
+ const commentURL = `https://bitbucket.org/${this.ENV.BITBUCKET_WORKSPACE}/${this.ENV.BITBUCKET_REPO_SLUG}/pull-requests/${this.ENV.BITBUCKET_PR_ID}#comment-${commentID}`;
183
196
 
184
197
  console.log(APP_PREFIX, chalk.yellow('Bitbucket'), `Report created: ${chalk.magenta(commentURL)}`);
185
198
  } catch (err) {
@@ -235,7 +248,6 @@ async function deletePreviousReport(axiosInstance, commentsRequestURL, hiddenCom
235
248
  } catch (e) {
236
249
  console.warn(`Can't delete previously added comment with testomat.io report. Ignored.`);
237
250
  }
238
-
239
251
  // Pass next env var if need to clear all previous reports;
240
252
  // only the last one is removed by default
241
253
  if (!process.env.BITBUCKET_REMOVE_ALL_OUTDATED_REPORTS) break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.4.11-beta-bitbucket-pipe",
3
+ "version": "1.4.12-beta-bitbucket-pipe",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",
@@ -33,6 +33,7 @@
33
33
  "lodash.merge": "^4.6.2",
34
34
  "minimatch": "^9.0.3",
35
35
  "promise-retry": "^2.0.1",
36
+ "strip-ansi": "^7.1.0",
36
37
  "uuid": "^9.0.0"
37
38
  },
38
39
  "files": [