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

cypress-mochawesome-reporter

v3.8.2

Published

Zero config Mochawesome reporter for Cypress with screenshots

Downloads

1,392,925

Readme

cypress-mochawesome-reporter

npm node npm npm

Zero config Mochawesome reporter for Cypress with screenshots attached to tests.

Example report

Cypress compatibility

| reporter version | cypress version | reporter branch | | ---------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------- | | v3 | node >= 14>= 6.7.0 >= 6.2.0 with experimentalRunEvents: true | master | | v2 | >= 6.7.0 >= 6.2.0 with experimentalRunEvents: true | v2 | | v1 | >= 4.0.0 | v1 |

migration guide from v1 to v2

Setup

This setup tutorial works with Cypress >= v10, looking for older version setup? here

  1. install cypress-mochawesome-reporter

    npm i --save-dev cypress-mochawesome-reporter

    or

    yarn add -D cypress-mochawesome-reporter
  2. Change cypress reporter & setup hooks

    Edit config file (cypress.config.js by default)

    const { defineConfig } = require('cypress');
    
    module.exports = defineConfig({
      reporter: 'cypress-mochawesome-reporter',
      e2e: {
        setupNodeEvents(on, config) {
          require('cypress-mochawesome-reporter/plugin')(on);
        },
      },
    });

    If you are override before:run or after:run hooks, use this:

    const { defineConfig } = require('cypress');
    const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
    
    module.exports = defineConfig({
      reporter: 'cypress-mochawesome-reporter',
      e2e: {
        setupNodeEvents(on, config) {
          on('before:run', async (details) => {
            console.log('override before:run');
            await beforeRunHook(details);
          });
    
          on('after:run', async () => {
            console.log('override after:run');
            await afterRunHook();
          });
        },
      },
    });
  3. Add to cypress/support/e2e.js

    import 'cypress-mochawesome-reporter/register';
  4. (optional, if your are using cypress-cucumber-preprocessor) Add to cypress/support/step_definitions/index.js

    import 'cypress-mochawesome-reporter/cucumberSupport';

    ⚠️ cypress-cucumber-preprocessor uses the same hooks as cypress-mochawesome-reporter, you also need to install cypress-on-fix. Full example of using cypress-mochawesome-reporter with cypress-cucumber-preprocessor can be found here.

  5. run cypress

Custom options

If you want to customize your HTML report with mochawesome-report-generator flags just add the flags you want to reporterOptions

const { defineConfig } = require('cypress');

module.exports = defineConfig({
  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    charts: true,
    reportPageTitle: 'custom-title',
    embeddedScreenshots: true,
    inlineAssets: true,
    saveAllAttempts: false,
  },
  e2e: {
    setupNodeEvents(on, config) {
      require('cypress-mochawesome-reporter/plugin')(on);
    },
  },
});

Additional reporter options:

| name | type | default | description | | --------------------- | --------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | embeddedScreenshots | boolean | false | Embedded external screenshots into HTML using base64, use with inlineAssets option to produce a single HTML file | | ignoreVideos | boolean | false | Will not copy videos recorded by Cypress nor show them in the mochawesome report. Requires that Cypress config option video is set to true for the option to have any effectBecause mochawesome doesn't support context per spec file, each test will have the whole spec file video. More info can be found here | | videoOnFailOnly | boolean | false | If Videos are recorded and added to the report, setting this to true will add the videos only to tests with failures.Do not that this will NOT cause video's to only record failed tests, just they not be added to passed tests in the mochawesome report | | quiet | boolean | false | Silence console messages | | saveAllAttempts | boolean | true | Save screenshots of all test attempts, set to false to save only the last attempt | | debug | boolean | false | Creates log file with debug data |

Add extra information to report

Add extra information to the report manually by using cy.addTestContext() as seen in the simple-typescript example test 2

Examples

  1. Simple use of cypress-mochawesome-reporter
  2. Using cypress-multi-reporters
  3. With mochawesome-report-generator flags
  4. Change default screenshots folder in cypress.json
  5. Using cypress-mochawesome-reporter with typescript
  6. Using cypress-mochawesome-reporter with cypress-parallel
  7. Using cypress-mochawesome-reporter with cypress-cucumber-preprocessor

Run npm i in root directory then:

cd examples/<example-project>

npm i
npm test