Skip to content

Unable to pass [System.Collections.IDictionary] for .CodeCoverage.Path #2190

Open
@johlju

Description

@johlju

Checklist

What is the issue?

According to the source it should be possible to pass an [System.Collections.IDictionary] so that it is possible to only calculate code coverage on part of a source file.

if ($InputObject -is [System.Collections.IDictionary]) {

But since the Pester configuration object only takes a string array for the property CodeCoverage.Path it is not possible to use this functionality,

Expected Behavior

Possible to pass an array of [System.Collections.IDictionary] for the property CodeCoverage.Path. I think it even is supposed to be able to mix both [System.Collections.IDictionary] and [String]? 🤔

Steps To Reproduce

$coverage1 = [System.Collections.IDictionary] @{
    Path = '/Users/johlju/source/Sampler/output/Sampler/0.113.0/Sampler.psm1'
    StartLine = 1
    EndLine = 100
    Function = 'Add-Sample'
}

$pesterConfig = New-PesterConfiguration -Hashtable @{
    Run = @{
        Path = './tests/Unit/Public/Add-Sample.tests.ps1'
    }
    CodeCoverage = @{
        Enabled = $true
        Path = @($coverage1)
        UseBreakpoints = $true
    }
    Output = @{
        Verbosity = 'Detailed'
    }
}

Invoke-Pester -Configuration $pesterConfig

Since I can't get passed setting the property in the pester configuration, I'm not sure if IDictionary need more of the properties:

return [pscustomobject]@{
Path = $Path
Class = $Class
Function = $Function
StartLine = $StartLine
EndLine = $EndLine
IncludeTests = $IncludeTests
RecursePaths = $RecursePaths
}

Describe your environment

Pester version     : 5.3.3 /Users/johlju/source/Sampler/output/RequiredModules/Pester/5.3.3/Pester.psm1                 
PowerShell version : 7.2.4
OS version         : Unix 12.4.0

Possible Solution?

The Pester configuration option .CodeCoverage.Path needs to be a Tuple to be able to pass both [String] and [System.Collections.IDictionary]?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions