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.

regression: Cypress 9.1.0 throws when code coverage is enabled, failing every test

See original GitHub issue

Current behavior

every test fails with a crash

Screen Shot 2021-11-23 at 1 19 07 PM

Desired behavior

Screen Shot 2021-11-23 at 1 13 34 PM

Test code to reproduce

upgrade cypress to 9.1.0 with a project that has followed instructions for enabling instrumenting and code coverage. Failure is in both cypress open and cypress open-ct

Cypress Version

9.1.0

Other

Tested with Cypress 8.3.1 -> 9.1.0. Every version of Cypress except 9.1.0 successfully runs tests with code coverage enabled, version 9.1.0 fails

  "optionalDependencies": {
    "@cypress/code-coverage": "3.9.10",
    "@cypress/react": "5.9.4",
    "@cypress/webpack-dev-server": "1.4.0",
    "@cypress/webpack-preprocessor": "5.9.1",
    "@istanbuljs/nyc-config-typescript": "1.0.1",
    "@jsdevtools/coverage-istanbul-loader": "3.0.5",
    "@testing-library/cypress": "8.0.1",
    "@types/cypress-cucumber-preprocessor": "4.0.1",
    "babel-plugin-istanbul": "6.0.0",
    "cypress": "9.1.0",
    "cypress-cucumber-preprocessor": "4.2.0",
    "cypress-file-upload": "5.0.8",
    "cypress-iframe": "1.0.1",
    "cypress-real-events": "1.5.1"
  }

cypress.json:

{
  "baseUrl": "http://localhost:6007",
  "integrationFolder": "../src",
  "testFiles": "**/integration_tests/**/*.{test.tsx,test.ts,feature}",
  "video": false,
  "component": {
    "componentFolder": "../../",
    "testFiles": "**/component_tests/**/*.{test.tsx,test.ts}"
  }
}

code coverage-related plugins code (it’s all standard stuff):

plugins/index.js

/* eslint-disable @typescript-eslint/no-var-requires */
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

const resolve = require("resolve");
const path = require("path");

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const preprocessor = require("@cypress/webpack-preprocessor");
const codeCoverage = require("@cypress/code-coverage/task");
const cucumber = require("cypress-cucumber-preprocessor").default;
const browserify = require("@cypress/browserify-preprocessor");
const webpackOptions = require("./webpack.config");
const tsConfig = require("../../../../../tsconfig.common.json");

/**
 * @type {Cypress.PluginConfig}
 */
module.exports = (on, config) => {
  const cucumberOptions = {
    ...browserify.defaultOptions,
    typescript: resolve.sync("typescript", { baseDir: config.projectRoot }),
  };

  cucumberOptions.browserifyOptions.transform.unshift([
    // There is absolutely a better way to share these resources, but this is the best
    // I can do given the constraints of git, file links, and the monorepo we live with
    path.resolve("..", "..", "..", "e2e", "cypress", "plugins", "aliaser.js"),
    {
      aliases: tsConfig.compilerOptions.paths,
      baseDir: path.resolve("..", "..", ".."),
    },
  ]);

  if (config.testingType === "component") {
    const { startDevServer } = require("@cypress/webpack-dev-server");

    on("dev-server:start", (options) => startDevServer({ options, webpackConfig: webpackOptions }));
  } else {
    on("file:preprocessor", (file) =>
      file.filePath.includes(".feature") ? cucumber(cucumberOptions)(file) : preprocessor({ webpackOptions })(file)
    );
  }
  codeCoverage(on, config);
  return config;
};

support/index.js

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
import "@cypress/code-coverage/support";
import "cypress-real-events/support";

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tmieuletcommented, Dec 10, 2021

9.1.1 fixed this issue. Thanks

0reactions
cellogcommented, Dec 4, 2021

I’ll try on Monday, thanks so much for the response!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS files were not being correctly resolved which could result in incomplete styling....
Read more >
package.json - rouch/Cypress - NotABug.org
Cypress - Fast, easy and reliable testing for anything that runs in a browser.
Read more >
@cypress/code-coverage - npm
Saves the code coverage collected during Cypress tests. Latest version: 3.10.0, last published: 3 months ago.
Read more >
Changelog - Nextcloud
Nextcloud 9 (unsupported!) Note here that with 'supported' in this context we mean that software updates will be available to the public, not...
Read more >
cypress: Versions - Openbase
0 where ANSI colors were not removed from the cy.fixtures() error code frame. Fixes #20208. Fixed a regression in 9.5.0 where the test...
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