Getting "Error: Pattern mochawesome-report/*.json matched no report files" error only when test running in github action

4.8k views Asked by At

I am able to merge and generate reports in my local but when I am running mt test into GitHub action through error ERROR: Failed to merge reports. I never used GitHub action before so maybe I have made a mistake. Any suggestions are welcome.

Here is my cypress.json file

{
  "reporter": "cypress-mochawesome-reporter",
  "reporterOptions": {
    "reportDir": "cypress/Reports",
    "charts": true,
    "overwrite": false,
    "html": false,
    "json": true,
    "reportPageTitle": "Legrande Cypress",
    "reportFilename": "Legrande Cypress Test Report",
    "embeddedScreenshots": true,
    "inlineAssets": true
  },
  "defaultCommandTimeout": 30000,
  "retries": {
    "runMode": 1,
    "openMode": 1
  },
  "video": false,
  "scrollBehavior": "nearest",
  "chromeWebSecurity": false,
}

Here is my package.json file.

{
  "name": "cypressautomation",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "delete:reportFolder": "rm -rf mochawesome-report/",
    "test:cli": "npm run delete:reportFolder && cypress run",
    "merge:reports": "mochawesome-merge mochawesome-report/*.json > cypress-combined-report.json",
    "create:html:report": "npm run merge:reports && marge --reportDir TestReport cypress-combined-report.json",
    "cy:run": "cypress run",
    "record-test": "cypress run --record --key ######################"
  },
  "reporter": "cypress-mochawesome-reporter",
  "reporterOptions": {
    "reportDir": "cypress/Reports",
    "charts": true,
    "reportPageTitle": "My Test Suite",
    "embeddedScreenshots": true,
    "inlineAssets": true
  },
  "video": false,
  "author": "weblylab",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^9.5.0",
    "cypress-file-upload": "^5.0.2",
    "cypress-mochawesome-reporter": "^2.2.0",
    "cypress-slack-reporter": "^1.2.1",
    "cypress-xpath": "^1.6.1",
    "faker": "^5.5.3",
    "i": "^0.3.6",
    "mocha": "^8.4.0",
    "mochawesome": "^6.2.2",
    "mochawesome-merge": "^4.2.0",
    "mochawesome-report-generator": "^5.2.0",
    "tsconfig-paths": "^3.9.0"
  },
  "dependencies": {
    "@auth0/auth0-spa-js": "^1.13.6",
    "@types/bluebird": "^3.5.33",
    "@types/lodash": "^4.14.168",
    "chai": "^4.3.0",
    "cypress-iframe": "^1.0.1",
    "cypress-skip-test": "^1.0.0",
    "delay": "^5.0.0",
    "Faker": "^0.7.2",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "resolve-url": "^0.2.1",
    "save": "^2.4.0",
    "source-map-resolve": "^0.6.0",
    "urix": "^0.1.0",
    "xlsx": "^0.17.0"
  }
}

And here is my cypress.yml file that I used for GitHub action.

name: GitHub Actions Demo
on:
  schedule:
  - cron: "0 0 * * *"
  push:
    branches:
      - 'master'

jobs:
 cypress-test:
  name: Run on windows
  runs-on: windows-latest
  steps: 
    - uses: actions/checkout@v2

    - name: Install dependencies
      run: |
        npm install
        npm install --dev
        npm run record-test

    - name: Copy execution test screenshots
      run: |
        mkdir public
        cp -r cypress/screenshots public/screenshots
    
    - name: Merge test reports
      run: npm run merge:reports

    - name: Generate HTML reports
      run: npm run create:html:report

I am getting the below error for merging reports. In my local machine, it working fine.

enter image description here

2

There are 2 answers

0
Kris Luminar On

I had similar issues and solved some of them with

    reporter: '../node_modules/cypress-mochawesome-reporter',
    video: true,
    reporterOptions: {
        reportDir: 'reports/mochawesome',

That said, I found a reference saying that you need a relative directory now for reportDir, so I suspect that my reportDir above is only working because I happened to select the default directory used by Mochawesome.

0
gagneet On

Did you try to change the

"reportDir": "cypress/Reports",

to the mochawesome-report

"reportDir": "cypress/reports/mochawesome-report",

Also, check your plugins/index.js

  on('before:run', async (details) => {
    console.log('Override before:run');
    await beforeRunHook(details);
    // Note: if you are using other than Windows remove below two lines, start with await exec
    //await exec("IF EXIST cypress\\screenshots rmdir /Q /S cypress\\screenshots")
    //await exec("IF EXIST cypress\\reports rmdir /Q /S cypress\\test-reports")
    //await exec("IF EXIST cypress\\reports rmdir /Q /S cypress\\reports")
  });

  on('after:run', async () => {
    console.log('Override after:run');
    // Note: if you are using other than Windows remove below line, starts with await exec
    //await exec("npx jrm ./cypress/reports/junitreport.xml ./cypress/test-reports/junit-report-[hash].xml");
    //await exec("npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit-report-[hash].xml");
    await afterRunHook();
  });