Build/Test.ps1

Install-Module Pester -Force
$ProjectRoot = Split-Path $PSScriptRoot -Parent
$ResultsFilePath = (Join-Path -Path $ProjectRoot -ChildPath "test-results/testResults.xml")

Invoke-Pester -Path $ProjectRoot -OutputFile $ResultsFilePath -OutputFormat 'JUnitXml'

If (Test-Path $ResultsFilePath) {
    $PesterResults = Select-Xml -Path $ResultsFilePath -XPath '/testsuites/testsuite' | Select-Object -ExpandProperty Node
    if ($PesterResults.errors -ne 0 -or $PesterResults.failures -ne 0 ) {
        Write-Error -Message "Pester tests have failed or encountered errors." -ErrorAction Continue
    }
}