microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
scripts/tests/pester.config.ps1
70lines · modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | # |
| 3 | # pester.config.ps1 |
| 4 | # |
| 5 | # Purpose: Pester 5.x configuration for HVE-Core PowerShell testing |
| 6 | # Author: HVE Core Team |
| 7 | # |
| 8 | |
| 9 | [CmdletBinding()] |
| 10 | param( |
| 11 | [Parameter()] |
| 12 | [switch]$CI, |
| 13 | |
| 14 | [Parameter()] |
| 15 | [switch]$CodeCoverage, |
| 16 | |
| 17 | [Parameter()] |
| 18 | [string[]]$TestPath = @("$PSScriptRoot") |
| 19 | ) |
| 20 | |
| 21 | $configuration = New-PesterConfiguration |
| 22 | |
| 23 | # Run configuration |
| 24 | $configuration.Run.Path = @($TestPath) |
| 25 | $configuration.Run.Exit = $CI.IsPresent |
| 26 | $configuration.Run.PassThru = $true |
| 27 | $configuration.Run.TestExtension = '.Tests.ps1' |
| 28 | |
| 29 | # Filter configuration |
| 30 | $configuration.Filter.ExcludeTag = @('Integration', 'Slow') |
| 31 | |
| 32 | # Output configuration |
| 33 | $configuration.Output.Verbosity = if ($CI.IsPresent) { 'Normal' } else { 'Detailed' } |
| 34 | $configuration.Output.CIFormat = if ($CI.IsPresent) { 'GithubActions' } else { 'Auto' } |
| 35 | $configuration.Output.CILogLevel = 'Error' |
| 36 | |
| 37 | # Test result configuration (NUnit XML for CI artifact upload) |
| 38 | $configuration.TestResult.Enabled = $CI.IsPresent |
| 39 | $configuration.TestResult.OutputFormat = 'NUnitXml' |
| 40 | $configuration.TestResult.OutputPath = Join-Path $PSScriptRoot '../../logs/pester-results.xml' |
| 41 | $configuration.TestResult.TestSuiteName = 'HVE-Core-PowerShell-Tests' |
| 42 | |
| 43 | # Code coverage configuration |
| 44 | if ($CodeCoverage.IsPresent) { |
| 45 | $configuration.CodeCoverage.Enabled = $true |
| 46 | $configuration.CodeCoverage.OutputFormat = 'JaCoCo' |
| 47 | $configuration.CodeCoverage.OutputPath = Join-Path $PSScriptRoot '../../logs/coverage.xml' |
| 48 | |
| 49 | # Resolve coverage paths explicitly - Join-Path with wildcards returns literal paths without file system expansion in Pester configuration |
| 50 | $scriptRoot = Split-Path $PSScriptRoot -Parent |
| 51 | $coverageDirs = @('linting', 'security', 'dev-tools', 'lib', 'extension') |
| 52 | |
| 53 | $coveragePaths = $coverageDirs | ForEach-Object { |
| 54 | Get-ChildItem -Path (Join-Path $scriptRoot $_) -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue |
| 55 | } | Where-Object { |
| 56 | $_.FullName -notmatch '\.Tests\.ps1$' |
| 57 | } | Select-Object -ExpandProperty FullName |
| 58 | |
| 59 | if ($coveragePaths.Count -gt 0) { |
| 60 | $configuration.CodeCoverage.Path = $coveragePaths |
| 61 | } |
| 62 | |
| 63 | $configuration.CodeCoverage.ExcludeTests = $true |
| 64 | $configuration.CodeCoverage.CoveragePercentTarget = 70 |
| 65 | } |
| 66 | |
| 67 | # Should configuration |
| 68 | $configuration.Should.ErrorAction = 'Stop' |
| 69 | |
| 70 | return $configuration |
| 71 | |