-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPesterConfiguration.ps1
More file actions
147 lines (129 loc) · 4.84 KB
/
PesterConfiguration.ps1
File metadata and controls
147 lines (129 loc) · 4.84 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Pester测试框架配置脚本
.DESCRIPTION
该脚本定义了Pester测试框架的配置参数,包括测试路径、并行执行设置、
代码覆盖率分析等。配置用于自动化测试psutils模块的功能。
.EXAMPLE
.\PesterConfiguration.ps1
加载Pester测试配置
.NOTES
配置包括:
- 测试路径设置为./psutils目录
- 启用并行测试,最大4个线程
- 启用代码覆盖率分析
- 排除特定模块的覆盖率统计
- 输出格式为CoverageGutters
#>
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$excludeTags = @('Slow')
if ($IsLinux -or $IsMacOS) {
$excludeTags += 'windowsOnly'
}
$isCI = $env:CI -in @('true', '1', 'yes', 'on')
$testMode = if ([string]::IsNullOrWhiteSpace($env:PWSH_TEST_MODE)) { 'full' } else { $env:PWSH_TEST_MODE.Trim().ToLowerInvariant() }
$isQa = $testMode -eq 'qa'
$isFast = $testMode -in @('fast', 'serial', 'debug', 'qa')
$isSerial = $testMode -eq 'serial'
$isDebug = $testMode -eq 'debug'
$isVerbose = -not [string]::IsNullOrWhiteSpace($env:PWSH_TEST_VERBOSE)
$coverageOverride = if ([string]::IsNullOrWhiteSpace($env:PWSH_TEST_ENABLE_COVERAGE)) {
$null
}
else {
$env:PWSH_TEST_ENABLE_COVERAGE.Trim().ToLowerInvariant()
}
$isCoverageEnabled = if ($coverageOverride -in @('1', 'true', 'yes', 'on')) {
$true
}
elseif ($coverageOverride -in @('0', 'false', 'no', 'off')) {
$false
}
else {
-not $isFast
}
$qaDefaultPaths = @(
"./tests/DeferredLoading.Tests.ps1"
"./tests/losslessToAdaptiveAudio.Tests.ps1"
"./tests/ProfileInstallHints.Tests.ps1"
"./tests/ProfileMode.Tests.ps1"
"./psutils/tests/commandDiscovery.Tests.ps1"
"./tests/Switch-Mirrors.Tests.ps1"
"./psutils/tests/error.Tests.ps1"
"./psutils/tests/filesystem.Tests.ps1"
"./psutils/tests/font.Tests.ps1"
"./psutils/tests/git.Tests.ps1"
"./psutils/tests/string.Tests.ps1"
"./psutils/tests/win.Tests.ps1"
"./psutils/tests/wrapper.Tests.ps1"
)
$runPaths = if ($isQa) { $qaDefaultPaths } else { @("./psutils", "./tests") }
if (-not [string]::IsNullOrWhiteSpace($env:PWSH_TEST_PATH)) {
$runPaths = $env:PWSH_TEST_PATH -split '[;,]' | ForEach-Object { $_.Trim() } | Where-Object { $_ }
}
if ($isQa) {
$excludeTags += 'QaSkip'
}
$config = @{
Run = @{
Path = $runPaths
# 输出测试结果对象,因为我不需要解析结果对象,所以关掉
# PassThru = $True
PassThru = $False
# 多线程执行测试
Parallel = @{
Enabled = -not $isSerial
MaxThreads = 4
}
# 关键点:
# 本地运行 (False): 测试失败仅仅显示红色,不退出 PowerShell 进程
# CI 运行 (True): 测试失败会返回非零 ExitCode,让 GitHub Action 标记为失败
Exit = $isCI
}
# Filter 模块: 定义筛选规则
Filter = @{
ExcludeTag = $excludeTags
}
CodeCoverage = @{
# 允许通过环境变量覆盖 coverage,便于 Linux 容器在 Pester 收尾异常时退回到
# “full 断言回归但不承担 coverage”的执行模式。
Enabled = $isCoverageEnabled
Path = "./psutils/modules/*.psm1"
# 显式写回仓库当前采用的 50% 覆盖率门槛,避免继续沿用 Pester 默认 75%
# 导致控制台输出与 OpenSpec 规范长期漂移。
CoveragePercentTarget = 50
# OutputPath = "./coverge.xml"
OutputFormat = 'CoverageGutters'
ExcludeFromCodeCoverage = @(
'./psutils/modules/error.psm1'
'./psutils/modules/linux.psm1'
'./psutils/modules/network.psm1'
'./psutils/modules/proxy.psm1'
'./psutils/modules/pwsh.psm1'
)
}
Output = @{
# 使用详细输出,方便查看哪些测试被跳过了
# Verbosity = 'Detailed'
# CI 环境用详细输出方便排错,本地用 Normal 保持清爽
Verbosity = if ($isCI -or $isDebug -or $isVerbose) { 'Detailed' } else { 'Normal' }
# 支持 NO_COLOR 标准 (https://no-color.org/)
RenderMode = if (-not [string]::IsNullOrEmpty($env:NO_COLOR)) { 'Plaintext' } else { 'Auto' }
}
TestResult = @{
Enabled = $true
# 支持环境变量覆盖输出路径,用于并发 host/container 运行时避免冲突
OutputPath = if (-not [string]::IsNullOrWhiteSpace($env:PESTER_RESULT_PATH)) { $env:PESTER_RESULT_PATH } else { "testResults.xml" }
OutputFormat = 'NUnit3'
TestSuiteName = "PsUtils.Tests" ## 可选:给你的测试套件起个名字
}
TestRegistry = @{
Enabled = $false
}
}
$newConfig = New-PesterConfiguration -Hashtable $config
Write-Output $newConfig