artillery-plugin-slack 1.19.0-e72f537 → 1.19.0-eb2ea5e

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 +1 -1
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  const debug = require('debug')('plugin:slack');
2
2
  const moment = require('moment');
3
3
 
4
+ const MAX_SLACK_TEST_NAME_LENGTH = 80;
5
+
4
6
  class SlackPlugin {
5
7
  constructor(script, events) {
6
8
  this.script = script;
@@ -25,6 +27,13 @@ class SlackPlugin {
25
27
  this.cloudTestRunUrl = `${baseUrl}/load-tests/${global.artillery.testRunId}`;
26
28
  }
27
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
+
28
37
  if (
29
38
  this.script.config.plugins.ensure &&
30
39
  Object.keys(this.script.config.plugins.ensure).length > 0
@@ -119,10 +128,11 @@ class SlackPlugin {
119
128
  const exitCode =
120
129
  this.exitCode !== undefined && this.exitCode !== null ? this.exitCode : 0;
121
130
 
131
+ const testLabel = this.testName ? ` (${this.testName})` : '';
122
132
  const headerText =
123
133
  exitCode === 0
124
- ? '🟢 Artillery test run finished'
125
- : '🔴 Artillery test run failed';
134
+ ? `🟢 Artillery test run finished${testLabel}`
135
+ : `🔴 Artillery test run failed${testLabel}`;
126
136
 
127
137
  const payloadTemplate = {
128
138
  text: headerText,
@@ -239,12 +249,30 @@ class SlackPlugin {
239
249
  });
240
250
  }
241
251
 
252
+ // TODO: stringify in the caller
242
253
  return JSON.stringify(payloadTemplate);
243
254
  }
244
255
 
245
256
  async sendReport(report, ensureChecks) {
246
- const got = (await import('got')).default;
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.19.0-e72f537",
3
+ "version": "1.19.0-eb2ea5e",
4
4
  "description": "Send Artillery.io test notifications to Slack",
5
5
  "main": "index.js",
6
6
  "publishConfig": {