LironEr / cypress-mochawesome-reporter

Zero config Mochawesome reporter for Cypress with screenshots and videos
MIT License
158 stars 49 forks source link

Unable to generate report using cypress-parallel, throwing error - [Error: ENOENT: no such file or directory, open 'cypress/.tmp/cypressMochawesomeReporterConfig.json'] #196

Closed chilkakalpesh closed 3 months ago

chilkakalpesh commented 3 months ago

Environment

- OS: Mac OS M1/Running locally fails and also on CI
- Node: 16.6.0
- cypress-mochawesome-reporter: 3.8.2
- cypress: 13.8.1

What happened?

Trying to generate mochawesome report using cypress-parallel. Followed the guide - https://github.com/LironEr/cypress-mochawesome-reporter/tree/master/examples/cypress-parallel. But throwing error:

[Error: ENOENT: no such file or directory, open 'cypress/.tmp/cypressMochawesomeReporterConfig.json'] { errno: -2, code: 'ENOENT', syscall: 'open', path: 'cypress/.tmp/cypressMochawesomeReporterConfig.json' }

package.json

 "scripts": {
    "test:dev:es:parallel": "cypress-parallel -s test:dev:es -t 3 -d 'cypress/e2e/es' -n './node_modules/cypress-multi-reporters' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'",
    "clean": "rimraf cypress/reports",
    "generate-report": "generate-mochawesome-report --set-exit-code",
    "test": "pnpm run clean && pnpm run test:dev:es:parallel || true && pnpm run generate-report"
  },

e2e.ts

// Import commands.js using ES2015 syntax:
import './commands';
import 'cypress-plugin-api';
import '@cypress/xpath/src';
import 'cypress-mochawesome-reporter/register';
import * as dayjs from 'dayjs';

Cypress.dayjs = dayjs;

Cypress.on('uncaught:exception', (err) => {
  // returning false here prevents Cypress from
  // failing the test
  console.log(`exception- ${err}`);
  return false;
});

Config file

import { defineConfig } from 'cypress';
import { beforeRunHook } from 'cypress-mochawesome-reporter/lib';

export default defineConfig({
  defaultCommandTimeout: 30000,
  requestTimeout: 30000,
  viewportWidth: 1200,
  viewportHeight: 1200,
  screenshotOnRunFailure: true,
  video: false,
  chromeWebSecurity: false,
  reporter: 'cypress-mochawesome-reporter',
  e2e: {
    testIsolation: false,
    setupNodeEvents(on, config) {
      on('before:run', async (details) => {
        await beforeRunHook(details);
      });
  },
});

Relevant log output

kalpesh-manohar@Kalpeshs-MacBook-Pro e2e-tests % pnpm run test

> @huspy/e2e-tests@1.0.0 test /Users/kalpesh-manohar/stack/lang/python/brokers/packages/e2e-tests
> pnpm run clean && pnpm run test:dev:es:parallel || true && pnpm run generate-report

 WARN  Issue while reading "/Users/kalpesh-manohar/stack/lang/python/brokers/.npmrc". Failed to replace env in config: ${GITHUB_TOKEN}

> @huspy/e2e-tests@1.0.0 clean /Users/kalpesh-manohar/stack/lang/python/brokers/packages/e2e-tests
> rimraf cypress/reports

sh: rimraf: command not found
 ELIFECYCLE  Command failed.
 WARN  Issue while reading "/Users/kalpesh-manohar/stack/lang/python/brokers/.npmrc". Failed to replace env in config: ${GITHUB_TOKEN}

> @huspy/e2e-tests@1.0.0 generate-report /Users/kalpesh-manohar/stack/lang/python/brokers/packages/e2e-tests
> generate-mochawesome-report --set-exit-code

read config from cypress/.tmp/cypressMochawesomeReporterConfig.json
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: ENOENT: no such file or directory, open 'cypress/.tmp/cypressMochawesomeReporterConfig.json'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'cypress/.tmp/cypressMochawesomeReporterConfig.json'
}
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Test failed. See above for more details.

Anything else?

No response

chilkakalpesh commented 3 months ago

Fixed the issue by removing -n './node_modules/cypress-multi-reporters' from script "test:dev:es:parallel". Reporter was getting confused and also downgraded the reporter version - "cypress-mochawesome-reporter": "^3.6.0"

"test:dev:es:parallel": "cypress-parallel -s test:dev:es -t 3 -d 'cypress/e2e/es' -n './node_modules/cypress-multi-reporters' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'",