cypress-io / code-coverage

Saves the code coverage collected during Cypress tests
MIT License
432 stars 108 forks source link

Code coverage e2e and unit test combining not working #265

Open julianklumpers opened 4 years ago

julianklumpers commented 4 years ago

Logs and screenshots

first.spec.ts Screenshot 2020-06-20 at 23 44 58

second.spec.ts Screenshot 2020-06-20 at 23 43 12

Versions

i use typescript in my project and test files.

Link to the repo Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved.

Example See #217 that is an excellent bug report example

edimitchel commented 4 years ago

Hi @julianklumpers, You still have this issue ?

pakatagoh commented 4 years ago

I'm getting a similar issue when working with spec files that have unit tests

Placing the following into cypress/plugins/index.js according to the docs returns me an error message shown as below

/// <reference types="cypress" />

module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config);
  on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'));
  return config;
};

image

Currently working on a Next.js project in a monorepo

.babelrc

{
  "presets": ["next/babel"],
  "plugins": [
    [
      "styled-components",
      {
        "ssr": true,
        "displayName": true,
        "preprocess": false
      }
    ],
    "istanbul"
  ],
}

Installed @istanbuljs/nyc-config-typescript cypress nyc source-map-support ts-node

Inside package.json

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript"
  },

After changing /cypress/plugins/index.js to the following

const browserify = require('@cypress/browserify-preprocessor');
le.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config);

  const options = browserify.defaultOptions;
  options.browserifyOptions.transform[1][1].babelrc = true;
  on('file:preprocessor', browserify({ ...options, typescript: require.resolve('typescript') }));
  return config;
};

I get a new error image

Any help or insights will be appreciated. After looking through the examples, there doesn't seem to be one with a cypress(cypress tests written in ts as well) + monorepo(not sure if this would affect anything) + Next.js(written with ts)

jashworth commented 3 years ago

Hi @pakatagoh, did you manage to find a fix?

pakatagoh commented 3 years ago

Hi @pakatagoh, did you manage to find a fix?

@jashworth unfortunately not. it's been a year since I've worked on the issue. in the end I believe we falled back to many more unit tests. sorry I don't have a solution.

jashworth commented 3 years ago

@pakatagoh Thanks for replying.

I managed to get it working with webpack in the end, in a similar way to #435, where I've added a comment.