ci-slack-reporter 1.0.7 → 1.0.8

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/README.md ADDED
@@ -0,0 +1,28 @@
1
+
2
+ Mocha/Cypress reporter to post tests results directly to Slack
3
+
4
+ Usable for CI services like [Woodpecker](https://devforth.io/blog/step-by-step-guide-to-modern-secure-ci-setup/)
5
+
6
+ Read [Guide how to Setup with Woodpecker](https://devforth.io/blog/run-cypress-auto-tests-in-woodpecker-ci/)
7
+
8
+
9
+
10
+ # Example
11
+ ```
12
+ pipeline:
13
+ websitesTest:
14
+ image: cypress/included:10.2.0
15
+ commands:
16
+ - npm install
17
+ - npm install ci-slack-reporter
18
+ - export CI_SLACK_REPORTER_ICON_URL=https://raw.githubusercontent.com/devforth/ci-slack-reporter/master/assets/patron_autotester.png
19
+ - export CI_SLACK_REPORTER_USERNAME="Patron Autotester"
20
+ - export CI_SLACK_REPORTER_VIDEO_URL=https://<bucket name>.s3.eu-central-1.amazonaws.com/output${CI_BUILD_NUMBER}.mp4
21
+ - export CI_SLACK_REPORTER_WEBHOOK=https://hooks.slack.com/services<your slack webhook>
22
+ - cypress run --reporter ci-slack-reporter --spec "cypress/e2e/$${TEST_NAME}.cy.js"
23
+
24
+ ```
25
+
26
+ Result:
27
+
28
+ ![](./assets/demo.png)
Binary file
Binary file
package/index.js CHANGED
@@ -17,6 +17,7 @@ const {
17
17
  if (!process.env.CI_SLACK_REPORTER_WEBHOOK) {
18
18
  console.error('CI_SLACK_REPORTER_WEBHOOK env variable is not set, reported will not work, please do export CI_SLACK_REPORTER_WEBHOOK=...')
19
19
  }
20
+ const fails_only_webhook = process.env.CI_SLACK_REPORTER_FAILS_ONLY_WEBHOOK && new IncomingWebhook(process.env.CI_SLACK_REPORTER_FAILS_ONLY_WEBHOOK);
20
21
 
21
22
  const webhook = new IncomingWebhook(process.env.CI_SLACK_REPORTER_WEBHOOK);
22
23
 
@@ -31,7 +32,6 @@ class MyReporter {
31
32
  runner
32
33
  .once(EVENT_RUN_BEGIN, () => {
33
34
  out = {
34
- // icon_emoji: ":robot_face:",
35
35
  attachments: [
36
36
  {
37
37
  "color": "#ff0000",
@@ -52,6 +52,14 @@ class MyReporter {
52
52
  }
53
53
  ]
54
54
  };
55
+ if (process.env.CI_SLACK_REPORTER_ICON_URL) {
56
+ out.icon_url = process.env.CI_SLACK_REPORTER_ICON_URL;
57
+ } else {
58
+ out.icon_emoji = ":robot:"
59
+ }
60
+
61
+ out.username = process.env.CI_SLACK_REPORTER_USERNAME || 'Autotester'
62
+
55
63
  })
56
64
  .on(EVENT_SUITE_BEGIN, () => {
57
65
  this.increaseIndent();
@@ -87,7 +95,7 @@ class MyReporter {
87
95
  "type": "button",
88
96
  "text": {
89
97
  "type": "plain_text",
90
- "text": "Video recording",
98
+ "text": "Watch video",
91
99
  "emoji": true
92
100
  },
93
101
  "value": "click_me_123",
@@ -99,6 +107,12 @@ class MyReporter {
99
107
  out.attachments[0].blocks[0].text.text = `Tests finished ${stats.passes}/${stats.passes + stats.failures}`;
100
108
  out.attachments[0].color = stats.failures ? "#a30200" : "#2eb886";
101
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
+ fails_only_webhook?.send(out)
115
+ }
102
116
  });
103
117
  }
104
118
 
@@ -115,4 +129,4 @@ class MyReporter {
115
129
  }
116
130
  }
117
131
 
118
- module.exports = MyReporter;
132
+ module.exports = MyReporter;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ci-slack-reporter",
3
- "version": "1.0.7",
4
- "description": "",
3
+ "version": "1.0.8",
4
+ "description": "Mocha/Cypress reporter to post tests results directly to Slack",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -18,5 +18,6 @@
18
18
  "homepage": "https://github.com/devforth/ci-slack-reporter#readme",
19
19
  "dependencies": {
20
20
  "@slack/webhook": "^6.1.0"
21
- }
21
+ },
22
+ "keywords": ["slack", "mocha reporter", "mocha", "cypress", "", "ci", "woodpeckerci", "docker"]
22
23
  }