ci-slack-reporter 1.0.9-a2 → 1.0.9-a4

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 +15 -18
  2. package/package.json +2 -3
package/index.js CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  const Mocha = require('mocha');
6
6
  const { IncomingWebhook } = require('@slack/webhook');
7
- const fetch = require('node-fetch');
8
7
 
9
8
  const {
10
9
  EVENT_RUN_BEGIN,
@@ -22,7 +21,7 @@ const fails_only_webhook = process.env.CI_SLACK_REPORTER_FAILS_ONLY_WEBHOOK && n
22
21
 
23
22
  const webhook = new IncomingWebhook(process.env.CI_SLACK_REPORTER_WEBHOOK);
24
23
 
25
- let out;
24
+ let out = {};
26
25
 
27
26
  // this reporter outputs test results, indenting two spaces per suite
28
27
  class MyReporter {
@@ -32,11 +31,9 @@ class MyReporter {
32
31
 
33
32
  runner
34
33
  .once(EVENT_RUN_BEGIN, () => {
35
- fetch('https://webhook.site/961a40af-8afc-476d-9ed6-d6c757f50acf', {method: 'POST', body: `runner EVENT_RUN_BEGIN ${JSON.stringify(runner)}`});
34
+ console.log('⚡runner, EVENT_RUN_BEGIN', runner);
36
35
 
37
-
38
-
39
- out = {
36
+ out[runner.file] = {
40
37
  attachments: [
41
38
  {
42
39
  "color": "#ff0000",
@@ -58,12 +55,12 @@ class MyReporter {
58
55
  ]
59
56
  };
60
57
  if (process.env.CI_SLACK_REPORTER_ICON_URL) {
61
- out.icon_url = process.env.CI_SLACK_REPORTER_ICON_URL;
58
+ out[runner.file].icon_url = process.env.CI_SLACK_REPORTER_ICON_URL;
62
59
  } else {
63
- out.icon_emoji = ":robot:"
60
+ out[runner.file].icon_emoji = ":robot:"
64
61
  }
65
62
 
66
- out.username = process.env.CI_SLACK_REPORTER_USERNAME || 'Autotester'
63
+ out[runner.file].username = process.env.CI_SLACK_REPORTER_USERNAME || 'Autotester'
67
64
 
68
65
  })
69
66
  .on(EVENT_SUITE_BEGIN, () => {
@@ -75,7 +72,7 @@ class MyReporter {
75
72
  .on(EVENT_TEST_PASS, test => {
76
73
  // Test#fullTitle() returns the suite name(s)
77
74
  // prepended to the test title
78
- out.attachments[0].blocks.push({
75
+ out[runner.file].attachments[0].blocks.push({
79
76
  "type": "section",
80
77
  "text": {
81
78
  "type": "plain_text",
@@ -85,7 +82,7 @@ class MyReporter {
85
82
  })
86
83
  })
87
84
  .on(EVENT_TEST_FAIL, (test, err) => {
88
- out.attachments[0].blocks.push({
85
+ out[runner.file].attachments[0].blocks.push({
89
86
  "type": "section",
90
87
  "text": {
91
88
  "type": "plain_text",
@@ -96,7 +93,7 @@ class MyReporter {
96
93
  })
97
94
  .once(EVENT_RUN_END, () => {
98
95
  if (process.env.CI_SLACK_REPORTER_VIDEO_URL && stats.failures) {
99
- out.attachments[0].blocks[2].accessory = {
96
+ out[runner.file].attachments[0].blocks[2].accessory = {
100
97
  "type": "button",
101
98
  "text": {
102
99
  "type": "plain_text",
@@ -109,16 +106,16 @@ class MyReporter {
109
106
  }
110
107
  }
111
108
 
112
- out.attachments[0].blocks[0].text.text = `Tests finished ${stats.passes}/${stats.passes + stats.failures}`;
113
- out.attachments[0].color = stats.failures ? "#a30200" : "#2eb886";
114
- webhook.send(out);
115
- fetch('https://webhook.site/961a40af-8afc-476d-9ed6-d6c757f50acf', {method: 'POST', body: `webhook send`});
109
+ out[runner.file].attachments[0].blocks[0].text.text = `Tests finished ${stats.passes}/${stats.passes + stats.failures}`;
110
+ out[runner.file].attachments[0].color = stats.failures ? "#a30200" : "#2eb886";
111
+ webhook.send(out[runner.file]);
112
+ console.log(' webhook send');
116
113
 
117
114
  if (stats.failures) {
118
- out.attachments[0].blocks = out.attachments[0].blocks.filter(el => {
115
+ out[runner.file].attachments[0].blocks = out[runner.file].attachments[0].blocks.filter(el => {
119
116
  return !el?.text?.text?.startsWith(":white")
120
117
  })
121
- fails_only_webhook?.send(out)
118
+ fails_only_webhook?.send(out[runner.file])
122
119
  }
123
120
  });
124
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ci-slack-reporter",
3
- "version": "1.0.9a2",
3
+ "version": "1.0.9a4",
4
4
  "description": "Mocha/Cypress reporter to post tests results directly to Slack",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,8 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/devforth/ci-slack-reporter#readme",
19
19
  "dependencies": {
20
- "@slack/webhook": "^6.1.0",
21
- "node-fetch": "^3.2.10"
20
+ "@slack/webhook": "^6.1.0"
22
21
  },
23
22
  "keywords": [
24
23
  "slack",