|
2 | 2 | Describe "Testing Helper Functions" {
|
3 | 3 |
|
4 | 4 | BeforeAll {
|
5 |
| - Import-Module -Name (Resolve-Path "$PSScriptRoot/../../task/HelperModule.psm1") -Force |
| 5 | + Import-Module -Name (Resolve-Path "$PSScriptRoot/../../PesterV9/HelperModule.psm1") -Force |
6 | 6 | }
|
7 | 7 | Context "Testing Get-HashtableFromString" {
|
8 | 8 |
|
@@ -82,103 +82,120 @@ Describe "Testing Helper Functions" {
|
82 | 82 | }
|
83 | 83 | }
|
84 | 84 |
|
85 |
| - Context "Testing Import-Pester" { |
| 85 | + InModuleScope "HelperModule" { |
| 86 | + Context "Testing Import-Pester" { |
86 | 87 |
|
87 |
| - BeforeAll { |
88 |
| - Mock -CommandName Import-Module -MockWith { } |
89 |
| - Mock -CommandName Install-Module -MockWith { $true } |
90 |
| - Mock -CommandName Write-host -MockWith { } |
91 |
| - Mock -CommandName Get-PSRepository -MockWith {[PSCustomObject]@{Name = 'PSGallery'}} |
92 |
| - Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{SkipPublisherCheck='SomeValue'}}} -ParameterFilter {$Name -eq 'Install-Module'} |
93 |
| - Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{AllowPrerelease='SomeValue'}}} -ParameterFilter {$Name -eq 'Find-Module'} |
94 |
| - } |
95 |
| - |
96 |
| - It "Installs the latest version of Pester when on PS5+ and PowerShellGet is available" { |
97 |
| - Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
98 |
| - Mock -CommandName Get-PackageProvider -MockWith { $True } |
| 88 | + BeforeAll { |
| 89 | + Mock -CommandName Import-Module -MockWith { } |
| 90 | + Mock -CommandName Install-Module -MockWith { $true } |
| 91 | + Mock -CommandName Write-host -MockWith { } |
| 92 | + Mock -CommandName Get-PSRepository -MockWith {[PSCustomObject]@{Name = 'PSGallery'}} |
| 93 | + Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{SkipPublisherCheck='SomeValue'}}} -ParameterFilter {$Name -eq 'Install-Module'} |
| 94 | + Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{AllowPrerelease='SomeValue'}}} -ParameterFilter {$Name -eq 'Find-Module'} |
| 95 | + } |
99 | 96 |
|
100 |
| - Import-Pester -Version "latest" |
101 |
| - |
102 |
| - Assert-MockCalled -CommandName Import-Module -ParameterFilter {$RequiredVersion -eq "9.9.9"} -Scope It -Times 1 |
103 |
| - } |
| 97 | + It "Installs the latest version of Pester when on PS5+ and PowerShellGet is available" { |
| 98 | + Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
| 99 | + Mock -CommandName Get-PackageProvider -MockWith { $True } |
104 | 100 |
|
105 |
| - It "Installs the latest version of Pester from PSGallery when multiple repositories are available" { |
106 |
| - Mock -CommandName Find-Module -MockWith { @( |
107 |
| - [PsCustomObject]@{Version=[version]::new(4,3,0);Repository='OtherRepository'} |
108 |
| - [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'} |
109 |
| - ) |
| 101 | + Import-Pester -Version "latest" |
| 102 | + |
| 103 | + Assert-MockCalled -CommandName Import-Module -ParameterFilter {$RequiredVersion -eq "9.9.9"} -Scope It -Times 1 |
110 | 104 | }
|
111 |
| - Mock -CommandName Get-PackageProvider -MockWith { $True } |
112 | 105 |
|
113 |
| - Import-Pester -Version "latest" |
| 106 | + It "Installs the latest version of Pester from PSGallery when multiple repositories are available" { |
| 107 | + Mock -CommandName Find-Module -MockWith { @( |
| 108 | + [PsCustomObject]@{Version=[version]::new(4,3,0);Repository='OtherRepository'} |
| 109 | + [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'} |
| 110 | + ) |
| 111 | + } |
| 112 | + Mock -CommandName Get-PackageProvider -MockWith { $True } |
114 | 113 |
|
115 |
| - Assert-MockCalled -CommandName Install-Module -Scope It -ParameterFilter {$Repository -eq 'PSGallery'} |
116 |
| - } |
| 114 | + Import-Pester -Version "latest" |
117 | 115 |
|
118 |
| - It "Installs the required version of NuGet provider when PowerShellGet is available and NuGet isn't already installed" { |
119 |
| - Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
120 |
| - Mock -CommandName Get-PackageProvider -MockWith { throw } |
121 |
| - Mock -CommandName Install-PackageProvider -MockWith {} |
| 116 | + Assert-MockCalled -CommandName Install-Module -Scope It -ParameterFilter {$Repository -eq 'PSGallery'} |
| 117 | + } |
122 | 118 |
|
123 |
| - Import-Pester -Version "latest" |
| 119 | + It "Installs the required version of NuGet provider when PowerShellGet is available and NuGet isn't already installed" { |
| 120 | + Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
| 121 | + Mock -CommandName Get-PackageProvider -MockWith { throw } |
| 122 | + Mock -CommandName Install-PackageProvider -MockWith {} |
124 | 123 |
|
125 |
| - Assert-MockCalled -CommandName Install-PackageProvider |
126 |
| - } |
| 124 | + Import-Pester -Version "latest" |
127 | 125 |
|
128 |
| - It "Should not install a new version of Pester when the latest is already installed" { |
129 |
| - Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=(Get-Module Pester).Version;Repository='PSGallery'}} |
130 |
| - Mock -CommandName Get-PackageProvider -MockWith { $True } |
| 126 | + Assert-MockCalled -CommandName Install-PackageProvider |
| 127 | + } |
131 | 128 |
|
132 |
| - Import-Pester -Version "latest" |
| 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 | + } |
133 | 143 |
|
134 |
| - Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It |
135 |
| - } |
| 144 | + It "Should not install a new version of Pester when the latest is already installed" { |
| 145 | + Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=(Get-Module Pester).Version;Repository='PSGallery'}} |
| 146 | + Mock -CommandName Get-PackageProvider -MockWith { $True } |
136 | 147 |
|
137 |
| - It "Should install and import the specified version of Pester regardless of what is avaialble locally" { |
138 |
| - Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(4,2,0);Repository='PSGallery'}} |
139 |
| - Mock -CommandName Get-PackageProvider -MockWith { $True } |
| 148 | + Import-Pester -Version "latest" |
140 | 149 |
|
141 |
| - Import-Pester -Version 4.2.0 |
| 150 | + Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It |
| 151 | + } |
142 | 152 |
|
143 |
| - Assert-MockCalled -CommandName Install-Module -Times 1 -ParameterFilter { $RequiredVersion -eq "4.2.0"} |
144 |
| - Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$RequiredVersion -eq "4.2.0"} |
145 |
| - } |
| 153 | + It "Should install and import the specified version of Pester regardless of what is avaialble locally" { |
| 154 | + Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(4,2,0);Repository='PSGallery'}} |
| 155 | + Mock -CommandName Get-PackageProvider -MockWith { $True } |
146 | 156 |
|
147 |
| - It "Should not Install the latest version of Pester when on PowerShellGet is available but SkipPublisherCheck is not available" { |
148 |
| - Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
149 |
| - Mock -CommandName Get-PackageProvider -MockWith { $True } |
150 |
| - Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{OtherProperty='SomeValue'}} } -ParameterFilter {$Name -eq 'Install-Module'} |
| 157 | + Import-Pester -Version 4.2.0 |
151 | 158 |
|
152 |
| - Import-Pester -Version "latest" |
| 159 | + Assert-MockCalled -CommandName Install-Module -Times 1 -ParameterFilter { $RequiredVersion -eq "4.2.0"} |
| 160 | + Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$RequiredVersion -eq "4.2.0"} |
| 161 | + } |
153 | 162 |
|
154 |
| - Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It |
155 |
| - Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'} |
156 |
| - } |
| 163 | + It "Should not Install the latest version of Pester when on PowerShellGet is available but SkipPublisherCheck is not available" { |
| 164 | + Mock -CommandName Find-Module -MockWith { [PsCustomObject]@{Version=[version]::new(9,9,9);Repository='PSGallery'}} |
| 165 | + Mock -CommandName Get-PackageProvider -MockWith { $True } |
| 166 | + Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{OtherProperty='SomeValue'}} } -ParameterFilter {$Name -eq 'Install-Module'} |
| 167 | + |
| 168 | + Import-Pester -Version "latest" |
| 169 | + |
| 170 | + Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It |
| 171 | + Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'} |
| 172 | + } |
157 | 173 |
|
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'} |
| 174 | + It "Should fall back to build in version of Pester when no repositories are available" { |
| 175 | + Mock -CommandName Get-PSRepository -MockWith {} |
| 176 | + Mock -CommandName Get-Command -MockWith { [PsCustomObject]@{Parameters=@{SkipPublisherCheck='SomeValue'}}} -ParameterFilter {$Name -eq 'Install-Module'} |
161 | 177 |
|
162 |
| - Import-Pester -Version "latest" |
| 178 | + Import-Pester -Version "latest" |
163 | 179 |
|
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." |
| 180 | + Assert-MockCalled -CommandName Install-Module -Times 0 -Scope It |
| 181 | + Assert-MockCalled -CommandName Write-Host -Times 1 -Scope It -ParameterFilter { |
| 182 | + $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." |
| 183 | + } |
| 184 | + Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'} |
167 | 185 | }
|
168 |
| - Assert-MockCalled -CommandName Import-Module -Times 1 -ParameterFilter {$Name -like '*\4.10.1\Pester.psd1'} |
169 |
| - } |
170 | 186 |
|
171 |
| - <#It "Loads Pester version that ships with task when not on PS5+ or PowerShellGet is unavailable" { |
172 |
| - Mock -CommandName Invoke-Pester -MockWith { } |
173 |
| - Mock -CommandName Import-Module -MockWith { } |
174 |
| - Mock -CommandName Write-Host -MockWith { } |
175 |
| - Mock -CommandName Write-Warning -MockWith { } |
176 |
| - Mock -CommandName Write-Error -MockWith { } |
177 |
| - Mock -CommandName Get-Module -MockWith { } |
178 |
| -
|
179 |
| - &$sut -ScriptFolder TestDrive:\ -ResultsFile TestDrive:\output.xml |
180 |
| - Assert-MockCalled Import-Module -ParameterFilter { $Name -eq "$pwd\4.10.1\Pester.psd1" } |
181 |
| - Assert-MockCalled Invoke-Pester |
182 |
| - }#> |
183 |
| - } |
| 187 | + <#It "Loads Pester version that ships with task when not on PS5+ or PowerShellGet is unavailable" { |
| 188 | + Mock -CommandName Invoke-Pester -MockWith { } |
| 189 | + Mock -CommandName Import-Module -MockWith { } |
| 190 | + Mock -CommandName Write-Host -MockWith { } |
| 191 | + Mock -CommandName Write-Warning -MockWith { } |
| 192 | + Mock -CommandName Write-Error -MockWith { } |
| 193 | + Mock -CommandName Get-Module -MockWith { } |
| 194 | +
|
| 195 | + &$sut -ScriptFolder TestDrive:\ -ResultsFile TestDrive:\output.xml |
| 196 | + Assert-MockCalled Import-Module -ParameterFilter { $Name -eq "$pwd\4.10.1\Pester.psd1" } |
| 197 | + Assert-MockCalled Invoke-Pester |
| 198 | + }#> |
| 199 | + } |
| 200 | + } |
184 | 201 | }
|
0 commit comments