Error: Code coverage tasks not registered by the plugins file
Code-coverge debug logs:
code-coverage combined NYC options { 'report-dir': './coverage', reporter: [ 'lcov', 'clover', 'json', 'json-summary' ], extension: [ '.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx' ], excludeAfterRemap: false } +0ms
thats it and nothing else
Added in support --> index.js
import '@cypress/code-coverage/support';
In plugin index.js -->
const corePlugins = require('@company/e2e-core/plugins');
module.exports = function plugins(on, config) {
// eslint-disable-next-line global-require
require('@cypress/code-coverage/task')(on, config);
corePlugins(on, config);
return config;
};
Always get below error

tried adding this
require('@cypress/code-coverage/task')(on, config);
in e2e-core/plugins as well then it says
Warning: Multiple attempts to register the following task(s): resetCoverage, combineCoverage, coverageReport. Only the last attempt will be registered.
Versions Cypress 6.5.0 mac os catalina Node v15.8.0 NPM v7.5.3 Instrumentation: istanbul React application Code-coverage: 3.9.2 webpack-preprocessor: 5.6.0 cucumber-preprocessor: 4.0.1 Shell: xsh
We have e2e tests as feature files. Cypress is in the root where as application is as packages. We also have e2e-core package for cypress where there is also a common plugins file loaded onto cypress folder plugins-->index.js.
webpack.config.js
module.exports = {
node: { fs: 'empty', child_process: 'empty', readline: 'empty' },
module: {
rules: [
{
test: /\.js?$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['istanbul'],
},
}],
},
{
test: /\.feature$/,
use: [
{
loader: 'cypress-cucumber-preprocessor/loader',
},
],
},
],
},
};
webpack index.js
const webpack = require('@cypress/webpack-preprocessor');
const webpackOptions = require('./webpack.config');
module.exports = function webpackPreprocessor(on) {
on('file:preprocessor', webpack({
webpackOptions,
}));
};
Instrumentation is setup. window.coverage works

-
Is there
.nyc_outputfolder? Is there.nyc_output/out.jsonfile. Is it empty? Can you paste at least part of it so we can see the keys and file paths? no folder created
-
Do you have any custom NYC settings in
package.json(nycobject) or in other NYC config files no -
Do you run Cypress tests in a Docker container? not in this case
Link to the repo Not a public repo.
Check this: https://github.com/cypress-io/code-coverage/issues/331
I tried the solution mentioned there i.e
return _.merge({}, webpack, envConfig, codeCoverage);
and I still have the same issue.
In this case when I see in cypress configuration on the browser there is
codeCoverageTasksRegistered:"true"
along with my other environment variables. So I don't see why it is not working.
Also weirdly if I remove envConfig then i see coverage working but obviously I cannot run tests without env variables.
This is how the plugin/index.js is. Is there anything wrong with the below code?
const _ = require('lodash');
const env = require('/e2e-core/plugins/setEnv');
const corePlugin = require('/e2e-core/plugins');
module.exports = function plugins(on, config) {
const webpack = corePlugin(on, config);
const codeCoverage = require('@cypress/code-coverage/task')(on, config);
const envConfig = env(on, require('dotenv').config({ path: `${process.cwd()}/cypress/.env` }));
return _.merge({}, webpack, envConfig, codeCoverage);
};
codeCoverageTasksRegistered:"true" when this clearly present in env variables in the configuration I should not get Code coverage tasks not registered by the plugins file this error right?
Hmmm this is how my plugins.js is looking like and working well:
module.exports = async (on, config) => {
require('@cypress/code-coverage/task')(on, config)
const file = config.env.configFile || 'dev'
const envConfig = await getConfigurationByFile(file)
const allConfig = merge({}, config, envConfig)
return allConfig
}
This is my getConfigurationByFile function, for reference:
async function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve('cypress/config', `cypress.${file}.json`)
return await fs.readJson(pathToConfigFile)
}
hope it helps!
I tried many things still have no idea.
cy.log(env:${Cypress.env('codeCoverageTasksRegistered')});. --> this is true but still not working
I think it is related to the way we are env variables
const envConfig = env(on, require('dotenv').config({ path: ${process.cwd()}/cypress/.env }));
in env its like below
module.exports = (on, config) => {
config.env = process.env;
return config;
};
we have a lot of variables in .env. Is there any example with require('dotenv').config()? If I comment the env variable part I see code coverage starts working.
Not understanding how is this possible.
Did anyone manage to make any headway here? Having the exact same issues. 🙏
In our case, the problem was that we were doing config.env = process.env, which I suppose must have been overwriting some value that @cypress/code-coverage was setting. One way to fix it was to make sure that any existing config.env values were still kept:
require('@cypress/code-coverage/task')(on, config)
config.env = {
...process.env,
...config.env,
}
This is exactly what I tried but it still tells me that the tasks weren't registered. If I log out the config, I can clearly see that codeCoverageTasksRegistered: true so I can't even begin to fathom why this isn't working.
Any updates on this?
add { "env": { "codeCoverageTasksRegistered": true } } in env json file for example config/dev.json
In my case, Cypress version 10.3.1, the setupNodeEvents runs AFTER the supportFile, so it indeed there's a problem here.
I could testify this by putting a throw new Error in the beginning of each one and running to see what breaks first.
+1 to @jourdanrodrigues
I was debugging this for ages and ended up forking this repo and throwing errors every-which-way to find out why it wasn't working. I eventually found that the tasks weren't registered and "to fix this in config's setupNodeEvents."
I made the following changes to fix this:
- Renamed
cypress.config.mjstocypress.config.cjs(ESM to CJS). - Deleted the plugin from
cypress/plugins/e2e.ts. - Added the following to
cypress.config.cjs:
module.exports = {
e2e: {
setupNodeEvents(on, config) {
require('@cypress/code-coverage/task')(on, config);
return config;
},
},
env: {
codeCoverageTasksRegistered: true,
},
};
+1 to @jourdanrodrigues
I was debugging this for ages and ended up forking this repo and throwing errors every-which-way to find out why it wasn't working. I eventually found that the tasks weren't registered and "to fix this in config's
setupNodeEvents."I made the following changes to fix this:
- Renamed
cypress.config.mjstocypress.config.cjs(ESM to CJS).- Deleted the plugin from
cypress/plugins/e2e.ts.- Added the following to
cypress.config.cjs:module.exports = { e2e: { setupNodeEvents(on, config) { require('@cypress/code-coverage/task')(on, config); return config; }, }, env: { codeCoverageTasksRegistered: true, }, };
Thanks! I don't know why exactly, but this worked nicely for me. It seems that setupNodeEvents is overwriting the plugins configuration, which I suppose is an unexpected behavior.