npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

testcafe-reporter-slack-custom

v1.3.0

Published

slack-custom TestCafe reporter plugin.

Downloads

9,845

Readme

TestCafe Reporter Slack Custom

testcafe-reporter-slack-custom

This is a reporter for TestCafe. It sends the output of the test to Slack.

Purpose

Once configured the reporter sends test results to Slack channel, e.g.

Slack report - success

Slack report - failed

Installation

Install this reporter as your test project dependency:

yarn add testcafe-reporter-slack-custom

Setup instructions

In order to use this TestCafe reporter plugin, it is necessary to add it as your reporter to your TestCafe.

Using .testcaferc.json config file

Add a reporter name (slack-custom) to your reporter object:

{
  "browsers": [ "chrome" ],
  "src": "scenarios",
  "reporter": [
    {
      "name": "slack-custom"
    }
  ]
}

Using TestCafe API

Pass the reporter name (slack-custom) to the reporter() method:

testCafe
    .createRunner()
    .src('path/to/test/file.js')
    .browsers('chrome')
    .reporter('slack-custom') // <-
    .run();

Necessary configuration

After that, you should define .env file with variables in your test project, hence the folder from where your call TestCafe (root directory).

# .env
TESTCAFE_SLACK_WEBHOOK=https://hooks.slack.com/services/*****

This is required minimum to have the reporter working.

Options

Slack Custom reporter has few options which it could be configured from: .scReporterConfig.js, .testcaferc.json, or .env file as global variables. It will first retrieve the values from the .scReporterConfig.js file, followed by the TestCafe config file .testcaferc.json, after that from .env file.

  • :warning: - required

Slack Webhook URL :warning:

This option is required! Your Slack channel webhook URL generated from Slack API to allow reporter post there. It's not recommended to pass your webhookUrl into either config file, in this case, due to sensitive data, it's better to pass it via global variable in .env file.

  • via .scReporterConfig.js
module.exports = {
  webhookUrl: "https://hooks.slack.com/services/*****"
};
  • via .testcaferc.json
{
  "name": "slack-custom",
  "options": {
    "webhookUrl": "https://hooks.slack.com/services/*****"
  }
}
  • via .env file
# .env
TESTCAFE_SLACK_WEBHOOK=https://hooks.slack.com/services/*****

Logging level

Choose your report logging level, if you want to see each test with error stack trace, choose DETAILED (default). The second one is short & condensed which shows the only number of tests which passed, failed, and were skipped - SUMMARY. If you would like a summary view, but to explicity show test errors, choose SUMMARY_WITH_ERRORS.

  • via .scReporterConfig.js
module.exports = {
  loggingLevel: "SUMMARY"
};
  • via .testcaferc.json
{
  "name": "slack-custom",
  "options": {
    "loggingLevel": "SUMMARY"
  }
}
  • via .env file
# .env
TESTCAFE_SLACK_LOGGING_LEVEL=SUMMARY

Quiet mode

Choose if you want to have messages in the terminal about sending specific messages to Slack, it's turned off by default.

  • via .scReporterConfig.js
module.exports = {
  quietMode: true
};
  • via .testcaferc.json
{
  "name": "slack-custom",
  "options": {
    "quietMode": true
  }
}
  • via .env file
# .env
TESTCAFE_SLACK_QUIET_MODE=true

Overriding Reporter Methods

TestCafe Reporters require certain reporting methods. You can read more about those here: TestCafe Reporter Methods. Slack Custom Reporter allows you to customize the output of these functions, to a certain degree. This can only be done via the .scReporterConfig.js file inside a reporterMethods object and must return a specific format in order to work properly.

Your function must return either an object, or an array of objects, with an action key that may only have a value of ADD or SEND and a message key with a String value.

ADD - adds your message to a message list that will be sent to Slack at the end of the test run. SEND - immediately sends the message to Slack.

  • via .scReporterConfig.js
module.exports = {
  reporterMethods: {
    reportTaskStart: function(startTime, userAgents, testCount) {
      return {
        action: 'ADD',
        message: 'The tests started at: ' + startTime
      };
    }
  }
};

Multiple messages can be passed through:

module.exports = {
  reporterMethods: {
    reportTaskStart: function(startTime, userAgents, testCount) {
      return [
        {
          action: 'SEND',
          message: 'Starting Tests!'
        },
        {
          action: 'ADD',
          message: 'Test Count: ' + testCount
        }
      ];
    }
  }
};

Further Documentation :books:

TestCafe Reporter Plugins