Closed bahmutov closed 4 years ago
Maybe we should use window.__coverage__
to know?
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
}
:tada: This issue has been resolved in version 3.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
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: 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.
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
https://github.com/cypress-io/code-coverage/issues/405#issuecomment-882820159
TLDR:
require('@cypress/code-coverage/task')(on, config)
config.env = {
...process.env,
...config.env, // Don't overwrite `codeCoverageTasksRegistered` set by `@cypress/code-coverage/task`
};
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...
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