Skip to content

Commit 6e4779f

Browse files
🩹 [Patch]: Added verbosity to BeforeAll (#70)
## Description - Added verbosity to BeforeAll on SourceCode 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 c3b43d4 commit 6e4779f

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ jobs:
101101
| `TestType` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | |
102102
| `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | |
103103
| `TestsPath` | The path to the tests to run. | `false` | `tests` |
104-
| `Shell` | The shell to use for running the tests. | `false` | `pwsh` |
104+
| `StackTraceVerbosity` | Verbosity level of the stack trace. Allowed values: `None`, `FirstLine`, `Filtered`, `Full`. | `false` | `None` |
105+
| `Verbosity` | Verbosity level of the test output. Allowed values: `None`, `Normal`, `Detailed`, `Diagnostic`. | `false` | `Detailed` |
105106

106107
### Outputs
107108

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ inputs:
1919
description: The path to the tests to run.
2020
required: false
2121
default: tests
22+
StackTraceVerbosity:
23+
description: "Verbosity level of the stack trace. Allowed values: 'None', 'FirstLine', 'Filtered', 'Full'."
24+
required: false
25+
default: 'None'
26+
Verbosity:
27+
description: "Verbosity level of the test output. Allowed values: 'None', 'Normal', 'Detailed', 'Diagnostic'."
28+
required: false
29+
default: 'Detailed'
2230

2331
outputs:
2432
passed:
@@ -39,6 +47,8 @@ runs:
3947
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
4048
GITHUB_ACTION_INPUT_TestType: ${{ inputs.TestType }}
4149
GITHUB_ACTION_INPUT_TestsPath: ${{ inputs.TestsPath }}
50+
GITHUB_ACTION_INPUT_StackTraceVerbosity: ${{ inputs.StackTraceVerbosity }}
51+
GITHUB_ACTION_INPUT_Verbosity: ${{ inputs.Verbosity }}
4252
run: |
4353
# Test-PSModule
4454
$passed = . "${{ github.action_path }}\scripts\main.ps1" -Verbose

scripts/helpers/Test-PSModule.ps1

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#>
66
[OutputType([int])]
77
[CmdletBinding()]
8+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
9+
'PSReviewUnusedParameter', '', Scope = 'Function',
10+
Justification = 'Parameters are used in nested ScriptBlocks'
11+
)]
812
param(
913
# Path to the folder where the code to test is located.
1014
[Parameter(Mandatory)]
@@ -17,7 +21,17 @@
1721

1822
# Path to the folder where the tests are located.
1923
[Parameter()]
20-
[string] $TestsPath = 'tests'
24+
[string] $TestsPath = 'tests',
25+
26+
# Verbosity level of the stack trace.
27+
[Parameter()]
28+
[ValidateSet('None', 'FirstLine', 'Filtered', 'Full')]
29+
[string] $StackTraceVerbosity = 'None',
30+
31+
# Verbosity level of the test output.
32+
[Parameter()]
33+
[ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')]
34+
[string] $Verbosity = 'Detailed'
2135
)
2236

2337
$moduleName = Split-Path -Path $Path -Leaf
@@ -151,8 +165,8 @@
151165
}
152166
Output = @{
153167
CIFormat = 'Auto'
154-
StackTraceVerbosity = 'None'
155-
Verbosity = 'Detailed'
168+
StackTraceVerbosity = $StackTraceVerbosity
169+
Verbosity = $Verbosity
156170
}
157171
}
158172
}

scripts/main.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,40 @@ LogGroup "Loading helper scripts from [$path]" {
1111

1212
LogGroup 'Loading inputs' {
1313
$moduleName = if ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) { $env:GITHUB_REPOSITORY_NAME } else { $env:GITHUB_ACTION_INPUT_Name }
14-
Write-Verbose "Module name: [$moduleName]"
14+
Write-Verbose "Module name: [$moduleName]"
1515

1616
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "$env:GITHUB_ACTION_INPUT_Path\$moduleName"
1717
if (Test-Path -Path $codeToTest) {
18-
Write-Verbose "Code to test: [$codeToTest]"
18+
Write-Verbose "Code to test: [$codeToTest]"
1919
} else {
2020
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path
2121
}
2222

23-
Write-Verbose "Code to test: [$codeToTest]"
23+
Write-Verbose "Code to test: [$codeToTest]"
2424
if (-not (Test-Path -Path $codeToTest)) {
2525
throw "Path [$codeToTest] does not exist."
2626
}
2727
Write-Verbose "Test type to run: [$env:GITHUB_ACTION_INPUT_TestType]"
2828

2929
$testsPath = $env:GITHUB_ACTION_INPUT_TestsPath
30-
Write-Verbose "Path to tests: [$testsPath]"
30+
Write-Verbose "Path to tests: [$testsPath]"
3131
if (-not (Test-Path -Path $testsPath)) {
3232
throw "Path [$testsPath] does not exist."
3333
}
34+
35+
$StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity
36+
Write-Verbose "StackTraceVerbosity: [$StackTraceVerbosity]"
37+
$Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity
38+
Write-Verbose "Verbosity: [$Verbosity]"
39+
3440
}
3541

3642
$params = @{
37-
Path = $codeToTest
38-
TestType = $env:GITHUB_ACTION_INPUT_TestType
39-
TestsPath = $testsPath
43+
Path = $codeToTest
44+
TestType = $env:GITHUB_ACTION_INPUT_TestType
45+
TestsPath = $testsPath
46+
StackTraceVerbosity = $StackTraceVerbosity
47+
Verbosity = $Verbosity
4048
}
4149
$results = Test-PSModule @params
4250

scripts/tests/PSModule/SourceCode.Tests.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Param(
1313

1414
BeforeAll {
1515
$scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File
16+
LogGroup 'Script files:' {
17+
$scriptFiles | ForEach-Object {
18+
Write-Verbose " - $($_.FullName)" -Verbose
19+
}
20+
}
1621
$functionsPath = Join-Path -Path $Path -ChildPath 'functions'
1722
# $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private'
1823
$publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public'
@@ -22,9 +27,9 @@ BeforeAll {
2227
$functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -Filter '*.ps1' -File) : $null
2328
$publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null
2429

25-
Write-Verbose "Found $($scriptFiles.Count) script files in $Path"
26-
Write-Verbose "Found $($functionFiles.Count) function files in $Path"
27-
Write-Verbose "Found $($publicFunctionFiles.Count) public function files in $Path"
30+
Write-Verbose "Found $($scriptFiles.Count) script files in [$Path]" -Verbose
31+
Write-Verbose "Found $($functionFiles.Count) function files in [$functionsPath]" -Verbose
32+
Write-Verbose "Found $($publicFunctionFiles.Count) public function files in [$publicFunctionsPath]" -Verbose
2833
}
2934

3035
Describe 'PSModule - SourceCode tests' {

0 commit comments

Comments
 (0)