Skip to content

Commit 8254355

Browse files
committed
Add support for no PSRepositories being available on machine
1 parent 359af09 commit 8254355

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Extension/task/HelperModule.psm1

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function Import-Pester {
3434

3535

3636
if ((Get-Module -Name PowerShellGet -ListAvailable) -and
37-
(Get-Command Install-Module).Parameters.ContainsKey('SkipPublisherCheck')) {
37+
(Get-Command Install-Module).Parameters.ContainsKey('SkipPublisherCheck') -and
38+
(Get-PSRepository)) {
3839

3940
try {
4041
$null = Get-PackageProvider -Name NuGet -ErrorAction Stop

Extension/test/PesterTask/Helper.Tests.ps1

+15-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,20 @@ Describe "Testing Helper Functions" {
152152
Import-Pester -Version "latest"
153153

154154
Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It
155-
Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.6.0\Pester.psd1'}
155+
Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'}
156+
}
157+
158+
It "Should fall back to build in version of Pester when no repositories are available" {
159+
Mock -CommandName Get-PSRepository -MockWith {}
160+
Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{SkipPublisherCheck='SomeValue'}}} -ParameterFilter {$Name -eq 'Install-Module'}
161+
162+
Import-Pester -Version "latest"
163+
164+
Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It
165+
Assert-MockCalled -CommandName Write-Host -Times 1 -Scope It -ParameterFilter {
166+
$Object -eq "##vso[task.logissue type=warning]Falling back to version of Pester shipped with extension. To use a newer version please update the version of PowerShellGet available on this machine."
167+
}
168+
Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'}
156169
}
157170

158171
<#It "Loads Pester version that ships with task when not on PS5+ or PowerShellGet is unavailable" {
@@ -164,7 +177,7 @@ Describe "Testing Helper Functions" {
164177
Mock -CommandName Get-Module -MockWith { }
165178
166179
&$sut -ScriptFolder TestDrive:\ -ResultsFile TestDrive:\output.xml
167-
Assert-MockCalled Import-Module -ParameterFilter { $Name -eq "$pwd\4.6.0\Pester.psd1" }
180+
Assert-MockCalled Import-Module -ParameterFilter { $Name -eq "$pwd\4.10.1\Pester.psd1" }
168181
Assert-MockCalled Invoke-Pester
169182
}#>
170183
}

0 commit comments

Comments
 (0)