-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-test.ps1
More file actions
104 lines (82 loc) · 2.62 KB
/
Copy pathdev-test.ps1
File metadata and controls
104 lines (82 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<#
.SYNOPSIS
Runs the PowerStub test suite using Pester.
.DESCRIPTION
This script runs all Pester tests for the PowerStub module. It automatically
reloads the module before running tests to ensure the latest code is tested.
.PARAMETER Filter
Run only tests matching this filter pattern (passed to Pester's -FullNameFilter).
.PARAMETER Tag
Run only tests with these tags.
.PARAMETER Output
Pester output verbosity: None, Normal, Detailed, Diagnostic. Default: Detailed.
.PARAMETER PassThru
Returns the Pester result object for programmatic inspection.
.PARAMETER SkipReload
Skip reloading the module before running tests.
.EXAMPLE
.\dev-test.ps1
# Runs all tests with detailed output
.EXAMPLE
.\dev-test.ps1 -Filter "*Alpha*"
# Runs only tests with "Alpha" in the name
.EXAMPLE
.\dev-test.ps1 -Output Normal
# Runs tests with minimal output
.EXAMPLE
.\dev-test.ps1 -SkipReload
# Runs tests without reloading the module first
#>
param(
[string]$Filter,
[string[]]$Tag,
[ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')]
[string]$Output = 'Detailed',
[switch]$PassThru,
[switch]$SkipReload
)
$ErrorActionPreference = 'Stop'
# Check for Pester
$pester = Get-Module -ListAvailable -Name Pester | Sort-Object Version -Descending | Select-Object -First 1
if (-not $pester) {
Write-Error "Pester is not installed. Install it with: Install-Module Pester -Force -SkipPublisherCheck"
return
}
if ($pester.Version.Major -lt 5) {
Write-Warning "Pester version $($pester.Version) detected. Tests require Pester 5.x or later."
Write-Warning "Update with: Install-Module Pester -Force -SkipPublisherCheck"
}
# Reload module unless skipped
if (-not $SkipReload) {
Write-Host "Reloading module before tests..." -ForegroundColor Cyan
& "$PSScriptRoot\dev-reload.ps1"
Write-Host ""
}
# Build Pester configuration
$config = New-PesterConfiguration
$config.Run.Path = Join-Path $PSScriptRoot 'tests'
$config.Output.Verbosity = $Output
if ($Filter) {
$config.Filter.FullName = $Filter
}
if ($Tag) {
$config.Filter.Tag = $Tag
}
# Always enable PassThru so $result is populated for exit code checking
$config.Run.PassThru = $true
# Run tests
Write-Host "Running Pester tests..." -ForegroundColor Cyan
Write-Host " Test path: $($config.Run.Path.Value)" -ForegroundColor Gray
if ($Filter) {
Write-Host " Filter: $Filter" -ForegroundColor Gray
}
Write-Host ""
$result = Invoke-Pester -Configuration $config
# Return result if PassThru
if ($PassThru) {
return $result
}
# Exit with appropriate code for CI
if ($result.FailedCount -gt 0) {
exit 1
}