artillery-plugin-slack 1.18.0-e22ca80 → 1.19.0-3838eee

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 +48 -3
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const debug = require('debug')('plugin:slack');
2
- const got = require('got');
3
2
  const moment = require('moment');
4
3
 
4
+ const MAX_SLACK_TEST_NAME_LENGTH = 80;
5
+
5
6
  class SlackPlugin {
6
7
  constructor(script, events) {
7
8
  this.script = script;
@@ -26,6 +27,13 @@ class SlackPlugin {
26
27
  this.cloudTestRunUrl = `${baseUrl}/load-tests/${global.artillery.testRunId}`;
27
28
  }
28
29
 
30
+ const nameTag = (global.artillery.testInfo?.tags || []).find(
31
+ (t) => t.name === 'name'
32
+ );
33
+ if (nameTag) {
34
+ this.testName = truncateForSlackHeader(nameTag.value);
35
+ }
36
+
29
37
  if (
30
38
  this.script.config.plugins.ensure &&
31
39
  Object.keys(this.script.config.plugins.ensure).length > 0
@@ -120,10 +128,11 @@ class SlackPlugin {
120
128
  const exitCode =
121
129
  this.exitCode !== undefined && this.exitCode !== null ? this.exitCode : 0;
122
130
 
131
+ const testLabel = this.testName ? ` (${this.testName})` : '';
123
132
  const headerText =
124
133
  exitCode === 0
125
- ? '🟢 Artillery test run finished'
126
- : '🔴 Artillery test run failed';
134
+ ? `🟢 Artillery test run finished${testLabel}`
135
+ : `🔴 Artillery test run failed${testLabel}`;
127
136
 
128
137
  const payloadTemplate = {
129
138
  text: headerText,
@@ -240,11 +249,30 @@ class SlackPlugin {
240
249
  });
241
250
  }
242
251
 
252
+ // TODO: stringify in the caller
243
253
  return JSON.stringify(payloadTemplate);
244
254
  }
245
255
 
246
256
  async sendReport(report, ensureChecks) {
257
+ if (this.config.notifyOnFailureOnly) {
258
+ const hasFailed = this.exitCode !== 0;
259
+ if (!hasFailed) {
260
+ debug('Test passed, notifyOnFailureOnly is set, skipping notification');
261
+ this.finished = true;
262
+ return;
263
+ }
264
+ }
265
+
247
266
  const payload = this.assembleSlackPayload(report, ensureChecks);
267
+
268
+ if (process.env.ARTILLERY_SLACK_PLUGIN_DEBUG) {
269
+ console.log('Slack plugin payload:');
270
+ console.log(payload);
271
+ this.finished = true;
272
+ return;
273
+ }
274
+
275
+ const got = (await import('got')).default;
248
276
  try {
249
277
  const res = await got.post(this.config.webhookUrl, {
250
278
  headers: {
@@ -305,6 +333,23 @@ function maybePluralize(amount, singular, plural = `${singular}s`) {
305
333
  return amount === 1 ? singular : plural;
306
334
  }
307
335
 
336
+ function truncateForSlackHeader(value) {
337
+ if (value === undefined || value === null) {
338
+ return undefined;
339
+ }
340
+
341
+ const normalized = String(value).trim();
342
+ if (!normalized) {
343
+ return undefined;
344
+ }
345
+
346
+ if (normalized.length <= MAX_SLACK_TEST_NAME_LENGTH) {
347
+ return normalized;
348
+ }
349
+
350
+ return `${normalized.slice(0, MAX_SLACK_TEST_NAME_LENGTH - 1)}…`;
351
+ }
352
+
308
353
  module.exports = {
309
354
  Plugin: SlackPlugin,
310
355
  LEGACY_METRICS_FORMAT: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artillery-plugin-slack",
3
- "version": "1.18.0-e22ca80",
3
+ "version": "1.19.0-3838eee",
4
4
  "description": "Send Artillery.io test notifications to Slack",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -13,6 +13,6 @@
13
13
  "license": "MPL-2.0",
14
14
  "dependencies": {
15
15
  "debug": "^4.4.3",
16
- "got": "^11.8.5"
16
+ "got": "^14.6.6"
17
17
  }
18
18
  }