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

Cypress + Reporter Plugin in nested projects. Could not load reporter by name: reporter #4536

Open
danyfoo opened this issue Jun 20, 2019 · 9 comments
Labels
prevent-stale mark an issue so it is ignored by stale[bot] stage: needs investigating Someone from Cypress needs to look at this topic: reporters 📄

Comments

@danyfoo
Copy link

danyfoo commented Jun 20, 2019

Current behavior:

Based on the project: https://github.com/cypress-io/cypress-test-nested-projects
I'm trying to use a reporter (In these case mochawesome)to generate report logs of my runs in cypress, but it always expected the reporter was installed inside the nested project so cypress never run the tests.

Image with the error that throw:
image

Here is a example repo where you can test this behavior: https://github.com/danyfu/cy_mocha_awesome_nested_folders_tests

Desired behavior:

Cypress runs with the desired reporter without the nested level of the project.

Steps to reproduce: (app code and test code)

Execute npm run cy:run:foo

This is what nested project foo/cypress.json has:

{
    "reporter": "mochawesome",
    "reporterOptions": {
        "mochaFile": "cypress/results/results-[hash].xml"
    }
}

Versions

cypress: ^3.3.1
Chrome: Version 74.0.3729.169 (Official Build) (64-bit)
OS: MacOS 10.14.5 (Mojave)

@pgroot91
Copy link

Also stumbled on the same issue!

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Jul 18, 2019
@Joelasaur
Copy link

Joelasaur commented Jul 19, 2019

Same issue here.

My cypress.json file:

"reporter": "mochawesome", "reporterOptions": { "overwrite": false, "html": false, "json": true }

Doing npm install mocha "fixes" the issue, but I shouldn't have to install mocha to make this work, seeing as Cypress already has it.

Actually installing mocha doesn't fix the issue at all. Halfway through the test run, I'm getting mocha related errors.

TypeError: Cannot read property 'passes' of undefined

Is this because the version of mocha I am installing is independent from what Cypress and/or Mochawesome is using?

This issue has been listed as fixed as of 3.0.0, but I'm on 3.4.0 and still getting it. #1192

Alright I'm going to try the fix authored by YOU54F, see if it works #3537

Actually just downgrading to Mocha 5.2 fixed the issue for me

@danyfoo
Copy link
Author

danyfoo commented Jul 23, 2019

@Joelasaur the problem is because cypress tries to execute Mochawesome inside foo/node_modules.

So I just write a workaround script to run cypress, to define the Mochawesome configuration on the script:

const cypress = require('cypress');
const fs_extra = require('fs-extra');
const { merge } = require('mochawesome-merge');
const generator = require('mochawesome-report-generator');

const project = process.env.PROJECT;

const reportDir = `./results/${project}/reports`;

const mochawesome_options = {
    'timestamp': false,
    'reportDir': reportDir,
    'overwrite': false,
    'html': false,
    'json': true
};

const cypress_options = {
    config: {
        'fileServerFolder': `./source/${project}`,
        'fixturesFolder': `./source/${project}/cypress/fixtures`,
        'integrationFolder': `./source/${project}/cypress/integration`,
        'pluginsFile': `./source/${project}/cypress/plugins/index.js`,
        'supportFile': `./source/${project}/cypress/support/index.js`,
        'screenshotsFolder': `./results/${project}/screenshots`,
        'videosFolder': `./results/${project}/videos`,
        'video': false,
        'reporter': 'mochawesome',
        'reporterOptions': mochawesome_options
    },
    // spec: './source/foo/cypress/integration/examples/actions*.spec.js'
};

async function runTests() {
    try {
        await fs_extra.emptyDir(reportDir);
        await cypress.run(cypress_options);
        const jsonReport = await merge({ reportDir: reportDir });
        await generator.create(jsonReport, mochawesome_options);
    } catch (error) {
        console.error(error);
    } finally {
        process.exit(0);
    }
}

runTests();

The workaround also needs to have a cypress.json on the root of the project with empty object written on the file, to make these approach work.

And you can execute the project using PROJECT=foo node ./run_scripts/run.js

This workaround solution is pushed on the project I written before https://github.com/danyfu/cy_mocha_awesome_nested_folders_tests

@adamtay
Copy link

adamtay commented Jul 24, 2019

Thanks for sharing @Danyfu but this workaround would mean having to rely on a run script and losing the ability to run default cli commands.

Would be great if cypress could also search for node_modules at the project root directory instead of just looking at the nested project directory.

@danyfoo
Copy link
Author

danyfoo commented Jul 24, 2019

@adamtay, You're right!. That's why I need to select the project to run cypress via node environment parameter.

Having a node modules for each project can be an excessive amount of storage.

@heaven
Copy link

heaven commented Jul 31, 2019

We had the same issue with the cypress-teamcity-reporter. The problem was resolved by adding that package to nohoist array of the global package.json:

{
  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/cypress-teamcity-reporter",
      "**/cypress-teamcity-reporter/**"
    ]
  },
}

@mihalcan
Copy link

mihalcan commented Oct 3, 2019

Setting the relative path to mochawesome.js worked fine for me:

"reporter": "../../node_modules/mochawesome/src/mochawesome.js",
"reporterOptions": {
    ...
 }`

@steinybot
Copy link

steinybot commented Dec 19, 2023

Cypress is doing something special here which is messing it up. The loader by default searches upwards and so naturally should work in nested projects. Looks as though it was the fix for #658 which breaks this.

@steinybot
Copy link

Actually no it was there much longer than that. It looks as though it has been that way for a long time, at least as far back as 98c4538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prevent-stale mark an issue so it is ignored by stale[bot] stage: needs investigating Someone from Cypress needs to look at this topic: reporters 📄
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants