Skip to content

Commit 1d547bb

Browse files
Hampson JaredHampson Jared
Hampson Jared
authored and
Hampson Jared
committedJun 10, 2020
Add test case for when Find-Package cannot find Pester module
1 parent 4161055 commit 1d547bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎Extension/PesterTask/test/PesterTask/Helper.Tests.ps1

+15
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ Describe "Testing Helper Functions" {
126126
Assert-MockCalled -CommandName Install-PackageProvider
127127
}
128128

129+
It "Should fall back to build in version of Pester when Find-Module can't find Pester" {
130+
Mock -CommandName Find-Module -MockWith { Write-Error "No match was found for the specified search
131+
criteria and module name 'Pester'"}
132+
Mock -CommandName Get-PackageProvider -MockWith { $True }
133+
134+
Import-Pester -Version "latest"
135+
136+
Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It
137+
Assert-MockCalled -CommandName Find-Module -Times 1 -Scope It
138+
Assert-MockCalled -CommandName Write-Host -Times 1 -Scope It -ParameterFilter {
139+
$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."
140+
}
141+
Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'}
142+
}
143+
129144
It "Should not install a new version of Pester when the latest is already installed" {
130145
Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=(Get-Module Pester).Version;Repository='PSGallery'}}
131146
Mock -CommandName Get-PackageProvider -MockWith { $True }

0 commit comments

Comments
 (0)
Please sign in to comment.