Skip to content

Support should not send coverage unless plugins task has been registered #179

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

Closed
bahmutov opened this issue Apr 6, 2020 · 6 comments · Fixed by #180
Closed

Support should not send coverage unless plugins task has been registered #179

bahmutov opened this issue Apr 6, 2020 · 6 comments · Fixed by #180
Labels

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Apr 6, 2020

in a situation where a support file has been registered BUT there is no task in the plugins file, we should not try to call the coverage report task

Example situation

{
  "pluginsFile": false,
  "supportFile": "node_modules/cypress-react-unit-test/support"
}
@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 6, 2020

Screen Shot 2020-04-06 at 9 08 19 AM

Maybe we should use window.__coverage__ to know?

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 6, 2020

Maybe if plugins can set a variable when registering a task we could do

// user code
module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config)
}

inside the task

module.exports = (on, config) => {
  on('task', tasks)
  config.env.codeCoverageTasksRegistered = true
  return config
}

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 6, 2020

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@quisido
Copy link
Contributor

quisido commented Dec 21, 2021

Is it possible for this to throw an error? I've been debugging for days why I'm not getting any coverage files in my CI workflow. Local tests didn't give me anything either, and this warning was simply not visible:
image
It was sheer happenstance that I ran a one-liner test on a local Cypress instance and saw this banner.

The end problem was that my plugins file's default export wasn't returning config after I mutated it with @cypress/code-coverage:

import task from '@cypress/code-coverage';
export default function(on, config) {
  task(on, config);
  return config; // <-- REQUIRED
}

This would have been so much easier to debug if CI had failed with an error that the code coverage task had not registered instead of failing silently.

@taymoork2
Copy link

taymoork2 commented Mar 28, 2022

For those who run into the edge case of trying to add process.env to config.env (i.e. config.env = process.env)
This comment from issue #405 helped resolved the issue of code coverage tasks not registering

#405 (comment)

TLDR:

require('@cypress/code-coverage/task')(on, config)
config.env = {
  ...process.env,
  ...config.env, // Don't overwrite `codeCoverageTasksRegistered` set by `@cypress/code-coverage/task`
};

@gwvt
Copy link

gwvt commented May 8, 2022

How do you keep the coverage tasks registered when using multiple config files as documented at https://docs.cypress.io/api/plugins/configuration-api#Customize-available-browsers?

In plugins/index.js as documented there:

module.exports = (on, config) => {
  const environment = config.env.configFile || "development";
  const configurationForEnvironment = fetchConfigurationByFile(environment);

  return configurationForEnvironment || config;
};

How do you incorporate

  require('@cypress/code-coverage/task')(on, config);

to register the coverage tasks on the returned config object? Config by file works but without coverage. Coverage works without config by file (i.e., just returning config). I can't get both to work together...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants