-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathInvoke-Tests.ps1
More file actions
152 lines (127 loc) · 5.09 KB
/
Invoke-Tests.ps1
File metadata and controls
152 lines (127 loc) · 5.09 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<#
.SYNOPSIS
Unified test runner for PSZoom module.
.DESCRIPTION
Runs Pester tests for the PSZoom module. Supports unit tests, integration tests,
contract tests, or all tests. Works both locally and in CI environments.
.PARAMETER TestType
Type of tests to run: Unit, Integration, Contract, or All.
Default: Unit
.PARAMETER NoCoverage
Skip code coverage collection. Speeds up test runs.
.PARAMETER OutputPath
Directory for test results. Default: ./Tests
.PARAMETER PassThru
Return the Pester result object.
.EXAMPLE
./Invoke-Tests.ps1
Runs unit tests with code coverage.
.EXAMPLE
./Invoke-Tests.ps1 -TestType All -NoCoverage
Runs all tests without code coverage.
.EXAMPLE
./Invoke-Tests.ps1 -TestType Integration
Runs integration tests (requires Zoom API credentials).
#>
[CmdletBinding()]
param(
[Parameter()]
[ValidateSet('Unit', 'Integration', 'Contract', 'All')]
[string]$TestType = 'Unit',
[Parameter()]
[switch]$NoCoverage,
[Parameter()]
[string]$OutputPath = './Tests',
[Parameter()]
[switch]$PassThru
)
$ErrorActionPreference = 'Stop'
$ProjectRoot = $PSScriptRoot
# Ensure Pester 5+ is available
$pester = Get-Module -Name Pester -ListAvailable | Where-Object { $_.Version.Major -ge 5 } | Select-Object -First 1
if (-not $pester) {
Write-Error "Pester 5+ is required. Install with: Install-Module -Name Pester -MinimumVersion 5.0.0 -Force"
exit 1
}
Import-Module Pester -MinimumVersion 5.0.0 -Force
# Build configuration based on test type
$config = New-PesterConfiguration
$config.Output.Verbosity = 'Detailed'
$config.Should.ErrorAction = 'Continue'
$config.Run.PassThru = $true
switch ($TestType) {
'Unit' {
Write-Host "`n=== Running Unit Tests ===" -ForegroundColor Cyan
$config.Run.Path = "$ProjectRoot/Tests"
$config.Filter.ExcludeTag = @('Integration', 'Contract')
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = "$OutputPath/testResults.xml"
if (-not $NoCoverage) {
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = @(
"$ProjectRoot/PSZoom/Public/**/*.ps1"
"$ProjectRoot/PSZoom/Private/**/*.ps1"
)
$config.CodeCoverage.OutputFormat = 'JaCoCo'
$config.CodeCoverage.OutputPath = "$OutputPath/coverage.xml"
$config.CodeCoverage.CoveragePercentTarget = 80
}
}
'Integration' {
Write-Host "`n=== Running Integration Tests ===" -ForegroundColor Cyan
# Check for credentials
if (-not $env:ZOOM_ACCOUNT_ID -or -not $env:ZOOM_CLIENT_ID -or -not $env:ZOOM_CLIENT_SECRET) {
Write-Warning "Zoom API credentials not configured. Set ZOOM_ACCOUNT_ID, ZOOM_CLIENT_ID, and ZOOM_CLIENT_SECRET environment variables."
Write-Warning "Skipping integration tests."
exit 0
}
$config.Run.Path = "$ProjectRoot/Tests/Integration"
$config.Filter.Tag = @('Integration')
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = "$OutputPath/integrationTestResults.xml"
}
'Contract' {
Write-Host "`n=== Running Contract Tests ===" -ForegroundColor Cyan
$config.Run.Path = "$ProjectRoot/Tests/Contract"
$config.Filter.Tag = @('Contract')
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = "$OutputPath/contractTestResults.xml"
}
'All' {
Write-Host "`n=== Running All Tests ===" -ForegroundColor Cyan
$config.Run.Path = "$ProjectRoot/Tests"
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = "$OutputPath/allTestResults.xml"
if (-not $NoCoverage) {
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = @(
"$ProjectRoot/PSZoom/Public/**/*.ps1"
"$ProjectRoot/PSZoom/Private/**/*.ps1"
)
$config.CodeCoverage.OutputFormat = 'JaCoCo'
$config.CodeCoverage.OutputPath = "$OutputPath/coverage.xml"
$config.CodeCoverage.CoveragePercentTarget = 80
}
}
}
# Run tests
$results = Invoke-Pester -Configuration $config
# Output summary
Write-Host "`n=== Test Summary ===" -ForegroundColor Cyan
Write-Host "Tests Run: $($results.TotalCount)"
Write-Host "Passed: $($results.PassedCount)" -ForegroundColor Green
Write-Host "Failed: $($results.FailedCount)" -ForegroundColor $(if ($results.FailedCount -gt 0) { 'Red' } else { 'Green' })
Write-Host "Skipped: $($results.SkippedCount)" -ForegroundColor Yellow
if ($results.CodeCoverage) {
$coverage = [math]::Round(($results.CodeCoverage.CoveragePercent), 2)
Write-Host "Code Coverage: $coverage%" -ForegroundColor $(if ($coverage -ge 80) { 'Green' } else { 'Yellow' })
}
# Return results or exit with appropriate code
if ($PassThru) {
return $results
}
exit $results.FailedCount