Skip to content

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

Description

@Oloompa

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.

Activity

  1. j03m commented on Jan 12, 2020

    @j03m
    Collaborator

    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.

  2. self-assigned this
    on Jan 12, 2020
  3. bcoe commented on Jan 14, 2020

    @bcoe
    Owner

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

  4. Oloompa commented on Jan 15, 2020

    @Oloompa
    Author

    Yes it works now !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions