ci-slack-reporter 1.0.9 → 1.0.11

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