Tests/Invoke-Tests.ps1
|
<#
.SYNOPSIS Runs the IntuneScopeTagManager Pester suite against the built-in mock tenant and exits non-zero on any failure. .EXAMPLE pwsh -NoProfile -File ./Tests/Invoke-Tests.ps1 .EXAMPLE pwsh -NoProfile -File ./Tests/Invoke-Tests.ps1 -Path ./Tests/Plan.Tests.ps1 -Output Normal -ResultPath ./TestResults.xml #> [CmdletBinding()] param( [string[]]$Path = @($PSScriptRoot), [ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')][string]$Output = 'Detailed', [string[]]$TagFilter, [string]$ResultPath ) $ErrorActionPreference = 'Stop' $env:POWERSHELL_TELEMETRY_OPTOUT = '1' try { Import-Module Pester -MinimumVersion 5.5.0 -ErrorAction Stop } catch { Write-Error "Pester 5.5 or later is required: $($_.Exception.Message)"; exit 2 } $cfg = New-PesterConfiguration $cfg.Run.Path = $Path $cfg.Run.PassThru = $true $cfg.Output.Verbosity = $Output if ($TagFilter) { $cfg.Filter.Tag = $TagFilter } if ($ResultPath) { $cfg.TestResult.Enabled = $true $cfg.TestResult.OutputPath = $ResultPath $cfg.TestResult.OutputFormat = 'NUnitXml' } $result = Invoke-Pester -Configuration $cfg Write-Host ('Total {0}: passed {1}, failed {2}, skipped {3}, not run {4}, failed containers {5}' -f $result.TotalCount, $result.PassedCount, $result.FailedCount, $result.SkippedCount, $result.NotRunCount, $result.FailedContainersCount) if ($result.FailedCount -gt 0 -or $result.FailedContainersCount -gt 0 -or $result.Result -ne 'Passed') { exit 1 } exit 0 |