ci-slack-reporter 1.0.9-a8 → 1.0.10

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.
Files changed (2) hide show
  1. package/index.js +34 -17
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -23,6 +23,19 @@ const webhook = new IncomingWebhook(process.env.CI_SLACK_REPORTER_WEBHOOK);
23
23
 
24
24
  let out = {};
25
25
 
26
+ const SLACK_BLOCKS_LIMIT = 50;
27
+ function splitIfBlocksLimit(obj) {
28
+ const res = [];
29
+ while (obj.attachments.blocks.length != 0) {
30
+ const deepClone = JSON.parse(JSON.stringify(obj))
31
+ deepClone.attachments.blocks = deepClone.attachments.blocks.slice(0, SLACK_BLOCKS_LIMIT);
32
+ ob.attachments.blocks.splice(0, SLACK_BLOCKS_LIMIT);
33
+ res.push(deepClone);
34
+ }
35
+ return res;
36
+
37
+ }
38
+
26
39
  // this reporter outputs test results, indenting two spaces per suite
27
40
  class MyReporter {
28
41
  constructor(runner) {
@@ -31,9 +44,10 @@ class MyReporter {
31
44
 
32
45
  runner
33
46
  .once(EVENT_RUN_BEGIN, () => {
34
- console.log(`⚡runner ${runner.suite?.file}`);
47
+ const filename = filename;
48
+ console.log(`⚡runner ${filename}`);
35
49
 
36
- out[runner.suite?.file] = {
50
+ out[filename] = {
37
51
  attachments: [
38
52
  {
39
53
  "color": "#ff0000",
@@ -49,18 +63,17 @@ class MyReporter {
49
63
  {
50
64
  "type": "divider"
51
65
  },
52
-
53
66
  ]
54
67
  }
55
68
  ]
56
69
  };
57
70
  if (process.env.CI_SLACK_REPORTER_ICON_URL) {
58
- out[runner.suite?.file].icon_url = process.env.CI_SLACK_REPORTER_ICON_URL;
71
+ out[filename].icon_url = process.env.CI_SLACK_REPORTER_ICON_URL;
59
72
  } else {
60
- out[runner.suite?.file].icon_emoji = ":robot:"
73
+ out[filename].icon_emoji = ":robot:"
61
74
  }
62
75
 
63
- out[runner.suite?.file].username = process.env.CI_SLACK_REPORTER_USERNAME || 'Autotester'
76
+ out[filename].username = process.env.CI_SLACK_REPORTER_USERNAME || 'Autotester'
64
77
 
65
78
  })
66
79
  .on(EVENT_SUITE_BEGIN, () => {
@@ -72,28 +85,28 @@ class MyReporter {
72
85
  .on(EVENT_TEST_PASS, test => {
73
86
  // Test#fullTitle() returns the suite name(s)
74
87
  // prepended to the test title
75
- out[runner.suite?.file].attachments[0].blocks.push({
88
+ out[filename].attachments[0].blocks.push({
76
89
  "type": "section",
77
90
  "text": {
78
91
  "type": "plain_text",
79
- "text": `:white_check_mark: ${test.fullTitle()}`,
92
+ "text": `${out[filename].attachments[0].blocks.length} - :white_check_mark: ${test.fullTitle()}`,
80
93
  "emoji": true
81
94
  }
82
95
  })
83
96
  })
84
97
  .on(EVENT_TEST_FAIL, (test, err) => {
85
- out[runner.suite?.file].attachments[0].blocks.push({
98
+ out[filename].attachments[0].blocks.push({
86
99
  "type": "section",
87
100
  "text": {
88
101
  "type": "plain_text",
89
- "text": `:no_entry: ${test.fullTitle()} - error: \`${err.message}\``,
102
+ "text": `${out[filename].attachments[0].blocks.length} - :no_entry: ${test.fullTitle()} - error: \`${err.message}\``,
90
103
  "emoji": true
91
104
  }
92
105
  })
93
106
  })
94
107
  .once(EVENT_RUN_END, () => {
95
108
  if (process.env.CI_SLACK_REPORTER_VIDEO_URL && stats.failures) {
96
- out[runner.suite?.file].attachments[0].blocks[2].accessory = {
109
+ out[filename].attachments[0].blocks[2].accessory = {
97
110
  "type": "button",
98
111
  "text": {
99
112
  "type": "plain_text",
@@ -106,16 +119,20 @@ class MyReporter {
106
119
  }
107
120
  }
108
121
 
109
- out[runner.suite?.file].attachments[0].blocks[0].text.text = `Tests finished ${stats.passes}/${stats.passes + stats.failures}`;
110
- out[runner.suite?.file].attachments[0].color = stats.failures ? "#a30200" : "#2eb886";
111
- console.log(`⚡ webhook send ${runner.suite?.file} / ${process.env.CI_SLACK_REPORTER_WEBHOOK}`, JSON.stringify(out[runner.suite?.file]));
112
- webhook.send(out[runner.suite?.file]);
122
+ out[filename].attachments[0].blocks[0].text.text = `Tests finished ${stats.passes}/${stats.passes + stats.failures}`;
123
+ out[filename].attachments[0].color = stats.failures ? "#a30200" : "#2eb886";
124
+ splitIfBlocksLimit(out[filename]).forEach((part) => {
125
+ webhook.send(part);
126
+ });
127
+
113
128
 
114
129
  if (stats.failures) {
115
- out[runner.suite?.file].attachments[0].blocks = out[runner.suite?.file].attachments[0].blocks.filter(el => {
130
+ out[filename].attachments[0].blocks = out[filename].attachments[0].blocks.filter(el => {
116
131
  return !el?.text?.text?.startsWith(":white")
117
132
  })
118
- fails_only_webhook?.send(out[runner.suite?.file])
133
+ splitIfBlocksLimit(out[filename]).forEach((part) => {
134
+ fails_only_webhook?.send(part);
135
+ });
119
136
  }
120
137
  });
121
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ci-slack-reporter",
3
- "version": "1.0.9a8",
3
+ "version": "1.0.10",
4
4
  "description": "Mocha/Cypress reporter to post tests results directly to Slack",
5
5
  "main": "index.js",
6
6
  "scripts": {