Skip to content

Commit c207858

Browse files
🩹 [Patch]: Add debug and verbose logging for module import in test (#99)
## Description This pull request introduces several changes to improve logging, enhance test configuration, and streamline code readability in the PowerShell module and its associated tests. Key updates include adding code coverage settings. ### Logging Improvements * Replaced all occurrences of `Write-Verbose` with `Write-Debug` in `tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1`. ### Test Configuration Enhancements * ⚠️ Added a `CodeCoverage` section with `Enabled = $true` in `scripts/tests/Module/Module.Configuration.ps1` to enable code coverage reporting during tests. ## 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 d6bc94d commit c207858

File tree

6 files changed

+55
-48
lines changed

6 files changed

+55
-48
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ runs:
291291
WorkingDirectory: ${{ inputs.WorkingDirectory }}
292292
with:
293293
Debug: ${{ inputs.Debug }}
294-
Prerelease: ${{ inputs.Prerelease }}
295294
Verbose: ${{ inputs.Verbose }}
296295
Version: ${{ inputs.Version }}
296+
Prerelease: ${{ inputs.Prerelease }}
297297
WorkingDirectory: ${{ inputs.WorkingDirectory }}
298298
Path: ${{ steps.paths.outputs.TestPath }}
299299
StepSummary_Mode: ${{ inputs.StepSummary_Mode }}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@{
2-
TestResult = @{
2+
TestResult = @{
33
Enabled = $true
44
}
5-
Output = @{
5+
CodeCoverage = @{
6+
Enabled = $true
7+
}
8+
Output = @{
69
Verbosity = 'Detailed'
710
}
811
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@{
22
Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName
33
Data = @{
4-
Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path
5-
Debug = $false
6-
Verbose = $false
4+
Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path
75
}
86
}

scripts/tests/Module/PSModule/PSModule.Tests.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
'PSReviewUnusedParameter', 'Path',
33
Justification = 'Path is used to specify the path to the module to test.'
44
)]
5+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
6+
'PSAvoidUsingWriteHost', '',
7+
Justification = 'Log outputs to GitHub Actions logs.'
8+
)]
59
[CmdLetBinding()]
610
Param(
711
[Parameter(Mandatory)]
@@ -23,14 +27,18 @@ Describe 'PSModule - Module tests' {
2327

2428
Context 'Module Manifest' {
2529
It 'Module Manifest exists' {
26-
$result = Test-Path -Path $moduleManifestPath
27-
$result | Should -Be $true
28-
Write-Verbose $result
30+
LogGroup 'Module manifest' {
31+
$result = Test-Path -Path $moduleManifestPath
32+
$result | Should -Be $true
33+
Write-Host "$($result | Format-List | Out-String)"
34+
}
2935
}
3036
It 'Module Manifest is valid' {
31-
$result = Test-ModuleManifest -Path $moduleManifestPath
32-
$result | Should -Not -Be $null
33-
Write-Verbose $result
37+
LogGroup 'Validating Module Manifest' {
38+
$result = Test-ModuleManifest -Path $moduleManifestPath
39+
$result | Should -Not -Be $null
40+
Write-Host "$($result | Format-List | Out-String)"
41+
}
3442
}
3543
# It 'has a valid license URL' {}
3644
# It 'has a valid project URL' {}

scripts/tests/SourceCode/PSModule/PSModule.Container.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
Data = @{
44
Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path
55
TestsPath = $env:LocalTestPath
6-
Debug = $false
7-
Verbose = $false
86
}
97
}

tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
param()
44

55
$scriptName = $MyInvocation.MyCommand.Name
6-
Write-Verbose "[$scriptName] Importing module"
6+
Write-Debug "[$scriptName] Importing module"
77

88
#region - Data import
9-
Write-Verbose "[$scriptName] - [data] - Processing folder"
9+
Write-Debug "[$scriptName] - [data] - Processing folder"
1010
$dataFolder = (Join-Path $PSScriptRoot 'data')
11-
Write-Verbose "[$scriptName] - [data] - [$dataFolder]"
11+
Write-Debug "[$scriptName] - [data] - [$dataFolder]"
1212
Get-ChildItem -Path "$dataFolder" -Recurse -Force -Include '*.psd1' -ErrorAction SilentlyContinue | ForEach-Object {
13-
Write-Verbose "[$scriptName] - [data] - [$($_.Name)] - Importing"
13+
Write-Debug "[$scriptName] - [data] - [$($_.Name)] - Importing"
1414
New-Variable -Name $_.BaseName -Value (Import-PowerShellDataFile -Path $_.FullName) -Force
15-
Write-Verbose "[$scriptName] - [data] - [$($_.Name)] - Done"
15+
Write-Debug "[$scriptName] - [data] - [$($_.Name)] - Done"
1616
}
1717

18-
Write-Verbose "[$scriptName] - [data] - Done"
18+
Write-Debug "[$scriptName] - [data] - Done"
1919
#endregion - Data import
2020

2121
#region - From /init
22-
Write-Verbose "[$scriptName] - [/init] - Processing folder"
22+
Write-Debug "[$scriptName] - [/init] - Processing folder"
2323

2424
#region - From /init/initializer.ps1
25-
Write-Verbose "[$scriptName] - [/init/initializer.ps1] - Importing"
25+
Write-Debug "[$scriptName] - [/init/initializer.ps1] - Importing"
2626

2727
Write-Verbose '-------------------------------'
2828
Write-Verbose '--- THIS IS AN INITIALIZER ---'
2929
Write-Verbose '-------------------------------'
3030

31-
Write-Verbose "[$scriptName] - [/init/initializer.ps1] - Done"
31+
Write-Debug "[$scriptName] - [/init/initializer.ps1] - Done"
3232
#endregion - From /init/initializer.ps1
3333

34-
Write-Verbose "[$scriptName] - [/init] - Done"
34+
Write-Debug "[$scriptName] - [/init] - Done"
3535
#endregion - From /init
3636

3737
#region - From /classes
38-
Write-Verbose "[$scriptName] - [/classes] - Processing folder"
38+
Write-Debug "[$scriptName] - [/classes] - Processing folder"
3939

4040
#region - From /classes/Book.ps1
41-
Write-Verbose "[$scriptName] - [/classes/Book.ps1] - Importing"
41+
Write-Debug "[$scriptName] - [/classes/Book.ps1] - Importing"
4242

4343
class Book {
4444
# Class properties
@@ -86,10 +86,10 @@ class Book {
8686
}
8787
}
8888

89-
Write-Verbose "[$scriptName] - [/classes/Book.ps1] - Done"
89+
Write-Debug "[$scriptName] - [/classes/Book.ps1] - Done"
9090
#endregion - From /classes/Book.ps1
9191
#region - From /classes/BookList.ps1
92-
Write-Verbose "[$scriptName] - [/classes/BookList.ps1] - Importing"
92+
Write-Debug "[$scriptName] - [/classes/BookList.ps1] - Importing"
9393

9494
class BookList {
9595
# Static property to hold the list of books
@@ -178,17 +178,17 @@ class BookList {
178178
}
179179
}
180180

181-
Write-Verbose "[$scriptName] - [/classes/BookList.ps1] - Done"
181+
Write-Debug "[$scriptName] - [/classes/BookList.ps1] - Done"
182182
#endregion - From /classes/BookList.ps1
183183

184-
Write-Verbose "[$scriptName] - [/classes] - Done"
184+
Write-Debug "[$scriptName] - [/classes] - Done"
185185
#endregion - From /classes
186186

187187
#region - From /private
188-
Write-Verbose "[$scriptName] - [/private] - Processing folder"
188+
Write-Debug "[$scriptName] - [/private] - Processing folder"
189189

190190
#region - From /private/Get-InternalPSModule.ps1
191-
Write-Verbose "[$scriptName] - [/private/Get-InternalPSModule.ps1] - Importing"
191+
Write-Debug "[$scriptName] - [/private/Get-InternalPSModule.ps1] - Importing"
192192

193193
Function Get-InternalPSModule {
194194
<#
@@ -209,10 +209,10 @@ Function Get-InternalPSModule {
209209
Write-Output "Hello, $Name!"
210210
}
211211

212-
Write-Verbose "[$scriptName] - [/private/Get-InternalPSModule.ps1] - Done"
212+
Write-Debug "[$scriptName] - [/private/Get-InternalPSModule.ps1] - Done"
213213
#endregion - From /private/Get-InternalPSModule.ps1
214214
#region - From /private/Set-InternalPSModule.ps1
215-
Write-Verbose "[$scriptName] - [/private/Set-InternalPSModule.ps1] - Importing"
215+
Write-Debug "[$scriptName] - [/private/Set-InternalPSModule.ps1] - Importing"
216216

217217
Function Set-InternalPSModule {
218218
<#
@@ -237,17 +237,17 @@ Function Set-InternalPSModule {
237237
Write-Output "Hello, $Name!"
238238
}
239239

240-
Write-Verbose "[$scriptName] - [/private/Set-InternalPSModule.ps1] - Done"
240+
Write-Debug "[$scriptName] - [/private/Set-InternalPSModule.ps1] - Done"
241241
#endregion - From /private/Set-InternalPSModule.ps1
242242

243-
Write-Verbose "[$scriptName] - [/private] - Done"
243+
Write-Debug "[$scriptName] - [/private] - Done"
244244
#endregion - From /private
245245

246246
#region - From /public
247-
Write-Verbose "[$scriptName] - [/public] - Processing folder"
247+
Write-Debug "[$scriptName] - [/public] - Processing folder"
248248

249249
#region - From /public/Get-PSModuleTest.ps1
250-
Write-Verbose "[$scriptName] - [/public/Get-PSModuleTest.ps1] - Importing"
250+
Write-Debug "[$scriptName] - [/public/Get-PSModuleTest.ps1] - Importing"
251251

252252
#Requires -Modules Utilities
253253

@@ -272,10 +272,10 @@ function Get-PSModuleTest {
272272
Write-Output "Hello, $Name!"
273273
}
274274

275-
Write-Verbose "[$scriptName] - [/public/Get-PSModuleTest.ps1] - Done"
275+
Write-Debug "[$scriptName] - [/public/Get-PSModuleTest.ps1] - Done"
276276
#endregion - From /public/Get-PSModuleTest.ps1
277277
#region - From /public/New-PSModuleTest.ps1
278-
Write-Verbose "[$scriptName] - [/public/New-PSModuleTest.ps1] - Importing"
278+
Write-Debug "[$scriptName] - [/public/New-PSModuleTest.ps1] - Importing"
279279

280280
#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'}
281281

@@ -304,10 +304,10 @@ function New-PSModuleTest {
304304
Write-Output "Hello, $Name!"
305305
}
306306

307-
Write-Verbose "[$scriptName] - [/public/New-PSModuleTest.ps1] - Done"
307+
Write-Debug "[$scriptName] - [/public/New-PSModuleTest.ps1] - Done"
308308
#endregion - From /public/New-PSModuleTest.ps1
309309
#region - From /public/Set-PSModuleTest.ps1
310-
Write-Verbose "[$scriptName] - [/public/Set-PSModuleTest.ps1] - Importing"
310+
Write-Debug "[$scriptName] - [/public/Set-PSModuleTest.ps1] - Importing"
311311

312312
function Set-PSModuleTest {
313313
<#
@@ -336,10 +336,10 @@ function Set-PSModuleTest {
336336
}
337337
}
338338

339-
Write-Verbose "[$scriptName] - [/public/Set-PSModuleTest.ps1] - Done"
339+
Write-Debug "[$scriptName] - [/public/Set-PSModuleTest.ps1] - Done"
340340
#endregion - From /public/Set-PSModuleTest.ps1
341341
#region - From /public/Test-PSModuleTest.ps1
342-
Write-Verbose "[$scriptName] - [/public/Test-PSModuleTest.ps1] - Importing"
342+
Write-Debug "[$scriptName] - [/public/Test-PSModuleTest.ps1] - Importing"
343343

344344
function Test-PSModuleTest {
345345
<#
@@ -362,19 +362,19 @@ function Test-PSModuleTest {
362362
Write-Output "Hello, $Name!"
363363
}
364364

365-
Write-Verbose "[$scriptName] - [/public/Test-PSModuleTest.ps1] - Done"
365+
Write-Debug "[$scriptName] - [/public/Test-PSModuleTest.ps1] - Done"
366366
#endregion - From /public/Test-PSModuleTest.ps1
367367

368-
Write-Verbose "[$scriptName] - [/public] - Done"
368+
Write-Debug "[$scriptName] - [/public] - Done"
369369
#endregion - From /public
370370

371371
#region - From /finally.ps1
372-
Write-Verbose "[$scriptName] - [/finally.ps1] - Importing"
372+
Write-Debug "[$scriptName] - [/finally.ps1] - Importing"
373373

374374
Write-Verbose '------------------------------'
375375
Write-Verbose '--- THIS IS A LAST LOADER ---'
376376
Write-Verbose '------------------------------'
377-
Write-Verbose "[$scriptName] - [/finally.ps1] - Done"
377+
Write-Debug "[$scriptName] - [/finally.ps1] - Done"
378378
#endregion - From /finally.ps1
379379

380380
$exports = @{

0 commit comments

Comments
 (0)