Skip to content

Generate coverage value for both unit and E2E tests #6690

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

Merged
merged 19 commits into from
Sep 30, 2022

Conversation

cnotv
Copy link
Member

@cnotv cnotv commented Aug 18, 2022

Summary

Fixes #6501
Add coverage report for Rancher Dashboard using Codecov.

Occurred changes and/or fixed issues

  • Correct existing Jest configuration
  • Add configuration for E2E with Cypress
  • Merge coverage values for both the tests
  • Integrate and publish to Codecov GHA
  • Upload coverage using flags for each type: unit, e2e, merged
  • Added documentation about coverage
  • Correct documentation tree

Technical notes summary

  • Added text-summary report for both the tests
  • Corrected Sorry Cypress group-id value with run number and attempt, to provide unique values
  • Added instrumentalization for Nuxt within Babel configuration, required for generating coverage
  • Replaced existing NYC configuration with own file .nycrc to increase visibility and simplify reviews
  • Moved commands interface inside its own global distributed file
  • Fixed issue with /shell/scripts/ folder not excluded from tests and generating non breaking errors in the logs
  • Added @cypress/code-coverage library for integrating coverage with Cypress
  • Added babel-plugin-istanbul library for transpiling code to generate instrumentation through Babel

Notes

  • Coverage files are copied under another name, as they are required to be in the same folder
  • The folder defined in the path of the artifact action is now omitted in GHA Omitting the enclosing directory actions/upload-artifact#30
  • Coverage is collected also on PR as they may be analyzed separately and generate a delta

Areas or cases that should be tested

Values should be displayed on Rancher Dashboard Codecov page.
Example on my fork with already merged branch.

Areas which could experience regressions

Existing pipeline, no actual check is needed.

Screenshot/Video

https://app.codecov.io/gh/rancher/dashboard/pulls

@cnotv cnotv added this to the v2.7.0 milestone Aug 18, 2022
@cnotv cnotv requested a review from richard-cox August 18, 2022 14:29
@cnotv cnotv self-assigned this Aug 18, 2022
@cnotv cnotv changed the title Feature/6501 coverage ops Generate coverage value for both unit and E2E tests Aug 18, 2022
@cnotv
Copy link
Member Author

cnotv commented Aug 18, 2022

It seems like we are not allowed to use Codecov on this repository, which makes exclude the tests from GHA.
Could we take a look @nwmac ?
Screenshot 2022-08-18 at 17 29 36

I had no problem to use that configuration on my fork and PR.

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch from 04ec511 to 932d250 Compare August 22, 2022 06:55
@cnotv
Copy link
Member Author

cnotv commented Aug 22, 2022

Action added to the repository and PR can be now reviewed.

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@3812fa5). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master    #6690   +/-   ##
=========================================
  Coverage          ?   16.50%           
=========================================
  Files             ?     1094           
  Lines             ?    41821           
  Branches          ?    10044           
=========================================
  Hits              ?     6902           
  Misses            ?    34919           
  Partials          ?        0           
Flag Coverage Δ
e2e 43.16% <0.00%> (?)
merged 16.50% <0.00%> (?)
unit 3.60% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch 2 times, most recently from 85e0832 to ccde634 Compare August 22, 2022 13:59
@cnotv
Copy link
Member Author

cnotv commented Aug 22, 2022

I take the chance to correct the (very!) latest changes about testing in the documentation.

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch from ccde634 to 4ac6940 Compare August 22, 2022 15:22
Copy link
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question and a couple of minor comments.

I looked at https://app.codecov.io/gh/rancher/dashboard and couldn't see anything in coverage, will that start displaying when things get in to master? I noticed there was an entry in https://app.codecov.io/gh/rancher/dashboard/pulls, though clicking on that gives some kind of 404 page

@cnotv
Copy link
Member Author

cnotv commented Aug 22, 2022

@richard-cox commits diff can be seen only after merge. PR are not working probably due the checkout in the GHA. I'm going to disable it to see if it changes, as that caused problems also somewhere else, e.g. Sorry Cypress.

@cnotv
Copy link
Member Author

cnotv commented Aug 23, 2022

I'd to merge the conflicts for yarn.lock already 3 times, we may consider push #6035 for it.

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch 8 times, most recently from 78f4cad to 4ddb126 Compare August 23, 2022 17:34
@cnotv
Copy link
Member Author

cnotv commented Aug 23, 2022

I took the chance to upload separated coverage, so they can be analyzed separately.

@cnotv
Copy link
Member Author

cnotv commented Aug 23, 2022

@richard-cox the 404 for the PR is due to the lack of coverage on master. It's explained here that to generate PR dashboards it requires a base and a head of the request.

In my fork you can see that a second PR is actually working fine.

