jest-slack-reporter-v2
v1.0.3
Published
Jest reporter that sends test run start and completion to Slack via webhook
Maintainers
Readme
jest-slack-reporter-v2
A Jest reporter that sends test run start and completion notifications to Slack via an incoming webhook.
Example
Reports in Slack look like this:
You get a message when the run starts (with 🚀), and when it finishes with status (Success/Failure/Unstable), passed/failed/skipped counts, and failing test names.
Install
npm install jest-slack-reporter-v2
# or
yarn add jest-slack-reporter-v2Peer dependency: axios. If your project doesn't have it:
npm install axiosUsage in Jest
In jest.config.js:
module.exports = {
reporters: [
[
'jest-slack-reporter-v2',
{
slackWebhookEnvName: 'SLACK_WEBHOOK_URL',
statuses: { passed: '✅', failed: '🚨', skipped: ':large_yellow_circle:' },
includeFilePath: false,
hidePassed: true,
hideSkipped: true,
jobName: process.env.JOB_NAME,
jobUrl: process.env.JOB_URL,
},
],
],
};Or use default options (reads from env: SLACK_WEBHOOK_URL, JOB_NAME, JOB_URL, FILE_NAME, GITHUB_JOB):
const { getDefaultOptions } = require('jest-slack-reporter-v2');
module.exports = {
reporters: [['jest-slack-reporter-v2', getDefaultOptions()]],
};Set the SLACK_WEBHOOK_URL environment variable to your Slack Incoming Webhook URL.
Options
| Option | Default | Description |
|--------|---------|-------------|
| slackWebhookUrl | — | Webhook URL directly (if not set, taken from env via slackWebhookEnvName) |
| slackWebhookEnvName | 'SLACK_WEBHOOK_URL' | Environment variable name for the webhook URL |
| jobName | process.env.JOB_NAME | Job name for display |
| jobUrl | process.env.JOB_URL | Job URL (clickable in Slack) |
| fileName | process.env.FILE_NAME or 'Default' | File/suite label |
| githubJob | process.env.GITHUB_JOB or 'Tests' | Job name in message title |
| statuses | { passed: '✅', failed: '🚨', skipped: '...' } | Status icons |
| colors | { success: '#00FF00', failure: '#FF0000', unstable: '#FFEA00' } | Slack attachment colors |
| includeFilePath | false | Include test file path in the message body |
| hidePassed | true | Do not list passed tests in the message body |
| hideSkipped | true | Do not list skipped tests |
To use different environment variable names:
const { getDefaultOptions } = require('jest-slack-reporter-v2');
const options = getDefaultOptions(
{ slackWebhook: 'MY_SLACK_WEBHOOK', jobUrl: 'CI_JOB_URL', githubJob: 'CI_JOB_NAME' },
{ hidePassed: false }
);
// Pass options as the second element of the reporter arrayUse as a library (format + send only)
Use formatting and sending without the full reporter:
const { formatReport, sendReport, getDefaultOptions } = require('jest-slack-reporter-v2');
const report = formatReport(jestAggregatedResult, getDefaultOptions());
await sendReport(process.env.SLACK_WEBHOOK_URL, report);sendReport(url, report, axiosOptions?, logger?) — optional third argument for axios options, fourth for a custom logger ({ log, error }).
License
MIT

