Skip to content

sSelmann/cypress-discord-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cypress-discord-reporter

Mochawesome Report

This package sends Mochawesome test results to Discord channel via Discord Webhook.

Install

npm install @sselmann/cypress-discord-reporter

Pre-requisite

mochawesome

Create a Discord Webhook and copy Webhook URL

Setup

1- Import reporter to cypress.config.js\config.ts file.

const sendDiscordWebhook = require('@sselmann/cypress-discord-reporter');

or for typescript:

import sendDiscordWebhook from "@sselmann/cypress-discord-reporter";

2- Declare reportDir and reportFileName

const  reportDir  =  'cypress/results/';
const  reportFileName  =  'mochawesome';

3- set reporter and options with use defineConfig

module.exports = defineConfig({
    reporter: 'mochawesome',
    reporterOptions: {
        reportDir: reportDir,
        overwrite: true,
        html: false,
        json: true,
    },
});

4- use after:run in setupNodeEvents and specify the webhook url and title.

setupNodeEvents(on, config) {
    on('after:run', async () => {
        const webhookURL = '<webhookURL>'; // Webhook URL for Discord
        const resultFile = reportDir + reportFileName + '.json';
        const title = 'Example Test Results'; // Title for results
        await sendDiscordWebhook(
            webhookURL,
            resultFile,
            title,
        );
    });
    return config;
},

Here is an example of a config file with all codes to be added:

const {defineConfig} = require('cypress');
const sendDiscordWebhook = require('@sselmann/cypress-discord-reporter');

const reportDir = 'cypress/results/';
const reportFileName = 'mochawesome';

module.exports = defineConfig({
    reporter: 'mochawesome',
    reporterOptions: {
        reportDir: reportDir,
        overwrite: true,
        html: false,
        json: true,
    },
    e2e: {
        setupNodeEvents(on, config) {
            on('after:run', async () => {
                const webhookURL = '<webhookURL>'; // Webhook URL for Discord
                const resultFile = reportDir + reportFileName + '.json';
                const title = 'Example Test Results'; // Title for results

                await sendDiscordWebhook(
                    webhookURL,
                    resultFile,
                    title,
                );
            });
            return config;
        },
    },
});

Execution

just run cypress

npx cypress run --spec <enter_your_spec>

or

npx cypress run

After the test process is finished, the report will appear on the discord channel.

About

This package sends Mochawesome test results to Discord channel via Discord Webhook.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published