@cnotv cnotv requested a review from richard-cox August 23, 2022 18:28
@cnotv cnotv force-pushed the feature/6501-coverage-ops branch from 4ddb126 to c0a8674 Compare August 26, 2022 08:12
Copy link
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the sum of coverage being lower than the sum of e2e and unit test coverage (https://app.codecov.io/gh/cnotv/dashboard/compare/4/overview .. e2e 43.11% + unit 3.61% = 16.48%)

  • Looking at the e2e (cypress,config.ts) and unit test ('jest.config.js) config it looks like the codeCoverageandcollectCoverageFromvalues should be pretty similar .. except thatcypress//.and/tests/**/.` are not explicitly ignored in jest. I don't think this though would account for the @20% drop
  • above both config's there's a line that might disable the codeCoverage/collectCoverageFrom config
    • coverage: false,
    • collectCoverage: false,
  • it's super hard to tell from the json output, but is there anything obvious in the unit test one (like cypress or shell/scripts) that is there that shouldn't be?
  • Could nyc config like from https://github.com/cypress-io/code-coverage#exclude-files-and-folders help solve the problem?

@cnotv
Copy link
Member Author

cnotv commented Aug 31, 2022

Looking at the e2e (cypress,config.ts) and unit test ('jest.config.js) config it looks like the codeCoverageandcollectCoverageFromvalues should be pretty similar .. except thatcypress//.and/tests/**/.` are not explicitly ignored in jest. I don't think this though would account for the @20% drop

I think is computed with the weight of tests we have.
Unit tests we have 400 tests.
E2E we have 18 tests active of 24.

Also if you check the configuration it is actually ignored for searching tests, based on your previous suggestion. On top of that, the configuration uses an allowing list, instead of an blocking list.

  modulePathIgnorePatterns: [
    '<rootDir>/cypress/',
    '<rootDir>/scripts/',
    '<rootDir>/docusaurus/',
    '<rootDir>/stories/',
    '<rootDir>/shell/scripts/',
  ],

above both config's there's a line that might disable the codeCoverage/collectCoverageFrom config
coverage: false,
collectCoverage: false,

This is intended and should stay like this, otherwise it generates coverage at every test even locally.

it's super hard to tell from the json output, but is there anything obvious in the unit test one (like cypress or shell/scripts) that is there that shouldn't be?

Based on the HTML output and the configuration, there's nothing else as far as I am aware of.

Could nyc config like from https://github.com/cypress-io/code-coverage#exclude-files-and-folders help solve the problem?

Which problem? I think we may use the same configuration of Jest and Cypress, as we already do.

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch from c0a8674 to 5fbf95b Compare August 31, 2022 16:16
@cnotv cnotv requested a review from richard-cox August 31, 2022 16:17
Copy link
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still merge conflicts in yarn.lock. Interestingly the e2e tests pass still

yarn install v1.22.19
info Merge conflict detected in yarn.lock and successfully merged.

https://github.com/rancher/dashboard/runs/8119029734?check_suite_focus=true#step:4:2

@cnotv
Copy link
Member Author

cnotv commented Sep 8, 2022

I may finish the yarn.lock issue by the time we merge this at that point 😬

@cnotv cnotv force-pushed the feature/6501-coverage-ops branch from 5fbf95b to d288161 Compare September 28, 2022 19:06
@cnotv
Copy link
Member Author

cnotv commented Sep 28, 2022

@richard-cox Generated new yarn.lock solving conflicts issues.

Copy link
Member

@nwmac nwmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nwmac nwmac dismissed richard-cox’s stale review September 30, 2022 08:36

yarn.lock has been adressed

@cnotv cnotv merged commit 1c6b5ac into rancher:master Sep 30, 2022
bisht-richa pushed a commit to bisht-richa/dashboard that referenced this pull request Oct 5, 2022
* Correct Jest coverage configuration

* Add coverage upload

* Exclude operationsl scripts from linting

* Rephrase title based on pull request title, run and attempt, with fallback for commits

* Add instrumentation for E2E coverage report

* Add merge logic to the coverage files

* Add instrumentalization for Cypress to generate coverage for E2E

* Download artifacts before merge coverage in CI

* Merge fix

* Copy coverage files before artifact upload

* Add summary after running tests

* Change restriction rules about coverage for pull_request and push

* Add documentation for the coverage

* Correct test documentation folder restructuring

* Add inclusion list for Cypress coverage; add scripts as exclusion

* Extend ignored path to be parsed for Jest to improve performances

* Workflow cleanup

* Checkout current branch head on test runs

* Submit separated coverage with different flags
bisht-richa pushed a commit to bisht-richa/dashboard that referenced this pull request Nov 21, 2022
* Correct Jest coverage configuration

* Add coverage upload

* Exclude operationsl scripts from linting

* Rephrase title based on pull request title, run and attempt, with fallback for commits

* Add instrumentation for E2E coverage report

* Add merge logic to the coverage files

* Add instrumentalization for Cypress to generate coverage for E2E

* Download artifacts before merge coverage in CI

* Merge fix

* Copy coverage files before artifact upload

* Add summary after running tests

* Change restriction rules about coverage for pull_request and push

* Add documentation for the coverage

* Correct test documentation folder restructuring

* Add inclusion list for Cypress coverage; add scripts as exclusion

* Extend ignored path to be parsed for Jest to improve performances

* Workflow cleanup

* Checkout current branch head on test runs

* Submit separated coverage with different flags
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

Successfully merging this pull request may close these issues.

Generate coverage value for both unit and E2E tests
4 participants