Skip to content

Add the integration test suite #32

Add the integration test suite

Add the integration test suite #32

Workflow file for this run

name: Unit Tests
on:
pull_request:
branches: [master, dev]
push:
branches: [master, dev]
jobs:
pester-unit-tests:
name: Pester Unit Tests
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Install Pester
shell: pwsh
run: |
if (-not (Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version -eq '5.7.1' })) {
Install-Module Pester -RequiredVersion 5.7.1 -Force -SkipPublisherCheck -Scope CurrentUser
}
Import-Module Pester -RequiredVersion 5.7.1
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
}
- name: Run static validation
shell: powershell
run: |
.\Tests\Invoke-StaticValidation.ps1 -RequirePSScriptAnalyzer
- name: Run Features.json unit tests
shell: pwsh
run: |
$result = Invoke-Pester -Path "Tests/Unit/Test-FeaturesJson.ps1" -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) test(s) failed in Test-FeaturesJson.ps1"
exit 1
}
- name: Run Apps.json unit tests
shell: pwsh
run: |
$result = Invoke-Pester -Path "Tests/Unit/Test-AppsJson.ps1" -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) test(s) failed in Test-AppsJson.ps1"
exit 1
}
- name: Run registry file unit tests
shell: pwsh
run: |
$result = Invoke-Pester -Path "Tests/Unit/Test-RegistryFiles.ps1" -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) test(s) failed in Test-RegistryFiles.ps1"
exit 1
}
- name: Run desired-state verification tests
shell: pwsh
run: |
$result = Invoke-Pester -Path "Tests/Unit/Test-DesiredStateVerification.ps1" -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) test(s) failed in Test-DesiredStateVerification.ps1"
exit 1
}
- name: Run custom feature and safety contract tests
shell: pwsh
run: |
$result = Invoke-Pester -Path @(
"Tests/Unit/Test-CustomFeatureContracts.ps1",
"Tests/Unit/Test-SafetyGuards.ps1"
) -Output Detailed -PassThru
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) custom feature or safety contract test(s) failed"
exit 1
}
- name: Run integration tests
shell: pwsh
run: |
# Hosted runners are ephemeral and elevated, so the ReadOnly and
# DryRun tags both run here. Mutating tests need Windows Sandbox,
# which hosted runners do not provide; see Tests/Integration/README.md.
$result = .\Tests\Integration\Invoke-IntegrationTests.ps1 -Ephemeral -PassThru
# A null or empty result means the suite never ran. Checking only
# FailedCount would let that pass as green.
if ($null -eq $result -or $result.TotalCount -eq 0) {
Write-Error "The integration suite did not run"
exit 1
}
Write-Host "Integration: $($result.PassedCount) passed, $($result.FailedCount) failed, $($result.SkippedCount) skipped, $($result.TotalCount) total"
if ($result.FailedCount -gt 0) {
Write-Error "$($result.FailedCount) integration test(s) failed"
exit 1
}
- name: Build and parse standalone script
shell: powershell
run: |
$outputFile = Join-Path $env:RUNNER_TEMP 'WinSwift-Standalone.ps1'
.\build.ps1 -OutputFile $outputFile
$tokens = $null
$parseErrors = $null
[System.Management.Automation.Language.Parser]::ParseFile(
$outputFile,
[ref]$tokens,
[ref]$parseErrors
) | Out-Null
if ($parseErrors.Count -gt 0) {
$parseErrors | ForEach-Object { Write-Error $_.Message }
exit 1
}
- name: Report summary
if: always()
shell: pwsh
run: |
Write-Host "Unit test run complete."