Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to generate the mochawesome merged report #203

Open
naveen1133 opened this issue Oct 29, 2024 · 1 comment
Open

Not able to generate the mochawesome merged report #203

naveen1133 opened this issue Oct 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@naveen1133
Copy link

Environment

- OS: Windows10
- Node: 20.16.0
- cypress-mochawesome-reporter: 3.8.2
- cypress: 10.9.0

What happened?

I am not able to generate the merged reports when I running the test files by using the parallel package.

"scripts": {
"cy:run": "cypress run",
"cy:run:parallel": "cypress-parallel -s cy:run -t 2 -d 'cypress/e2e/**/*.cy.js' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'",
"clean": "rimraf cypress/reports",
"generate-report": "generate-mochawesome-report --set-exit-code",
"test": "npm run clean && npm run cy:run:parallel || true && npm run generate-report"
},

Config file

const { defineConfig } = require('cypress');
const { lighthouse, prepareAudit } = require('@cypress-audit/lighthouse');
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
const fs = require('fs');
const path = require('path');

module.exports = defineConfig({
  e2e: {
    specPattern: 'cypress/e2e/**/*.cy.{js,ts}',
    setupNodeEvents(on, config) {
      // Cypress Mochawesome reporter
      require('cypress-mochawesome-reporter/plugin')(on);

      // Hooks for Mochawesome
      on('before:run', async (details) => {
        console.log('override before:run');
        await beforeRunHook(details);
      });

      on('after:run', async () => {
        console.log('override after:run');
        await afterRunHook();
      });

      // Hook for Lighthouse audits
      on('before:browser:launch', (browser = {}, launchOptions) => {
        prepareAudit(launchOptions);
      });
      on('task', {
        writeAccessibilityReport({ filename, content }) {
          // Define the reports directory
          const reportsDir = path.join(__dirname, '..', 'reports');  // Ensure '..' points to the correct location
          
          // Check if the reports directory exists, if not, create it
          if (!fs.existsSync(reportsDir)) {
            fs.mkdirSync(reportsDir);
          }
    
          // Define the path for the file where the report will be saved
          const filePath = path.join(reportsDir, filename);
    
          // Write the report content to the file
          fs.writeFileSync(filePath, content);
    
          console.log(`report saved as ${filePath}`);
    
          return null;
        }
      });
    

      // Task for generating Lighthouse reports
      on('task', {
        lighthouse: lighthouse((lighthouseReport) => {
          const folderPath = 'lighthouse-report';
          
          const filename = `lighthouse-report-${new Date().toISOString().replace(/[:.]/g, '-')}.html`;
          const filePath = path.join(folderPath, filename);

          if (!fs.existsSync(folderPath)) {
            fs.mkdirSync(folderPath, { recursive: true });
          }

          fs.writeFile(filePath, lighthouseReport.report, (error) => {
            if (error) {
              console.error('Error writing Lighthouse report:', error);
            } else {
              console.log(`Lighthouse report saved as ${filePath}`);
            }
          });
        }),
      });
    },

    // Specify the pattern for test files
    specPattern: 'cypress/e2e/**/*.cy.js',

    // Timeout and configuration options
    pageLoadTimeout: 180000, // 3 minutes
    defaultCommandTimeout: 90000, // 1.5 minutes
    requestTimeout: 60000, // 1 minute
    responseTimeout: 60000, // 1 minute

    // Retries for failed tests
    retries: {
      runMode: 1, // Number of retries when running in CI
      openMode: 0, // Number of retries when running locally
    },
    
    // Cypress Mochawesome reporter configuration
    reporter: 'cypress-mochawesome-reporter',
    reporterOptions: {
      reportDir: 'cypress/reports',
      reportFilename: `cypress-report-${new Date().toISOString().replace(/[:.]/g, '-')}`,
      overwrite: false,
      html: false,
      json: true,
    },
  },
});

Relevant log output

No response

Anything else?

No response

@naveen1133 naveen1133 added the bug Something isn't working label Oct 29, 2024
@LironEr
Copy link
Owner

LironEr commented Oct 29, 2024

I dont see anything special here, you can add debug flag and add the logs here.

Will be best to create a repo with the problem and steps to reproduce the issue so I can have a look.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants