Skip to content

Commit

Permalink
Modify Run-PesterTests.ps1 to run all tests regardless of the test su…
Browse files Browse the repository at this point in the history
…bdirectory they are in.
  • Loading branch information
jonnybottles committed Dec 4, 2024
1 parent 791b1da commit 13feedd
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Hawk/tests/Run-PesterTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Load Pester module if not already loaded
Import-Module -Name Pester -ErrorAction Stop

# Log function for consistent output
function Log {
param(
[string]$Message,
[string]$Level = "Info"
)
$timestamp = Get-Date -Format "HH:mm:ss"
Write-Output "[$timestamp][$Level] $Message"
}

# Start of test execution
Log "Starting Tests"

# Define the tests directory
$testDirectory = "$PSScriptRoot"

# Get all test files in the directory, excluding specific ones
$testFiles = Get-ChildItem -Path $testDirectory -Recurse -Include *.Tests.ps1 |
Where-Object { $_.Name -notin @('pester.ps1', 'Run-PesterTests.ps1') }

# Ensure we found test files
if (-not $testFiles) {
Log "No test files found to execute." "Error"
exit 1
}

# Loop through each test file
foreach ($testFile in $testFiles) {
Log "Executing $($testFile.FullName)" "Info"
try {
# Run tests with minimal output
Invoke-Pester -Path $testFile.FullName -Output Minimal -PassThru | Out-Null
} catch {
Log "Error running $($testFile.FullName): $_" "Error"
}
}

Log "All tests executed successfully!" "Success"

0 comments on commit 13feedd

Please sign in to comment.