Skip to content

Commit

Permalink
Merge pull request #158 from theohbrothers/test/entrypoint-improve-te…
Browse files Browse the repository at this point in the history
…st-entrypoint-script-1

Test (entrypoint): Improve test entrypoint script
  • Loading branch information
joeltimothyoh authored Jul 20, 2024
2 parents 0e0ba61 + 7910b6e commit b67e8cd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions test/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ Set-StrictMode -Version Latest
$script:PesterDebugPreference_ShowFullErrors = $true

try {
# Initialize variables
$moduleItem = if (Test-Path "$PSScriptRoot/../src/*/*.psd1" -PathType Leaf) { Get-Item "$PSScriptRoot/../src/*/*.psd1" }
elseif (Test-Path "$PSScriptRoot/../src/*/*.psm1" -PathType Leaf) { Get-Item "$PSScriptRoot/../src/*/*.psm1" }
$MODULE_PATH = $moduleItem.FullName
$MODULE_DIR = $moduleItem.Directory
$MODULE_NAME = $moduleItem.BaseName
# Process variables
$MODULE_NAME = (Get-Item $PSScriptRoot/../).Name
$MODULE_DIR = "$PSScriptRoot/../src/$MODULE_NAME" | Convert-Path -ErrorAction Stop
$MODULE_MANIFEST = Get-Item "$MODULE_DIR/$MODULE_NAME.psd1" -ErrorAction SilentlyContinue
$SCRIPT_MODULE = Get-Item "$MODULE_DIR/$MODULE_NAME.psm1" -ErrorAction SilentlyContinue
$MODULE_PATH = if ($MODULE_MANIFEST) { $MODULE_MANIFEST.FullName }
elseif ($SCRIPT_MODULE) { $SCRIPT_MODULE.FullName }
else { throw "Unable to locate module manifest file '$MODULE_DIR/$MODULE_NAME.psd1' nor script module file '$MODULE_DIR/$MODULE_NAME.psm1'." }

Push-Location $PSScriptRoot

# Install Pester if needed
"Checking Pester version" | Write-Host
$pesterMinimumVersion = [version]'4.0.0'
$pesterMaximumVersion = [version]'4.10.1'
$pester = Get-Module 'Pester' -ListAvailable -ErrorAction SilentlyContinue
$pester = Get-Module Pester -ListAvailable -ErrorAction SilentlyContinue
if (!$pester -or !($pester | ? { $_.Version -ge $pesterMinimumVersion -and $_.Version -le $pesterMaximumVersion })) {
"Installing Pester" | Write-Host
Install-Module -Name 'Pester' -Repository 'PSGallery' -MinimumVersion $pesterMinimumVersion -MaximumVersion $pesterMaximumVersion -Scope CurrentUser -Force -SkipPublisherCheck
Install-Module -Name Pester -Repository PSGallery -MinimumVersion $pesterMinimumVersion -MaximumVersion $pesterMaximumVersion -Scope CurrentUser -Force -SkipPublisherCheck
}
$pester = Get-Module Pester -ListAvailable
$pester | Out-String | Write-Verbose
$pester | ? { $_.Version -ge $pesterMinimumVersion -and $_.Version -le $pesterMaximumVersion } | Select-Object -First 1 | Import-Module # Force import the latest version within the defined range to ensure environment uses the correct version of Pester
$pester | ? { $_.Version -ge $pesterMinimumVersion -and $_.Version -le $pesterMaximumVersion } | Select-Object -First 1 | Import-Module -Force # Force import the latest version within the defined range to ensure environment uses the correct version of Pester

# Import the project module
Import-Module $MODULE_PATH -Force
Expand Down

0 comments on commit b67e8cd

Please sign in to comment.