3

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!

Jalal
  • 3,308
  • 4
  • 35
  • 43
  • The structure of the monrepo is not clear. You have enabled nyc for node_modules, do you use a symlink under node_modules to enable the import of pkg1? –  Jul 31 '20 at 09:31
  • @HiramK.Hackenbacker yes, i am using yarn workspace. – Jalal Jul 31 '20 at 14:57
  • i think i have to override webpack config, to make node_modules/@myProject be instrumented by istanbul – Jalal Jul 31 '20 at 15:40
  • Indeed, `babel-plugin-istanbul` is added to webpack config in `@cypress/instrument-cra`. If pkg1 is not React, take a look at how it's done in the source for instrument-cra. –  Jul 31 '20 at 23:28
  • @HiramK.Hackenbacker spent an hours without getting anywhere, then i opened an issue hoping to get any help https://github.com/cypress-io/instrument-cra/issues/172 – Jalal Jul 31 '20 at 23:31
  • Is there a github repo for the code? I can't understand the compilation steps for pkg1, pkg2, pkg3 and if React is the framework for all 3 pkg's or just for react-app. –  Aug 01 '20 at 10:06
  • Hi @HiramK.Hackenbacker. this is branch i am working on right now https://github.com/jalal246/dflex/tree/test/cy_code_cove_2 – Jalal Aug 01 '20 at 15:40
  • Hi, @Elisabetta. No, I haven't but resolving modules as alias could be a potential solution I am not sure though. – Jalal Jun 20 '22 at 11:13

1 Answers1

0

Create .nycrc file in your root folder and:

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