Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 1334134

Browse files
LarsLars
authored andcommitted
Quiet versus show Pester parameter fix
- Avoid using extra call to get-module for performance reasons. - Fix for quiet versus show Pester parameter when -TestFilePath parameter is used with OVF.
1 parent 4756bec commit 1334134

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

OperationValidation/Public/Invoke-OperationValidation.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ function Invoke-OperationValidation
170170

171171
BEGIN
172172
{
173-
if ( -not (Get-Module -Name Pester))
173+
$pesterMod = Get-Module -Name Pester
174+
if ( -not $pesterMod)
174175
{
175176
if ( Get-Module -Name Pester -ListAvailable)
176177
{
177-
Import-Module -Name Pester -Verbose:$false
178+
$pesterMod = Import-Module -Name Pester -Verbose:$false -PassThru
178179
}
179180
else
180181
{
@@ -259,7 +260,6 @@ function Invoke-OperationValidation
259260
}
260261

261262
# Pester 4.0.0 deprecated the 'Quiet' parameter in favor of 'Show'
262-
$pesterMod = Get-Module -Name Pester
263263
if ($pesterMod.Version -ge '4.0.0')
264264
{
265265
if ($IncludePesterOutput)
@@ -323,10 +323,32 @@ function Invoke-OperationValidation
323323

324324
if ($TestFilePath)
325325
{
326+
$pesterParams = @{
327+
PassThru = $true
328+
Verbose = $false
329+
}
330+
331+
# Pester 4.0.0 deprecated the 'Quiet' parameter in favor of 'Show'
332+
if ($pesterMod.Version -ge '4.0.0')
333+
{
334+
if ($IncludePesterOutput)
335+
{
336+
$pesterParams.Show = 'All'
337+
}
338+
else
339+
{
340+
$pesterParams.Show = 'None'
341+
}
342+
}
343+
else
344+
{
345+
$pesterParams.Quiet = !$IncludePesterOutput
346+
}
347+
326348
foreach($filePath in $TestFilePath) {
327349
write-progress -Activity "Invoking tests in $filePath"
328350
if ( $PSCmdlet.ShouldProcess($filePath)) {
329-
$testResult = Invoke-Pester $filePath -passthru -quiet:$quiet
351+
$testResult = Invoke-Pester $filePath @pesterParams
330352
Add-Member -InputObject $testResult -MemberType NoteProperty -Name Path -Value $filePath
331353
Convert-TestResult -Result $testResult
332354
}

0 commit comments

Comments
 (0)