question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Code coverage tasks not registered by the plugins file

See original GitHub issue

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 Screenshot 2021-02-26 at 15 26 28

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 Screenshot 2021-02-26 at 15 27 49

  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Is it empty? Can you paste at least part of it so we can see the keys and file paths? no folder created Screenshot 2021-02-26 at 16 58 21

  • Do you have any custom NYC settings in package.json (nyc object) 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

3reactions
CharlesStovercommented, Sep 12, 2022

+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.mjs to cypress.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,
  },
};
3reactions
rdhelmscommented, Jul 19, 2021

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,
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get code coverage with Cypress + Istanbul
With @cypress/code-coverage, you have to know that the plugin does not instrument your code. You can use instanbul for that purpose.
Read more >
Code Coverage - Cypress Documentation
The code coverage information in unit tests and end-to-end tests has the same format; the @cypress/code-coverage plugin automatically grabs both and saves the ......
Read more >
How to set up code coverage for cypress - Medium
A quick and short step-by-step tutorial to set up code coverage for cypress automated testing tool.
Read more >
cypress-io/cypress - Gitter
I'm trying to build cypress for ARMv8, but getting this error when running yarn : ... Getting "Code coverage tasks were not registered...
Read more >
@cypress/code-coverage | Yarn - Package Manager
Install. npm install -D @cypress/code-coverage. Note: this plugin assumes cypress is a peer dependency already installed in your project.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found