playwright-slack-report-burak 1.3.7 β†’ 1.5.0

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.
@@ -1,119 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFailures =
3
+ //exports.generateBlocks =
4
+ //exports.generateFailures =
4
5
  exports.generateFailuresReasons =
5
6
  exports.generateProblemSuiteList =
6
7
  exports.generateProblemCaseList =
7
- exports.generateBlocks =
8
8
  exports.generateAllRunSuites =
9
9
  void 0;
10
10
 
11
- const generateBlocks = async (summaryResults, maxNumberOfFailures) => {
12
- const meta = [];
13
- const header = {
14
- type: 'section',
15
- text: {
16
- type: 'mrkdwn',
17
- text: '🎭 *Playwright Results*',
18
- },
19
- };
20
- const summary = {
21
- type: 'section',
22
- text: {
23
- type: 'mrkdwn',
24
- text: `βœ… *${summaryResults.passed}* | ❌ *${summaryResults.failed}* |${summaryResults.flaky !== undefined
25
- ? ` 🟑 *${summaryResults.flaky}* | `
26
- : ' '}⏩ *${summaryResults.skipped}*`,
27
- },
28
- };
29
- const fails = await generateFailures(summaryResults, maxNumberOfFailures);
30
- if (summaryResults.meta) {
31
- for (let i = 0; i < summaryResults.meta.length; i += 1) {
32
- const { key, value } = summaryResults.meta[i];
33
- meta.push({
34
- type: 'section',
35
- text: {
36
- type: 'mrkdwn',
37
- text: `\n*${key}* :\t${value}`,
38
- },
39
- });
40
- }
41
- }
42
- return [header, summary, ...meta, ...fails];
43
- };
44
- exports.generateBlocks = generateBlocks;
45
-
46
- // Became obsolete with the introdΔ±ction of generateProblemCaseList()
47
- const generateFailures = async (summaryResults) => {
48
- const thread = [];
49
- const failedNamesTitle = [];
50
- const skippedNamesTitle = [];
51
- const failsList = [];
52
- const skipsList = [];
53
- let previousTestName = undefined;
54
- let previousSuiteName = undefined;
55
-
56
- // Create a list for names of failed test cases
57
- for (const result of summaryResults.tests) {
58
- if (result.status === 'failed' || result.status === 'timedOut') {
59
- const testName = result.name;
60
- const suiteName = result.suiteName;
61
- const parts = result.suiteName.split('/')[result.suiteName.split('/').length-1].replace('.spec.ts', '');
62
- const backSlashedParts = parts.split('\\')[parts.split('\\').length-1];
63
- if (testName !== previousTestName || (testName === previousSuiteName && suiteName !== previousSuiteName) ) {
64
- failsList.push(testName + ' (' + backSlashedParts + ')');
65
- previousTestName = testName;
66
- previousSuiteName = suiteName;
67
- }
68
- }
69
- }
70
- previousTestName = undefined;
71
- previousSuiteName = undefined;
72
-
73
- // Create a list for names of skipped test cases
74
- for (const result of summaryResults.tests) {
75
- if (result.status === 'skipped') {
76
- const testName = result.name;
77
- const suiteName = result.suiteName;
78
- const parts = result.suiteName.split('/')[result.suiteName.split('/').length-1].replace('.spec.ts', '');
79
- const backSlashedParts = parts.split('\\')[parts.split('\\').length-1];
80
- if (testName !== previousTestName || (testName === previousSuiteName && suiteName !== previousSuiteName) ) {
81
- skipsList.push(testName + ' (' + backSlashedParts + ')');
82
- previousTestName = testName;
83
- previousSuiteName = suiteName;
84
- }
85
- }
86
- }
87
- previousTestName = undefined;
88
- previousSuiteName = undefined;
89
-
90
- // Decide on Titles For Listing Failures & Skips
91
- if (summaryResults.failed === 1) {
92
- failedNamesTitle[0] = '\n*Failed Test Case:*\n';
93
- }
94
- if (summaryResults.failed > 1) {
95
- failedNamesTitle[0] = '\n*Failed Test Cases:*\n';
96
- }
97
- if (summaryResults.skipped === 1) {
98
- skippedNamesTitle[0] = '\n*Skipped Test Case:*\n';
99
- }
100
- if (summaryResults.skipped > 1) {
101
- skippedNamesTitle[0] = '\n*Skipped Test Cases:*\n';
102
- }
103
-
104
- thread.push({
105
- type: 'section',
106
- text: {
107
- type: 'mrkdwn',
108
- text: `${failedNamesTitle}${failsList.map((value, index) => `*${index + 1}.* ${value}`).join('\n')}` + // List of Failed Test Cases
109
- `\n${skippedNamesTitle}${skipsList.map((value, index) => `*${index + 1}.* ${value}`).join('\n')} `, // List of Skipped Test Cases
110
- },
111
- })
112
- return [
113
- ...thread,
114
- ];
115
- };
116
-
117
11
  const generateAllRunSuites = async (summaryResults) => {
118
12
  const suitesResults = [];
119
13
  const allSuites = [];
@@ -338,48 +232,80 @@ const generateProblemCaseList = async (summaryResults) => {
338
232
 
339
233
  // Decide on Titles For Listing Failures, Skips & Flakies
340
234
  if (summaryResults.failed === 1) {
341
- failedNamesTitle[0] = '\n*Failed Test Case:*\n';
235
+ failedNamesTitle[0] = '*Failed Test Case:*\n';
342
236
  }
343
237
  if (summaryResults.failed > 1) {
344
- failedNamesTitle[0] = '\n*Failed Test Cases:*\n';
238
+ failedNamesTitle[0] = '*Failed Test Cases:*\n';
345
239
  }
346
240
  if (summaryResults.flaky === 1) {
347
- flakyNamesTitle[0] = '\n*Flaky Test Case:*\n';
241
+ flakyNamesTitle[0] = '*Flaky Test Case:*\n';
348
242
  }
349
243
  if (summaryResults.flaky > 1) {
350
- flakyNamesTitle[0] = '\n*Flaky Test Cases:*\n';
244
+ flakyNamesTitle[0] = '*Flaky Test Cases:*\n';
351
245
  }
352
246
  if (summaryResults.skipped === 1) {
353
- skippedNamesTitle[0] = '\n*Skipped Test Case:*\n';
247
+ skippedNamesTitle[0] = '*Skipped Test Case:*\n';
354
248
  }
355
249
  if (summaryResults.skipped > 1) {
356
- skippedNamesTitle[0] = '\n*Skipped Test Cases:*\n';
250
+ skippedNamesTitle[0] = '*Skipped Test Cases:*\n';
357
251
  }
358
252
 
359
- // Push data into array to create the "List of Problematic Test Suites"
360
- if (summaryResults.tests.length !== summaryResults.passed){
361
- casesResults.push(
362
- {
363
- type: 'section',
364
- text: {
365
- type: 'mrkdwn',
366
- text:
367
- `\n${failedNamesTitle}${failsList.map((value, index) => `*${index + 1}.* ${value}`).join('\n')}` + // List of Failed Test Cases
368
- `\n${flakyNamesTitle}${flakyList.map((value, index) => `*${index + 1}.* ${value}`).join('\n')}` + // List of Flaky Test Cases
369
- `\n${skippedNamesTitle}${skipsList.map((value, index) => `*${index + 1}.* ${value}`).join('\n')} `, // List of Skipped Test Cases
370
- },
371
- },
372
- {
373
- type: 'section',
374
- text: {
375
- type: 'mrkdwn',
376
- text: ` `,
253
+ // Function to safely push text to casesResults
254
+ const safePush = (title, list, array) => {
255
+ let text = `${title}${list.map((value, index) => `*${index + 1}.* ${value}`).join('\n')}\n`;
256
+ if (text.length > 2700) {
257
+ text = text.substring(0, 2700) + '...';
258
+ array.push({
259
+ type: 'section',
260
+ text: {
261
+ type: 'mrkdwn',
262
+ text: text + '\n\n\n' + '⚠️ *There are too many items to display here. ' +
263
+ 'You can view more on CircleCI* ⚠️',
264
+ },
265
+ },
266
+ {
267
+ type: 'actions',
268
+ elements: [{
269
+ type: 'button',
270
+ text: {
271
+ type: 'plain_text',
272
+ text: 'Go to Build Details'
273
+ },
274
+ url: process.env.CIRCLE_BUILD_URL
275
+ }]
276
+ });
277
+ } else {
278
+ casesResults.push({
279
+ type: 'section',
280
+ text: {
281
+ type: 'mrkdwn',
282
+ text: text,
283
+ },
284
+ });
285
+ }
286
+ };
287
+
288
+ // Push each section with character limit check
289
+ if (summaryResults.tests.length !== summaryResults.passed) {
290
+ safePush(failedNamesTitle, failsList, casesResults);
291
+ safePush(flakyNamesTitle, flakyList, casesResults);
292
+ safePush(skippedNamesTitle, skipsList, casesResults);
293
+ }
294
+
295
+ // Add additional sections if needed
296
+ casesResults.push(
297
+ {
298
+ type: 'section',
299
+ text: {
300
+ type: 'mrkdwn',
301
+ text: ` `,
302
+ },
377
303
  },
378
- },
379
- {
380
- type: 'divider',
381
- },
382
- )}
304
+ {
305
+ type: 'divider',
306
+ },
307
+ );
308
+
383
309
  return [
384
310
  ...casesResults,
385
311
  ];
@@ -504,7 +430,7 @@ const generateFailuresReasons = async (summaryResults) => {
504
430
  ...failsList,
505
431
  ];
506
432
  };
507
- exports.generateFailures = generateFailures;
433
+ //exports.generateFailures = generateFailures;
508
434
  exports.generateFailuresReasons = generateFailuresReasons;
509
435
  exports.generateProblemSuiteList = generateProblemSuiteList;
510
436
  exports.generateProblemCaseList = generateProblemCaseList;
@@ -25,15 +25,7 @@ export default class SlackClient {
25
25
  outcome: string;
26
26
  ts: string;
27
27
  }>>;
28
- attachDetailsToThread({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }: {
29
- channelIds: Array<string>;
30
- ts: string;
31
- summaryResults: SummaryResults;
32
- maxNumberOfFailures: number;
33
- disableUnfurl?: boolean;
34
- fakeRequest?: Function;
35
- }): Promise<any[]>;
36
- attachDetailsToThreadReasons({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }: {
28
+ attachDetailsToThreadReasons({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }: {
37
29
  channelIds: Array<string>;
38
30
  ts: string;
39
31
  summaryResults: SummaryResults;
@@ -45,7 +45,7 @@ class SlackClient {
45
45
  ts: chatResponse.ts,
46
46
  });
47
47
  // eslint-disable-next-line no-console
48
- console.log(`βœ… Message sent to ${channel}`);
48
+ console.log(`βœ… Test results posted to Slack channel ${channel}`);
49
49
  }
50
50
  else {
51
51
  result.push({
@@ -63,30 +63,6 @@ class SlackClient {
63
63
  }
64
64
  return result;
65
65
  }
66
- async attachDetailsToThread({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }) {
67
- const result = [];
68
- const blocks = await (0, LayoutGenerator_1.generateRuns)(summaryResults, maxNumberOfFailures);
69
- for (const channel of channelIds) {
70
- // under test
71
- let chatResponse;
72
- if (fakeRequest) {
73
- chatResponse = await fakeRequest();
74
- }
75
- else {
76
- chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, blocks, disableUnfurl, ts);
77
- }
78
- if (chatResponse.ok) {
79
- // eslint-disable-next-line no-console
80
- console.log(`βœ… Message sent to ${channel} within thread ${ts}`);
81
- result.push({
82
- channel,
83
- outcome: `βœ… Message sent to ${channel} within thread ${ts}`,
84
- ts: chatResponse.ts,
85
- });
86
- }
87
- }
88
- return result;
89
- }
90
66
  async attachDetailsToThreadRuns({ channelIds, ts, summaryResults, maxNumberOfFailures, disableUnfurl, fakeRequest, }) {
91
67
  const result = [];
92
68
  const blocks = await (0, LayoutGenerator_1.generateAllRunSuites)(summaryResults, maxNumberOfFailures);
@@ -99,6 +75,15 @@ class SlackClient {
99
75
  else {
100
76
  chatResponse = await SlackClient.doPostRequest(this.slackWebClient, channel, blocks, disableUnfurl, ts);
101
77
  }
78
+ if (chatResponse.ok) {
79
+ // eslint-disable-next-line no-console
80
+ console.log(`βœ… List of run suites sent within a thread.`);
81
+ result.push({
82
+ channel,
83
+ outcome: `βœ… Message sent to ${channel} within thread ${ts}`,
84
+ ts: chatResponse.ts,
85
+ });
86
+ }
102
87
  }
103
88
  return result;
104
89
  }
@@ -116,7 +101,7 @@ class SlackClient {
116
101
  }
117
102
  if (chatResponse.ok) {
118
103
  // eslint-disable-next-line no-console
119
- console.log(`βœ… Message sent to ${channel} within thread ${ts}`);
104
+ console.log(`βœ… List of problematical suites sent within a thread.`);
120
105
  result.push({
121
106
  channel,
122
107
  outcome: `βœ… Message sent to ${channel} within thread ${ts}`,
@@ -140,7 +125,7 @@ class SlackClient {
140
125
  }
141
126
  if (chatResponse.ok) {
142
127
  // eslint-disable-next-line no-console
143
- console.log(`βœ… Message sent to ${channel} within thread ${ts}`);
128
+ console.log(`βœ… List of problematical cases sent within a thread.`);
144
129
  result.push({
145
130
  channel,
146
131
  outcome: `βœ… Message sent to ${channel} within thread ${ts}`,
@@ -164,7 +149,7 @@ class SlackClient {
164
149
  }
165
150
  if (chatResponse.ok) {
166
151
  // eslint-disable-next-line no-console
167
- console.log(`βœ… Message sent to ${channel} within thread ${ts}`);
152
+ console.log(`βœ… List of failure reasons sent within a thread.`);
168
153
  result.push({
169
154
  channel,
170
155
  outcome: `βœ… Message sent to ${channel} within thread ${ts}`,
@@ -110,17 +110,8 @@ class SlackReporter {
110
110
  },
111
111
  });
112
112
  // eslint-disable-next-line no-console
113
- console.log(JSON.stringify(result, null, 2));
113
+ //console.log(JSON.stringify(result, null, 2));
114
114
  if (this.showInThread) {
115
- /*for (let i = 0; i < result.length; i += 1) {
116
- // eslint-disable-next-line no-await-in-loop
117
- await slackClient.attachDetailsToThread({
118
- channelIds: [result[i].channel],
119
- ts: result[i].ts,
120
- summaryResults: resultSummary,
121
- maxNumberOfFailures: this.maxNumberOfFailuresToShow,
122
- });
123
- }*/
124
115
  for (let i = 0; i < result.length; i += 1) {
125
116
  // eslint-disable-next-line no-await-in-loop
126
117
  await slackClient.attachDetailsToThreadRuns({
@@ -152,14 +143,16 @@ class SlackReporter {
152
143
  });
153
144
  }
154
145
 
155
- for (let i = 0; i < result.length; i += 1) {
156
- // eslint-disable-next-line no-await-in-loop
157
- await slackClient.attachDetailsToThreadReasons({
158
- channelIds: [result[i].channel],
159
- ts: result[i].ts,
160
- summaryResults: resultSummary,
161
- maxNumberOfFailures: this.maxNumberOfFailuresToShow,
162
- });
146
+ if ((resultSummary.failures.length > 0)) {
147
+ for (let i = 0; i < result.length; i += 1) {
148
+ // eslint-disable-next-line no-await-in-loop
149
+ await slackClient.attachDetailsToThreadReasons({
150
+ channelIds: [result[i].channel],
151
+ ts: result[i].ts,
152
+ summaryResults: resultSummary,
153
+ maxNumberOfFailures: this.maxNumberOfFailuresToShow,
154
+ });
155
+ }
163
156
  }
164
157
  }
165
158
  }
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "lint-fix": "npx eslint . --ext .ts --fix"
31
31
  },
32
32
  "name": "playwright-slack-report-burak",
33
- "version": "1.3.7",
33
+ "version": "1.5.0",
34
34
  "main": "index.js",
35
35
  "types": "dist/index.d.ts",
36
36
  "repository": "git@github.com:ryanrosello-og/playwright-slack-report.git",