Skip to content

Coverage with Changed #5237

@bad4iz

Description

@bad4iz

Clear and concise description of the problem

--coverage + --changed don't work well together. Coverage doesn't do anything special when --changed is passed.
There are files for which there are no tests.

I created an example where you can see it.
https://gitlab.com/bad4iz/file-signature-in-react/-/merge_requests/92

$ git diff --name-only origin/develop HEAD
.gitlab-ci.yml
src/component/SelectCert.Copy.tsx
src/component/utils/toBase64.ts
$ /builds/bad4iz/file-signature-in-react/node_modules/.bin/vitest --coverage.enabled --changed=origin/develop
 RUN  v1.2.2 /builds/bad4iz/file-signature-in-react
      Coverage enabled with v8
stderr | plugin_loaded_error (/builds/bad4iz/file-signature-in-react/node_modules/crypto-pro-cadesplugin/dist/lib/cadesplugin_api.js:527:17)
Плагин недоступен
 ✓ src/component/utils/signFile.spec.js  (3 tests) 6ms
 ✓ src/component/utils/toBase64.spec.ts  (1 test) 7ms
 Test Files  2 passed (2)
      Tests  4 passed (4)
   Start at  10:51:05
   Duration  1.14s (transform 33ms, setup 0ms, collect 65ms, tests 13ms, environment 422ms, prepare 162ms)
 % Coverage report from v8
--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------|---------|----------|---------|---------|-------------------
All files     |   73.25 |      100 |      60 |   73.25 |                   
 b64toBlob.ts |   34.28 |      100 |       0 |   34.28 | 13-35             
 signFile.ts  |     100 |      100 |     100 |     100 |                   
 toBase64.ts  |     100 |      100 |   66.66 |     100 |                   
--------------|---------|----------|---------|---------|-------------------
Done in 1.76s.
  • What files would you expect to be included in coverage report in this case?
  • src/component/SelectCert.Copy.tsx

and just the second problem. It's strange how the coverage works with --changes + coverage
vitest --coverage.enabled --changed=origin/develop --coverage.all=true
https://gitlab.com/bad4iz/file-signature-in-react/-/jobs/6198442714

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   11.43 |    31.57 |   16.66 |   11.43 |                   
 src               |       0 |        0 |       0 |       0 |                   
//........             
  index.ts         |       0 |        0 |       0 |       0 | 1-2               
 ...omponent/utils |   55.75 |       75 |   42.85 |   55.75 |                   
  b64toBlob.ts     |   34.28 |      100 |       0 |   34.28 | 13-35             
  checkQuotes.ts   |       0 |        0 |       0 |       0 | 1-9               
  extract.ts       |       0 |        0 |       0 |       0 | 1-18              
  signFile.ts      |     100 |      100 |     100 |     100 |                   
  toBase64.ts      |     100 |      100 |   66.66 |     100 |                   
 ...nt/utils/hooks |       0 |        0 |       0 |       0 |                   
  index.js         |       0 |        0 |       0 |       0 | 1-2               
  ...oCertsList.ts |       0 |        0 |       0 |       0 | 1-27              
  ...ertificate.ts |       0 |        0 |       0 |       0 | 1-29              
-------------------|---------|----------|---------|---------|-------------------

and
vitest --coverage.enabled --coverage.all=true
https://gitlab.com/bad4iz/file-signature-in-react/-/jobs/6198442715

% Coverage report from v8
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   30.12 |    63.33 |   44.44 |   30.12 |                   
 src               |       0 |        0 |       0 |       0 |                   
//.....            
 ...omponent/utils |   97.34 |    86.66 |   85.71 |   97.34 |                   
  b64toBlob.ts     |     100 |      100 |     100 |     100 |                   
  checkQuotes.ts   |     100 |      100 |     100 |     100 |                   
  extract.ts       |   83.33 |    33.33 |     100 |   83.33 | 11-13             
  signFile.ts      |     100 |      100 |     100 |     100 |                   
  toBase64.ts      |     100 |      100 |   66.66 |     100 |                   
 ...nt/utils/hooks |   96.55 |    85.71 |   66.66 |   96.55 |                   
  index.js         |       0 |        0 |       0 |       0 | 1-2               
  ...oCertsList.ts |     100 |      100 |     100 |     100 |                   
  ...ertificate.ts |     100 |      100 |     100 |     100 |                   
-------------------|---------|----------|---------|---------|------------------

I think this is an important.
feature to write tests at all. And I think it's not worth running all the tests mr or pr to make sure that you didn't forget to test some file.

what is the point of measuring the coverage of the entire project? to increase it. and this is not present now in --coverage + --changed

Suggested solution

  1. --coverage + --changes show the coverage of files that do not have tests..
  2. --coverage + --changes shows true information about coverage

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat: coverageIssues and PRs related to the coverage featurep2-to-be-discussedEnhancement under consideration (priority)

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions