<# .SYNOPSIS Runs unit tests (and optionally the WebUI typecheck + lint and the integration tests). .EXAMPLE ./scripts/Test.ps1 ./scripts/Test.ps1 -IncludeIntegration -IncludeWebUI #> [CmdletBinding()] param( [ValidateSet('Debug', 'Release')] [string]$Configuration = 'Release', [string]$Version, [switch]$IncludeIntegration, [switch]$IncludeWebUI, # deploy.sh's database decisions (scripts/tests/Test-DeployDatabase.sh); needs bash (Git Bash on Windows). [switch]$IncludeDeploy ) $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $PSScriptRoot $Version = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version $unitProjects = @( 'tests/Shared.Tests', 'tests/Agent.Tests', 'tests/Agent.Watchdog.Tests', 'tests/Backend.Tests' ) foreach ($project in $unitProjects) { dotnet test (Join-Path $repoRoot $project) -c $Configuration --nologo "-p:UnifiedVersion=$Version" if ($LASTEXITCODE -ne 0) { throw "Tests failed in $project ($LASTEXITCODE)." } } if ($IncludeIntegration) { dotnet test (Join-Path $repoRoot 'tests/Integration.Tests') -c $Configuration --nologo "-p:UnifiedVersion=$Version" if ($LASTEXITCODE -ne 0) { throw "Integration tests failed ($LASTEXITCODE)." } } if ($IncludeWebUI) { Push-Location (Join-Path $repoRoot 'src/WebUI') try { if (-not (Test-Path 'node_modules')) { npm ci if ($LASTEXITCODE -ne 0) { throw "npm ci failed ($LASTEXITCODE)." } } npm run check if ($LASTEXITCODE -ne 0) { throw "WebUI check (typecheck + lint) failed ($LASTEXITCODE)." } } finally { Pop-Location } } if ($IncludeDeploy) { # Git Bash first on Windows: System32's bash.exe is WSL's, which cannot take a Windows path. $gitBash = if ($IsWindows) { Join-Path $env:ProgramFiles 'Git/bin/bash.exe' } else { $null } $bash = if ($gitBash -and (Test-Path $gitBash)) { Get-Command $gitBash } else { Get-Command bash -ErrorAction SilentlyContinue } if (-not $bash) { throw 'bash is needed for -IncludeDeploy (Git Bash on Windows).' } & $bash.Source (Join-Path $repoRoot 'scripts/tests/Test-DeployDatabase.sh') if ($LASTEXITCODE -ne 0) { throw "Deploy database tests failed ($LASTEXITCODE)." } } Write-Host 'All requested test suites passed.'