diff --git a/scripts/test.ps1 b/scripts/test.ps1 index c6a6c01..eddb855 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -1,22 +1,36 @@ -Write-Host "Starting test execution..." -ForegroundColor Magenta -Write-Host "" +$RepoRoot = Resolve-Path (Join-Path -Path $PSScriptRoot -ChildPath "..") -dotnet test +Push-Location -Path $RepoRoot +try { + Write-Host "Starting test execution..." -ForegroundColor Magenta + Write-Host "" -$TestExitCode = $LASTEXITCODE + $TestResultsPath = Join-Path -Path $RepoRoot -ChildPath "TestResults" -if ($TestExitCode -eq 0) { - Write-Host "" - Write-Host "Tests passed. Generating code coverage HTML report..." -ForegroundColor Magenta - Write-Host "" + if (Test-Path $TestResultsPath) { + Remove-Item -Path $TestResultsPath -Recurse -Force + } - reportgenerator -reports:"**/*.cobertura.xml" -targetdir:"CoverageReport" + dotnet test - Write-Host "" - Write-Host "SUCCESS: All tests passed and coverage report generated." -ForegroundColor Green -} else { - Write-Host "FAILURE: Tests failed with exit code $TestExitCode. Skipping coverage report generation." -ForegroundColor Red + $TestExitCode = $LASTEXITCODE + + if ($TestExitCode -eq 0) { + Write-Host "" + Write-Host "Tests passed. Generating code coverage HTML report..." -ForegroundColor Magenta + Write-Host "" + + reportgenerator -reports:"**/*.cobertura.xml" -targetdir:"CoverageReport" + + Write-Host "" + Write-Host "SUCCESS: All tests passed and coverage report generated." -ForegroundColor Green + } else { + Write-Host "FAILURE: Tests failed with exit code $TestExitCode. Skipping coverage report generation." -ForegroundColor Red + } +} +finally { + Pop-Location } exit $TestExitCode