Skip to content

Commit 4a55258

Browse files
Merge pull request #15 from ChrisLGardner/handle-no-psget-repo
Handle no psget repo - fixes #7
2 parents 359af09 + edd6d44 commit 4a55258

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

Extension/task/HelperModule.psm1

+4-3
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
@@ -44,7 +45,7 @@ function Import-Pester {
4445
Install-PackageProvider -Name Nuget -RequiredVersion 2.8.5.201 -Scope CurrentUser -Force -Confirm:$false -ErrorAction Stop
4546
}
4647
catch {
47-
Write-Host "##vos[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."
48+
Write-Host "##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."
4849
Import-Module "$PSScriptRoot\4.10.1\Pester.psd1" -force -Verbose:$false
4950
}
5051
}
@@ -65,7 +66,7 @@ function Import-Pester {
6566
Import-Module -Name Pester -RequiredVersion $NewestPester.Version -Verbose:$false
6667
}
6768
else {
68-
Write-Host "##vos[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."
69+
Write-Host "##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."
6970
Import-Module "$PSScriptRoot\4.10.1\Pester.psd1" -Force -Verbose:$false
7071
}
7172

Extension/task/Pester.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Write-Host "CodeCoverageOutputFile $CodeCoverageOutputFile"
5353
Write-Host "CodeCoverageFolder $CodeCoverageFolder"
5454
Write-Host "ScriptBlock $ScriptBlock"
5555

56-
Import-Module -Name "$PSScriptRoot\HelperModule.psm1" -Force
56+
Import-Module -Name (Join-Path $PSScriptRoot "HelperModule.psm1") -Force
5757
Import-Pester -Version $TargetPesterVersion
5858

5959
if ($run32Bit -eq $true -and $env:Processor_Architecture -ne "x86") {

Extension/test/PesterTask/Helper.Tests.ps1

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Describe "Testing Helper Functions" {
33

44
BeforeAll {
5-
Import-Module -Name "$PSScriptRoot\..\..\Task\HelperModule.psm1" -Force
5+
Import-Module -Name (Resolve-Path "$PSScriptRoot/../../task/HelperModule.psm1") -Force
66
}
77
Context "Testing Get-HashtableFromString" {
88

@@ -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
}

Extension/test/PesterTask/Pester.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Describe "Testing Pester Task" {
22

33
BeforeAll {
4-
$taskPath = "$PSScriptRoot\..\..\Task"
4+
$taskPath = Resolve-Path "$PSScriptRoot/../../task"
55
$sut = Join-Path -Path $taskPath -ChildPath Pester.ps1 -Resolve
66
}
77

azure-pipelines.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: $(major).$(minor).$(rev:r)
12
stages:
23
- stage: build
34
displayName: Build VSIX
@@ -6,10 +7,6 @@ stages:
67
pool:
78
vmimage: ubuntu-latest
89
steps:
9-
- task: GitVersion@5
10-
inputs:
11-
runtime: 'core'
12-
1310
#- task: Pester@9
1411
# inputs:
1512
# scriptFolder: '$(System.DefaultWorkingDirectory)\Extension\test\PesterTask'
@@ -59,7 +56,7 @@ stages:
5956
rootFolder: './Extension'
6057
outputPath: '$(Build.ArtifactStagingDirectory)/Pester.vsix'
6158
updateTasksVersion: true
62-
extensionVersion: "$(GitVersion.MajorMinorPatch).$(GitVersion.CommitsSinceVersionSource)"
59+
extensionVersion: "$(Build.BuildNumber)"
6360

6461
- task: PublishBuildArtifacts@1
6562
displayName: 'Publish Artifact: vsix'

0 commit comments

Comments
 (0)