-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathpester.config.ps1
More file actions
125 lines (104 loc) · 4.63 KB
/
pester.config.ps1
File metadata and controls
125 lines (104 loc) · 4.63 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
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: MIT
#
# pester.config.ps1
#
# Purpose: Pester 5.x configuration for HVE-Core PowerShell testing
# Author: HVE Core Team
#
[CmdletBinding()]
param(
[Parameter()]
[switch]$CI,
[Parameter()]
[switch]$CodeCoverage,
[Parameter()]
[string[]]$TestPath = @("$PSScriptRoot")
)
# Dynamically discover skill test directories when using the default TestPath.
# Skills live at .github/skills/<skill>/ or .github/skills/<collection>/<skill>/
# so we probe two fixed depths.
if (-not $PSBoundParameters.ContainsKey('TestPath')) {
$scriptRoot = Split-Path $PSScriptRoot -Parent
$repoRoot = Split-Path $scriptRoot -Parent
$skillsPath = Join-Path $repoRoot '.github' 'skills'
if (Test-Path $skillsPath) {
$skillTestDirs = @()
foreach ($depth in @('*', '*/*')) {
$pattern = Join-Path $skillsPath $depth 'tests'
$skillTestDirs += @(Get-Item -Path $pattern -ErrorAction SilentlyContinue |
Where-Object { $_.PSIsContainer -and (Test-Path (Join-Path $_.Parent.FullName 'scripts')) })
}
if ($skillTestDirs) {
$TestPath = @($TestPath) + @($skillTestDirs.FullName)
}
}
}
$configuration = New-PesterConfiguration
# Run configuration
$configuration.Run.Path = @($TestPath)
$configuration.Run.Exit = $CI.IsPresent
$configuration.Run.PassThru = $true
$configuration.Run.TestExtension = '.Tests.ps1'
# Filter configuration
$configuration.Filter.ExcludeTag = @('Integration', 'Slow')
# Output configuration
$configuration.Output.Verbosity = if ($CI.IsPresent) { 'Normal' } else { 'Detailed' }
$configuration.Output.CIFormat = if ($CI.IsPresent) { 'GithubActions' } else { 'Auto' }
$configuration.Output.CILogLevel = 'Error'
# Test result configuration (NUnit XML for CI artifact upload)
$configuration.TestResult.Enabled = $CI.IsPresent
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.TestResult.OutputPath = Join-Path $PSScriptRoot '../../logs/pester-results.xml'
$configuration.TestResult.TestSuiteName = 'HVE-Core-PowerShell-Tests'
# Code coverage configuration
if ($CodeCoverage.IsPresent) {
$configuration.CodeCoverage.Enabled = $true
$configuration.CodeCoverage.OutputFormat = 'JaCoCo'
$configuration.CodeCoverage.OutputPath = Join-Path $PSScriptRoot '../../logs/coverage.xml'
# Resolve coverage paths explicitly - Join-Path with wildcards returns literal paths without file system expansion in Pester configuration
$scriptRoot = Split-Path $PSScriptRoot -Parent
$coverageDirs = @('linting', 'security', 'lib', 'extension', 'plugins', 'collections', 'tests')
$coveragePaths = $coverageDirs | ForEach-Object {
Get-ChildItem -Path (Join-Path $scriptRoot $_) -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
} | Where-Object {
$_.FullName -notmatch '\.Tests\.ps1$'
} | Select-Object -ExpandProperty FullName
# Resolve skill script coverage paths from repo root.
# Skills live at .github/skills/<skill>/ or .github/skills/<collection>/<skill>/
# so probe two fixed depths, matching test directory discovery above.
$repoRoot = Split-Path $scriptRoot -Parent
$skillsPath = Join-Path $repoRoot '.github/skills'
if (Test-Path $skillsPath) {
$skillRoots = @()
foreach ($depth in @('*', '*/*')) {
$pattern = Join-Path $skillsPath $depth 'scripts'
$skillRoots += @(Get-Item -Path $pattern -ErrorAction SilentlyContinue |
Where-Object { $_.PSIsContainer } |
ForEach-Object { $_.Parent })
}
$skillCoveragePaths = $skillRoots | ForEach-Object {
$skillRoot = $_.FullName
$skillScripts = Join-Path $skillRoot 'scripts'
$paths = @()
$paths += Get-ChildItem -Path $skillRoot -Include '*.ps1', '*.psm1' -File -ErrorAction SilentlyContinue
if (Test-Path $skillScripts) {
$paths += Get-ChildItem -Path $skillScripts -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
}
$paths
} | Where-Object { $_.FullName -notmatch '\.Tests\.ps1$' } |
Select-Object -ExpandProperty FullName
if ($skillCoveragePaths) {
$coveragePaths = @($coveragePaths) + @($skillCoveragePaths)
}
}
if ($coveragePaths.Count -gt 0) {
$configuration.CodeCoverage.Path = $coveragePaths
}
$configuration.CodeCoverage.ExcludeTests = $true
$configuration.CodeCoverage.CoveragePercentTarget = 80
}
# Should configuration
$configuration.Should.ErrorAction = 'Stop'
return $configuration