Skip to content

Commit 3fa68e2

Browse files
🩹 [Patch]: Include debug and verbose preference parameters into the testing suites (#81)
## Description This pull request introduces changes to improve the verbosity and debugging capabilities of the PowerShell module tests. The most important changes include updating verbosity and debug preferences, modifying the default verbosity level, and enhancing the module import process. ### Verbosity and Debug Preferences: * [`.github/workflows/Action-Test-Src-Default.yml`](diffhunk://#diff-8ecb4765631346daa3fc827a56e509b7e8c1db0fc5ce7e3736bfea19531c0779R37-R38): Added `DebugPreference` and `VerbosePreference` settings to the `PSModuleTest` job. * [`scripts/helpers/Test-PSModule.ps1`](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L62-R63): Updated multiple instances to use `VerbosePreference` and `DebugPreference` from environment variables instead of hardcoded values. [[1]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L62-R63) [[2]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L75-R77) [[3]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L89-R92) [[4]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L105-R109) [[5]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76R123-R124) [[6]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L176-R193) ### Default Verbosity Level: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L25-R25): Changed the default verbosity level of the stack trace from 'Filtered' to 'Full'. ### Module Import Process: * [`scripts/helpers/Test-PSModule.ps1`](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L137-R146): Enhanced the module import process to remove existing modules and their dependencies more thoroughly before importing the test module. These changes collectively improve the control over verbosity and debugging during test execution, and ensure a cleaner module import process. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 5575596 commit 3fa68e2

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

.github/workflows/Action-Test-Src-Default.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
Name: PSModuleTest
3535
Path: tests/src
3636
TestType: SourceCode
37+
DebugPreference: 'Continue'
38+
VerbosePreference: 'Continue'
3739

3840
- name: Status
3941
shell: pwsh

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inputs:
2222
StackTraceVerbosity:
2323
description: "Verbosity level of the stack trace. Allowed values: 'None', 'FirstLine', 'Filtered', 'Full'."
2424
required: false
25-
default: 'Filtered'
25+
default: 'Full'
2626
Verbosity:
2727
description: "Verbosity level of the test output. Allowed values: 'None', 'Normal', 'Detailed', 'Diagnostic'."
2828
required: false

scripts/helpers/Test-PSModule.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
Data = @{
6060
Path = $Path
6161
SettingsFilePath = $settingsFilePath
62-
Verbose = $true
62+
Verbose = $env:GITHUB_ACTION_INPUT_VerbosePreference -eq 'Continue'
63+
Debug = $env:GITHUB_ACTION_INPUT_DebugPreference -eq 'Continue'
6364
}
6465
}
6566
Write-Verbose 'ContainerParams:'
@@ -72,7 +73,8 @@
7273
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1'
7374
Data = @{
7475
Path = $Path
75-
Verbose = $true
76+
Verbose = $env:GITHUB_ACTION_INPUT_VerbosePreference -eq 'Continue'
77+
Debug = $env:GITHUB_ACTION_INPUT_DebugPreference -eq 'Continue'
7678
}
7779
}
7880
Write-Verbose 'ContainerParams:'
@@ -86,7 +88,8 @@
8688
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1'
8789
Data = @{
8890
Path = $Path
89-
Verbose = $true
91+
Verbose = $env:GITHUB_ACTION_INPUT_VerbosePreference -eq 'Continue'
92+
Debug = $env:GITHUB_ACTION_INPUT_DebugPreference -eq 'Continue'
9093
}
9194
}
9295
Write-Verbose 'ContainerParams:'
@@ -102,7 +105,8 @@
102105
Data = @{
103106
Path = $Path
104107
TestsPath = $moduleTestsPath
105-
Verbose = $true
108+
Verbose = $env:GITHUB_ACTION_INPUT_VerbosePreference -eq 'Continue'
109+
Debug = $env:GITHUB_ACTION_INPUT_DebugPreference -eq 'Continue'
106110
}
107111
}
108112
Write-Verbose 'ContainerParams:'
@@ -115,7 +119,9 @@
115119
if (Test-Path -Path $moduleTestsPath) {
116120
LogGroup "Add test - Module - $moduleName" {
117121
$containerParams = @{
118-
Path = $moduleTestsPath
122+
Path = $moduleTestsPath
123+
Verbose = $env:GITHUB_ACTION_INPUT_VerbosePreference -eq 'Continue'
124+
Debug = $env:GITHUB_ACTION_INPUT_DebugPreference -eq 'Continue'
119125
}
120126
Write-Verbose 'ContainerParams:'
121127
Write-Verbose "$($containerParams | ConvertTo-Json)"
@@ -134,7 +140,10 @@
134140

135141
LogGroup "Importing module: $moduleName" {
136142
Add-PSModulePath -Path (Split-Path $Path -Parent)
137-
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force
143+
$existingModule = Get-Module -Name $ModuleName -ListAvailable
144+
$existingModule | Remove-Module -Force -Verbose
145+
$existingModule.RequiredModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue }
146+
$existingModule.NestedModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue }
138147
Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global
139148
}
140149
}
@@ -147,6 +156,9 @@
147156
Container = $containers
148157
PassThru = $true
149158
}
159+
Debug = @{
160+
WriteDebugMessages = $env:GITHUB_ACTION_INPUT_DebugPreference = 'Continue'
161+
}
150162
TestResult = @{
151163
Enabled = $testModule
152164
OutputFormat = 'NUnitXml'
@@ -173,9 +185,12 @@
173185

174186
#region Run tests
175187
$verbosepref = $VerbosePreference
176-
$VerbosePreference = 'SilentlyContinue'
188+
$debugpref = $DebugPreference
189+
$VerbosePreference = $env:GITHUB_ACTION_INPUT_VerbosePreference
190+
$DebugPreference = $env:GITHUB_ACTION_INPUT_DebugPreference
177191
$results = Invoke-Pester @pesterParams
178192
$VerbosePreference = $verbosepref
193+
$DebugPreference = $debugpref
179194
#endregion
180195

181196
$results

0 commit comments

Comments
 (0)