From a2df44056dc205f20cc5e193908e53d5276487ba Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Sat, 15 Jun 2024 14:56:13 +0000 Subject: [PATCH] Enhancement (ci): Enhance test entrypoint script --- test/test.ps1 | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/test.ps1 b/test/test.ps1 index 4f234fb..24ecb41 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -1,4 +1,7 @@ +[CmdletBinding()] param ( + [Parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] [string]$Tag = '' ) $MODULE_NAME = (Get-Item $PSScriptRoot/../).Name @@ -6,29 +9,27 @@ $MODULE_DIR = "$PSScriptRoot/../src/$MODULE_NAME" $MODULE_MANIFEST = "$MODULE_DIR/$MODULE_NAME.psd1" Set-StrictMode -Version Latest -$global:PesterDebugPreference_ShowFullErrors = $true # Install Pester if needed $pester = Get-Module Pester -ListAvailable -ErrorAction SilentlyContinue $pesterMinVersion = [version]'4.0.0' $pesterMaxVersion = [version]'4.10.1' -if ( ! $pester -or ! ($pester.Version | ? { $_ -ge $pesterMinVersion -and $_ -le $pesterMaxVersion }) ) { - if ($PSVersionTable.PSVersion.Major -ge 6) { - Install-Module Pester -Force -Scope CurrentUser -MinimumVersion $pesterMinVersion -MaximumVersion $pesterMaxVersion -ErrorAction Stop - }else { - Install-Module Pester -Force -Scope CurrentUser -MinimumVersion $pesterMinVersion -MaximumVersion $pesterMaxVersion -SkipPublisherCheck -ErrorAction Stop - } +if (!$pester -or !($pester.Version | ? { $_ -ge $pesterMinVersion -and $_ -le $pesterMaxVersion })) { + Install-Module Pester -Force -Scope CurrentUser -MinimumVersion $pesterMinVersion -MaximumVersion $pesterMaxVersion -ErrorAction Stop -SkipPublisherCheck } -Get-Module Pester -ListAvailable +Get-Module Pester | Remove-Module -Force Import-Module Pester -MinimumVersion $pesterMinVersion -MaximumVersion $pesterMaxVersion -Force -ErrorAction Stop +Get-Module Pester # Test the module manifest -Test-ModuleManifest "$MODULE_MANIFEST" -ErrorAction Stop +Test-ModuleManifest "$MODULE_MANIFEST" -ErrorAction Stop > $null # Import our module Get-Module "$MODULE_NAME" | Remove-Module -Force -Import-Module $MODULE_MANIFEST -Force -ErrorAction Stop +Import-Module $MODULE_MANIFEST -Force -ErrorAction Stop -Verbose +Get-Module "$MODULE_NAME" +$global:PesterDebugPreference_ShowFullErrors = $true # For Pester 4 if ($Tag) { # Run Unit Tests $res = Invoke-Pester -Script $MODULE_DIR -Tag $Tag -PassThru -ErrorAction Stop @@ -51,7 +52,7 @@ if ($Tag) { "$( $res2.FailedCount ) integration tests failed." | Write-Host } - if (($res -and $res.FailedCount -gt 0) -or ($res2 -and $res2.FailedCount)) { + if (($res -and $res.FailedCount -gt 0) -or ($res2 -and $res2.FailedCount -gt 0)) { throw } }