From 21920a7b29dcf59828a7a99e2825badbb5df645a Mon Sep 17 00:00:00 2001 From: "Vic Perdana (MSFT)" <7114832+vicperdana@users.noreply.github.com> Date: Wed, 21 Aug 2024 23:04:21 +1000 Subject: [PATCH] Refactor PSDocs.Common.Tests.ps1 to import PSDocs module and use current encoding variable in test names --- tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 index a02a4a3..4467633 100644 --- a/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 @@ -235,9 +235,13 @@ Describe 'Get-PSDocument' -Tag 'Cmdlet', 'Common', 'Get-PSDocument' { $testModuleSourcePath = Join-Path $here -ChildPath 'TestModule'; Mock -CommandName 'LoadModule' -ModuleName 'PSDocs' -Verifiable; Import-Module $testModuleSourcePath -Force; - Import-Module PSDocs -Force; + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath.Path -ChildPath out/modules/PSDocs) -Force; $result = @(Get-PSDocument -Module 'TestModule'); $currentLoadingPreference = Get-Variable -Name PSModuleAutoLoadingPreference -ErrorAction SilentlyContinue -ValueOnly + if (-not (Get-Module -Name PSDocs -ListAvailable)) { + Throw "PSDocs module is not available on this system." + } } It 'Returns documents' { $result = @(Get-PSDocument -Module 'TestModule'); @@ -252,6 +256,8 @@ Describe 'Get-PSDocument' -Tag 'Cmdlet', 'Common', 'Get-PSDocument' { InModuleScope PSDocs { It 'Loads module with preference' { + Mock -CommandName 'LoadModule' -ModuleName 'PSDocs' + $currentLoadingPreference = Get-Variable -Name PSModuleAutoLoadingPreference -ErrorAction SilentlyContinue -ValueOnly try { # Test negative case $Global:PSModuleAutoLoadingPreference = [System.Management.Automation.PSModuleAutoLoadingPreference]::None