MathieuBuisson / PSCodeHealth

PowerShell module gathering PowerShell code quality and maintainability metrics
MIT License
123 stars 16 forks source link

Support Pester v5.0.x invocation #29

Open jfixemer opened 3 years ago

jfixemer commented 3 years ago

Before submitting a bug report, please ensure you :

Describe the Problem

Throws warnings and quite likely does not work properly with Pester v5.0 Pester v5.0 changed from command line switches, hashtables, etc. to a single Configuration nested hashtable object.

Steps To Reproduce

  1. Import-Module Pester -RequiredVersion 5.0.4
  2. Run Invoke-PSCodeHealth -Path .\src -TestsPath .\tests
  3. Error or unexpected behavior :
    WARNING: You are using Legacy parameter set that adapts Pester 5 syntax to Pester 4 syntax. This parameter set is
    deprecated, and does not work 100%. The -Strict and -PesterOption parameters are ignored, and providing advanced
    configuration to -Path (-Script), and -CodeCoverage via a hash table does not work. Please refer to
    https://github.com/pester/Pester/releases/tag/5.0.1#legacy-parameter-set for more information.
    Resolve-CoverageInfo : Could not resolve coverage path 'System.Collections.Hashtable': Cannot find path
    '...\System.Collections.Hashtable' because it does not exist.
    At C:\Program Files\WindowsPowerShell\Modules\pester\5.0.4\Pester.psm1:7149 char:5
    +     Resolve-CoverageInfo -UnresolvedCoverageInfo $unresolvedCoverageI ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Resolve-CoverageInfo

Expected behavior

PSCodeHealth should detect the Pester version and invoke the command properly.

Environment

Additional context

How has this issue affected you ? Prevents us from migrating to new version of Pester. What are you trying to accomplish ? Basic functionality advertised by the package. Providing context helps us come up with a solution that is most useful and prioritize issues.

wethreetrees commented 3 years ago

You can also provide a -TestResult to Invoke-PSCodeHealth. So run your Pester 5 tests with -PassThru and then pipe that into ConvertTo-Pester4Result. You do have to manage the currently imported version of Pester though.

Import-Module Pester -MinimumVersion 5.0.0
$configuration              = [PesterConfiguration]::Default
$configuration.Run.Path     = $TestPath
$configuration.Run.PassThru = $true
$testResult = Invoke-Pester -Configuration $configuration | ConvertTo-Pester4Result

Remove-Module Pester -Force
Import-Module Pester -MaximumVersion 4.*

Invoke-PSCodeHealth -Path $CodePath -TestsResult $testResult