Heera Singh
Heera Singh

Reputation: 13

Skip Pending and Skipped tests from HTML report in Cypress

I have written some BDD tests in cypress using cucumber and using below command to run my automation tests:

./node_modules/.bin/cypress-tags run -e TAGS='not @ignore and @bdd',allure=true test:all

As I have 1 tests with @bdd tag so it runs it and shows other 3 tests from feature file as Pending

enter image description here

As I have integration with mochawesome and allure both shows Pending tests in corresponding HTML report as well.

enter image description here

Is there any way to skip|remove these tests (Pending and Skipped) from HTML reports

Here is my mochawesome config

enter image description here

Upvotes: 0

Views: 2208

Answers (2)

Fody
Fody

Reputation: 32118

The on('after:run') hook can be used to modify the stats displayed in the header, including the chart.

It's not perfect but may suit your requirement.

cypress.config.js

const { defineConfig } = require('cypress');
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
const { removePendingSkipped } = require('./remove-pending-skipped-from-report');

module.exports = defineConfig({
  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    reportDir: 'test-report',
    ...   // other options
  },
  e2e: {
    setupNodeEvents(on, config) {
      on('before:run', async (details) => {
        await beforeRunHook(details);
      });
      on('after:run', async () => {
        removePendingSkipped(config)
        await afterRunHook();
      });
    },
  },
});

remove-pending-skipped-from-report.js

const path = require('path');
const fs = require('fs-extra')

function removePendingSkipped(config) {
  const jsonPath = path.join(config.reporterOptions.reportDir , '/.jsons', '\mochawesome.json');
  const report = fs.readJsonSync(jsonPath)
  const topSuite = report.results[0].suites[0]
  remove(topSuite)
  fs.writeJsonSync(jsonPath, report)
}

function remove(suite, level = 0) {
  const childSuites = suite.suites.map(child => remove(child, ++level))
  suite.pending = []
  suite.skipped = []
  return suite
}

module.exports = {
  removePendingSkipped
}

Upvotes: 2

Raju
Raju

Reputation: 2509

By default, mochawesome should not show skipped tests in the html report. You can update your config as below.

    showPending: false
    showSkipped: false

You can find all other flags supported in this guide. A sample can be found here.

Upvotes: 0

Related Questions