Jalal
Jalal

Reputation: 3644

How to include monorepo packages in Cypress code coverage

I have multi packages in monorepo.

/pkg1
/pkg2
/pkg3
     - react-app
     - cypress
     - src
     - package.json

I am using @cypress/instrument-cra to collect coverage and it works only to cover the code inside react-app.

I need to go further because react-app is actually just a playground while the src has to be covered along with other packages that are used inside the react-app. I am importing packages as following:

import pkg1 from @myProject/pkg1

How can I use code coverage for pkg1?

I tried to config nyc but it didn't work

"nyc": {
  "all": true,
  "include": [
    "node_modules"
  ],
  "excludeNodeModules": false
}

Thanks!

Upvotes: 4

Views: 1517

Answers (2)

Ghanshyam Patel
Ghanshyam Patel

Reputation: 11

{
  cwd:"../"
}

By default, cypress will instrument only code residing in the react-app. So, you have to change the cwd to the root. Refer to this GitHub issue for more details: nyc does not work with symlinks

Upvotes: 1

devHichri
devHichri

Reputation: 11

Create .nycrc file in your root folder and:

{
  "all": true,
  "include": [
    "pkg1/src/**"
  ],
  "exclude": [
    "**/test/**"
  ],
}

Upvotes: 0

Related Questions