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

Code Coverage page is outdated #196

Closed
2 tasks done
fflaten opened this issue Jun 10, 2022 · 12 comments
Closed
2 tasks done

Code Coverage page is outdated #196

fflaten opened this issue Jun 10, 2022 · 12 comments

Comments

@fflaten
Copy link
Collaborator

fflaten commented Jun 10, 2022

Checklist

  • Issue has a meaningful title
  • I have searched the existing issues. See issues

Link to page

https://pester.dev/docs/usage/code-coverage

What is the issue?

Docs for using code coverage is not updated for Pester 5 yet.

Examples:

  • Mentions unique PS3+ requirement
  • References Pester 3.4.0 as not supported for a feature
  • Uses hashtable-config with -CodeCoverage

Suggested fix?

Should be updated to cover Pester 5.3 status with new configuration, breakpoint vs profiler etc.

@Veretax
Copy link

Veretax commented Jul 1, 2022

Is this related to why when I run a basic code coverage of one test to one file I no longer get the missed methods listing that this page shows?

@fflaten
Copy link
Collaborator Author

fflaten commented Jul 2, 2022

Code Coverage will report functions, but the samples and parameters to configure CodeCoverage on that page isn't valid for Pester 5. Try:

CoverageTest.ps1:

function FunctionOne ([switch] $SwitchParam)
{
    if ($SwitchParam)
    {
        return 'SwitchParam was set'
    }
    else
    {
        return 'SwitchParam was not set'
    }
}

function FunctionTwo
{
    return 'I get executed'
    return 'I do not'
}

CoverageTest.Tests.ps1:

BeforeAll {
    . $PSCommandPath.Replace('.Tests.ps1','.ps1')
}

Describe 'Demonstrating Code Coverage' {
    It 'Calls FunctionOne with no switch parameter set' {
        FunctionOne | Should -Be 'SwitchParam was not set'
    }

    It 'Calls FunctionTwo' {
        FunctionTwo | Should -Be 'I get executed'
    }
}

Then invoke like this:

$c = New-PesterConfiguration
# Just hardcoding a single test path to keep it simple. Can use wildcards etc as normal
$c.Run.Path = "C:\Path\To\Tests\CoverageTest.Tests.ps1"
$c.CodeCoverage.Enabled = $true
# Just hardcoding a single test path to keep it simple. Can use wildcards etc as normal
$c.CodeCoverage.Path = "C:\Path\To\Source\CoverageTest.ps1"
# Not required, but will print the report automatically
$c.Output.Verbosity = 'Detailed'
# Not required, but will let you access the report in the result-object, see below
$c.Run.PassThru = $true

$res = Invoke-Pester -Configuration $c

# Output:

Pester v5.3.3

Starting discovery in 1 files.
Discovery found 2 tests in 4ms.
Starting code coverage.
Code Coverage preparation finished after 4 ms.
Running tests.

Running tests from 'C:\Path\To\Tests\CoverageTest.Tests.ps1'
Describing Demonstrating Code Coverage
  [+] Calls FunctionOne with no switch parameter set 12ms (1ms|10ms)
  [+] Calls FunctionTwo 2ms (1ms|1ms)
Tests completed in 58ms
Tests Passed: 2, Failed: 0, Skipped: 0 NotRun: 0
Processing code coverage result.
Code Coverage result processed in 8 ms.
Covered 60% / 75%. 5 analyzed Commands in 1 File.
Missed commands:

File             Class Function    Line Command
----             ----- --------    ---- -------
CoverageTest.ps1       FunctionOne    5 return 'SwitchParam was set'
CoverageTest.ps1       FunctionTwo   16 return 'I do not'


# Access the report as a string if you want
# $res.CodeCoverage.CoverageReport

@bravo-kernel
Copy link
Collaborator

That's awesome man 👍

@Veretax
Copy link

Veretax commented Jul 2, 2022 via email

@Veretax
Copy link

Veretax commented Jul 5, 2022

Okay, finally figured out what was happening on my end.

When I had the paths setup, I think it was looking in the wrong folders all along. I had the relative paths there, but it thought they were in C:\ by referencing the source and test folders specifically down to c drive I started getting the feedback this way.

Thank you.

@mahomedalid
Copy link
Contributor

I had a very frustrating day trying to setup code coverage, verbosity and other stuff. I volunteer to update the code coverage page, the options mentioned there are already deprecated. You could assign this to me or not, but I will create a PR soon.

@fflaten
Copy link
Collaborator Author

fflaten commented Oct 24, 2023

@mahomedalid That would be great 👏

@mahomedalid
Copy link
Contributor

@fflaten ignore the "Deprecated" section for now, I am thinking in something like this, early feedback? how much do we want to keep from the deprecated section? how much from the configuration do we want to mention, considering that if we duplicate the same information than in the config reference, we have now two places to maintain?

https://github.com/pester/docs/blob/d348c5ed308355dc4908fe8bab8f0b2bac428b67/docs/usage/code-coverage.mdx

@fflaten
Copy link
Collaborator Author

fflaten commented Oct 26, 2023

Great start! I'm not able to view it rendered on mobile, so just some quick notes:

  • Pester 5 is PSv3 minimum, not just CC
  • Duplicate introduction? First lines + Understanding... section
  • TestResult is not necessary for CC, so I would skip it in example
  • Should the steps in config example be a single code block with comments to explain why? What looks best rendered? Single line codeblocks might waste vertical space on margins.
  • We support CC without breakpoints also, so maybe remove breakpoint-reference? We'll probably have to add a section about when to use which mode later. @nohwnd knows this better than me.

how much do we want to keep from the deprecated section?

I personally like the structure it has, ex:

  • Why use code coverage?
  • Simple console sample (with output)
  • How to integrate in CI examples

The last section about analyzed commands might be nice as a <details> element or a last section "How to read the results", but we could add it later.

how much from the configuration do we want to mention, considering that if we duplicate the same information than in the config reference, we have now two places to maintain?

The parts used in the examples at least. The hidden docs in New-PesterConfiguration is just the code help which is really limited in length and formatting (bare minimum). This Code Coverage page is the "real docs" and marketing for the feature.

@mahomedalid
Copy link
Contributor

@fflaten thanks for the comments, I will submit a PR now that I have more clear structure and we can continue discussing there.

@mahomedalid
Copy link
Contributor

@fflaten #286 was created

@fflaten
Copy link
Collaborator Author

fflaten commented Nov 6, 2023

Closing as fixed by #286. 🥳
Will create new issues to track any further improvements/ideas. 🙂

@fflaten fflaten closed this as completed Nov 6, 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

4 participants