1

I am using Cypress and Nyc configurations. My folder structure looks like this:

|/project
| /coverage/
   /lcov-report
    /index.html
 
|/cypress
| /main
   /car
    /car.spec.tsx
    /color.spec.tsx
     ...
| /integration

I need a solution to get inside the index.html only the tests coverage from main folder. So as a result in index.html i need to see only the coverage for the tests that was written there.
I noticed that NYC docs. have some configurations https://github.com/istanbuljs/nyc#common-configuration-options . But there i can specifiy only the files that contains features in include, but in each folder from my project i could have a test file and i can not specify every time the each new file only to get the coverage.
Question: Is there a solution to get the coverage only for the main folder or to get the coverage for the files that have already written a spec test? Or to get a coverage for the file that have spec.tsx extension?

Asking
  • 3,487
  • 11
  • 51
  • 106
  • @user16695029, could you help? – Asking Mar 25 '22 at 08:00
  • What does "But there i can specifiy only the files that contains features in include" mean? – kegne Mar 25 '22 at 08:21
  • @kegne, I mean that according documentation i can specify the files that contain the files with code implementation, not with tests, so i can not specify in `include` for example the files with `spec.tsx` because they contain only tests. This is how i understood. Do i understand correct? – Asking Mar 25 '22 at 08:42
  • Surely you select a subset of ***tests*** in the Cypress configuration? – kegne Mar 25 '22 at 08:53
  • @kegne, what do you mean? – Asking Mar 25 '22 at 08:54
  • 1
    Your explanation is not at all clear, but this ***so i can not specify in include for example the files with spec.tsx*** implies you want to select tests not code files. – kegne Mar 25 '22 at 09:01
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243313/discussion-between-asking-and-kegne). – Asking Mar 25 '22 at 09:28
  • @kegne, i need the coverage only for these file which i have written test. So i need the coverage only for these tests that are located in `main` folder. Please let me know if you understood. – Asking Mar 25 '22 at 09:30
  • @kegne, could you help? It will save my day. – Asking Mar 25 '22 at 11:09
  • 1
    So you written two test for only some of the src files, you want coverage only for those src files? – Visal Mar 27 '22 at 08:59
  • @Vispo Yes, all may tests are in `main` folder from `/cypress` folder. So, yes, i need the coverage only for these files that have tests. But i don't want to specific the list of the files in `include: []` being hardcoded, i want somehow to get the coverage report only for the tests that are in `main` folder. Could you help please? It will help me a lot. – Asking Mar 27 '22 at 10:57
  • Could you help? – Asking Mar 27 '22 at 19:16
  • 3
    The obvious thing is just run the tests in main. But the premise of your question is flawed - Cypress tests **are not unit tests**, there is no 1:1 between test and src. You have to take whatever code-coverage sees when it runs your tests. – Visal Mar 27 '22 at 21:32
  • @Vispo, so i can not get only the test coverage for the tests that was written in `main`? – Asking Mar 28 '22 at 05:50

1 Answers1

4

Please read the documentation, from the above page chose the link to Selecting files for coverage.

Globs are matched using minimatch.

Cypress explains minimatch here.

It's the same as many other places in javascript you will have seen files specified

include: [ '/main/**']
  • this `include` means that will set the coverage only for the tests that was written in `main` folder? I ask you because i understand that `include` means that in the coverage will be included the files that contain features but not tests. So can i add there the `spec.tsx` files? – Asking Mar 25 '22 at 08:29