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

"c8 check-coverage --all" do not works like intended #187

Closed
Oloompa opened this issue Jan 6, 2020 · 3 comments · Fixed by #188
Closed

"c8 check-coverage --all" do not works like intended #187

Oloompa opened this issue Jan 6, 2020 · 3 comments · Fixed by #188
Assignees
Labels

Comments

@Oloompa
Copy link

Oloompa commented Jan 6, 2020

Hi,

I want to both check a global coverage and a per file coverage so i need to call check-coverage separately.

If i have a file uncovered named foo.js,

calling c8 --all --include build --check-coverage works perfectly. It will fail telling me foo.js does not meet threshold.

but calling c8 --all --include build and later call c8 check-coverage --all --include build does not works. It doesn't throw an error.

@bcoe bcoe added the bug label Jan 6, 2020
@j03m
Copy link
Collaborator

j03m commented Jan 12, 2020

I think I see the problem. I wrote an integration test to simulate this use case that looks like this:

it.only('should allow for --all to be used with the check-coverage command (2 invocations)', () => {
      // generate v8 output
      let result = spawnSync(nodePath, [
        c8Path,
        '--temp-directory=tmp/all-check-coverage-as-command',
        '--clean=false',
        '--check-coverage',
        '--lines=90',
        '--all=true',
        '--include=test/fixtures/all/vanilla/**/*.js',
        '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/**
        nodePath,
        require.resolve('./fixtures/all/vanilla/main')
      ])
      console.log(result.output.toString())

      // invoke check-coverage as a command with --all
     result = spawnSync(nodePath, [
        c8Path,
        'check-coverage',
        '--lines-100',
        '--temp-directory=tmp/all-check-coverage-as-command',
        '--clean=false',
        '--all=true',
        '--include=test/fixtures/all/vanilla/**/*.js',
        '--exclude=**/*.ts' // add an exclude to avoid default excludes of test/**
      ])
      console.log(result.output.toString())
    })

The resulting output of this looks like:

--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------|---------|----------|---------|---------|-------------------
All files     |   64.29 |    66.67 |      50 |   64.29 |                   
 vanilla      |   78.26 |       75 |     100 |   78.26 |                   
  loaded.js   |   73.68 |    71.43 |     100 |   73.68 | 4,5,16-18         
  main.js     |     100 |      100 |     100 |     100 |                   
 vanilla/dir  |       0 |        0 |       0 |       0 |                   
  unloaded.js |       0 |        0 |       0 |       0 | 1-5               
--------------|---------|----------|---------|---------|-------------------
,ERROR: Coverage for lines (64.29%) does not meet global threshold (90%)

,,ERROR: Coverage for lines (78.26%) does not meet global threshold (90%)

In the 2nd run it looks like we're not taking into account the unloaded files and getting a coverage for loaded files only.

Will fix.

@j03m j03m self-assigned this Jan 12, 2020
j03m added a commit to j03m/c8 that referenced this issue Jan 12, 2020
Fixes: bcoe#187
When implementing all I neglected to supply it when building
`Report` in the `check-coverage.js` command. This commit
rectifies that and adds two test cases for `check-coverage`
as a flag and command used in conjunction with `--all` to
prevent regression.

**Snapshot updated**
@bcoe bcoe closed this as completed in #188 Jan 13, 2020
@bcoe
Copy link
Owner

bcoe commented Jan 14, 2020

@Oloompa mind trying out 7.0.1, @j03m fixed the issue 👍

@Oloompa
Copy link
Author

Oloompa commented Jan 15, 2020

Yes it works now !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants