Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimate code coverage for the current frontend codebase #1023

Closed
jiji14 opened this issue Oct 24, 2023 · 12 comments
Closed

Estimate code coverage for the current frontend codebase #1023

jiji14 opened this issue Oct 24, 2023 · 12 comments

Comments

@jiji14
Copy link

jiji14 commented Oct 24, 2023

Estimate code coverage for the current frontend codebase

We've made significant progress in setting up unit tests for e-emission-phone and are actively writing test cases as we overhaul Angular services. To gauge the effectiveness of our test suite, we aim to estimate the code coverage.

You can find test codes here

Related Issue

Estimate code coverage for the current server codebase


I've researched 3 well-known code coverage tools that work with jest and GitHub actions.


jest-coverage

Jest-coverage is a tool that extends Jest to provide code coverage reports. To generate code coverage reports using Jest, we can run tests with coverage using the --coverage flag.

[ Report Sample ]

  • This screenshot is our test case.

Screenshot 2023-10-26 at 11 31 17 AM

  1. Function coverage: Determines if each function has been called.
  2. Statement coverage: Checks if each statement in the program has been executed.
  3. Branch coverage: Evaluates whether each branch of control structures, like if and case statements, has been executed.
  4. Line coverage: Verifies if each executable line in the source file has been executed.

[ Pros ]

  1. Integration with Jest. (No need for complex setup)

[ Cons]

  1. Limited to Jest, limiting integration with other testing frameworks.
  2. Reports are somewhat simple compared to other options

[ Resources ]
jest-coverage
stackoverflow - jest-coverage issue


Codecov

Codecov is an all-in-one code coverage reporting solution that focuses on integration and encourages healthy pull requests. It delivers coverage metrics directly into the modern workflow, particularly in pull requests.

[ Report Sample ]
Screenshot 2023-10-26 at 11 20 01 AM

  1. hit: indicates that the source code was executed by the test suite.
  2. miss: indicates that the source code was not executed by the test suite.
  3. partial: indicates that the source code was not fully executed by the test suite; there are remaining branches that were not executed.

[ Pros ]

  1. Forever Free for Open Source 😸
  2. Provides detailed and customizable reports

[ Cons]

  1. Initial setup can be somewhat complex and may require additional time.

[ Resources ]
codecov.io


Istanbul

Istanbul instruments your ES5 and ES2015+ JavaScript code with line counters, allowing you to track code coverage based on unit tests.

[ Pros ]

  1. Offers more options for report formats and configuration compared to jest-coverage.

[ Cons]

  1. For TypeScript, transpilation to JavaScript is required, introducing an additional step.

[ Report Sample ]
Screenshot 2023-10-25 at 11 46 44 AM

[ Resources ]
Gudie for instanbul

Jest-coverage VS Codecov VS Istanbul

Screenshot 2023-10-26 at 11 54 37 AM
  • I did not consider JS Coverage as an option because it lacks support for CI/CD integration, and its last update is outdated.

[ Resources ]
code-coverage-js-in-2023


I am inclined towards Codecov because it is free for open-source projects and offers various features with user-friendly and readable reports.

@jiji14 jiji14 moved this to Issues being worked on in OpenPATH Tasks Overview Oct 24, 2023
@jiji14 jiji14 moved this from Issues being worked on to Ready for review in OpenPATH Tasks Overview Oct 26, 2023
@shankari
Copy link
Contributor

@jiji14 before we use any third party (hosted) tools, we have to get approval from NREL IT.
GitHub is pre-approved, which is why we are able to use GitHub and GH Actions.
I agree that codecov seems cool, but we should get started with the process to request approval immediately
It may be that it is also pre-approved (best case scenario!)

If not, Jest seems pretty good, but does it cover end-to-end testing? I am not sure that code coverage tools will do well with end-to-end testing anyway since they work at the code lines level.

@shankari shankari moved this from Ready for review to Review done; Changes requested in OpenPATH Tasks Overview Oct 26, 2023
@jiji14
Copy link
Author

jiji14 commented Oct 26, 2023

@shankari
It does not cover end-to-end testing because code coverage tools check the source code line by line, as you mentioned. End-to-end testing is a UI-level automation, not code-level. However, there are other tools available for checking end-to-end testing coverage (although I haven't delved deeply into this).

I also agree that jest-coverage is a good alternative if we can't get approval with codecov.

@jiji14 jiji14 moved this from Review done; Changes requested to Ready for review in OpenPATH Tasks Overview Oct 26, 2023
@shankari
Copy link
Contributor

shankari commented Oct 26, 2023

@jiji14 sounds good. What additional feedback would you like from me?
I think that the next step is to contact IT for a "solution exception" for codecov and update the issue with what they find.

@shankari shankari moved this from Ready for review to Review done; Changes requested in OpenPATH Tasks Overview Oct 26, 2023
@jiji14
Copy link
Author

jiji14 commented Oct 26, 2023

@shankari
Nothing for now. I will contact IT and will update how it goes!

@jiji14
Copy link
Author

jiji14 commented Nov 2, 2023

@shankari

I need to submit a Security Impact Analysis. I am wondering who the System owner will be and how many members will have access to the account.

@jiji14 jiji14 moved this from Review done; Changes requested to Ready for review in OpenPATH Tasks Overview Nov 2, 2023
@shankari
Copy link
Contributor

shankari commented Nov 2, 2023

@jiji14 I am 99% sure you don't need to submit an SIA. The SIA is for systems that we want to run internally, which is why they are asking for a system owner. We want to use an external service, which would be a technology exception. Please cc me on the discussion with IT if needed and I can clarify if there are any questions.

@shankari shankari moved this from Ready for review to Review done; Changes requested in OpenPATH Tasks Overview Nov 2, 2023
@jiji14
Copy link
Author

jiji14 commented Nov 21, 2023

@shankari

I received approval from the IT team. Should I reach out to Codecov directly to request access for the open-source project? Additionally, I think you should sign up with your GitHub handle to set up Codecov in the e-mission-phone project. After I signed up with my GitHub handle, I could only see the repositories that I owned. You can find the setup documentation here.

Image

@jiji14 jiji14 moved this from Review done; Changes requested to Ready for review in OpenPATH Tasks Overview Nov 21, 2023
@shankari
Copy link
Contributor

@jiji14 can you add me to the ticket related to the this, so I can have the approval for the record?
I will sign up for codecov over the weekend 😄

@shankari
Copy link
Contributor

@jiji14 thanks for adding me to the ticket. Signing up for codecov now...

@shankari
Copy link
Contributor

Signed up!

@shankari shankari moved this from Ready for review to Issues being worked on in OpenPATH Tasks Overview Nov 23, 2023
@jiji14
Copy link
Author

jiji14 commented Nov 24, 2023

@shankari
Can you please add the repository token to the e-mission-phone repository?

Here are the steps:

  1. Sign in to the Codecov website.

  2. Click on the e-mission-phone repository in dashboard.

Image

  1. Copy the token.

Image

  1. Go to the repository settings and paste the token in Settings > Security and Variables > Actions.
    Image

After you add the token, I will submit Codecov Github action PR.
Thank you!

@jiji14 jiji14 moved this from Issues being worked on to Ready for review in OpenPATH Tasks Overview Nov 24, 2023
@shankari
Copy link
Contributor

Added the token

@shankari shankari moved this from Ready for review to Issues being worked on in OpenPATH Tasks Overview Nov 25, 2023
@jiji14 jiji14 closed this as completed Dec 7, 2023
@github-project-automation github-project-automation bot moved this from Issues being worked on to Tasks completed in OpenPATH Tasks Overview Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants