diff --git a/Tests/powershell-helpers.ps1 b/Tests/powershell-helpers.ps1 index 8c16bea9c..a6fa2d2ae 100644 --- a/Tests/powershell-helpers.ps1 +++ b/Tests/powershell-helpers.ps1 @@ -37,6 +37,30 @@ function Test-AppExists($appName) { return $null -ne $command } +function Invoke-PesterTests { + Write-Output "##teamcity[blockOpened name='Pester tests']" + Write-Output "##teamcity[blockOpened name='Importing modules']" + Write-Output "Importing Pester module" + Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1" + Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0" + Write-Output "##teamcity[blockClosed name='Importing modules']" + Write-Output "Running Pester Tests" + $configuration = [PesterConfiguration]::Default + $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputPath = 'PesterTestResults.xml' + $configuration.TestResult.OutputFormat = 'NUnitXml' + $configuration.Run.PassThru = $true + $configuration.Run.Exit = $true + $configuration.Run.Path = @("./Tests", "./OctopusDSC") + $configuration.Output.Verbosity = 'Detailed' + $result = Invoke-Pester -configuration $configuration + write-output "##teamcity[publishArtifacts 'PesterTestResults.xml']" + if ($result.FailedCount -gt 0) { + exit 1 + } + Write-Output "##teamcity[blockClosed name='Pester tests']" +} + function Import-PowerShellModule ($Name, $MinimumVersion) { $command = Get-Module $Name -listavailable if ($null -eq $command) { diff --git a/build-aws.ps1 b/build-aws.ps1 index 797b02c7a..1fff46f32 100755 --- a/build-aws.ps1 +++ b/build-aws.ps1 @@ -41,24 +41,7 @@ Test-PluginInstalled "vagrant-winrm-file-download" Remove-OldLogsBeforeNewRun if(-not $SkipPester) { - Write-Output "##teamcity[blockOpened name='Pester tests']" - Write-Output "Importing Pester module" - Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1" - Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0" - - Write-Output "Running Pester Tests" - $configuration = [PesterConfiguration]::Default - $configuration.TestResult.Enabled = $true - $configuration.TestResult.OutputPath = 'PesterTestResults.xml' - $configuration.TestResult.OutputFormat = 'NUnitXml' - $configuration.Run.PassThru = $true - $configuration.Run.Exit = $true - $result = Invoke-Pester -configuration $configuration - write-output "##teamcity[publishArtifacts 'PesterTestResults.xml']" - if ($result.FailedCount -gt 0) { - exit 1 - } - Write-Output "##teamcity[blockClosed name='Pester tests']" + Invoke-PesterTests } else { Write-Output "-SkipPester was specified, skipping pester tests" } diff --git a/build-azure.ps1 b/build-azure.ps1 index 8c6520acf..47acddaad 100755 --- a/build-azure.ps1 +++ b/build-azure.ps1 @@ -41,22 +41,9 @@ Test-PluginInstalled "vagrant-winrm-file-download" Remove-OldLogsBeforeNewRun if(-not $SkipPester) { - Write-Output "Importing Pester module" - Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1" - Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0" - - Write-Output "Running Pester Tests" - $configuration = [PesterConfiguration]::Default - $configuration.TestResult.Enabled = $true - $configuration.TestResult.OutputPath = 'PesterTestResults.xml' - $configuration.TestResult.OutputFormat = 'NUnitXml' - $configuration.Run.PassThru = $true - $configuration.Run.Exit = $true - $configuration.Output.Verbosity = 'Detailed' - $result = Invoke-Pester -configuration $configuration - if ($result.FailedCount -gt 0) { - exit 1 - } + Invoke-PesterTests +} else { + Write-Output "-SkipPester was specified, skipping pester tests" } Write-Output "Running 'vagrant up --provider azure'" diff --git a/build-hyperv.ps1 b/build-hyperv.ps1 index b0acc424a..c3f43b6d8 100644 --- a/build-hyperv.ps1 +++ b/build-hyperv.ps1 @@ -56,22 +56,7 @@ Test-PluginInstalled "vagrant-winrm-file-download" Remove-OldLogsBeforeNewRun if(-not $SkipPester) { - Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1" - Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0" - Write-Output "Running Pester Tests" - - $configuration = [PesterConfiguration]::Default - $configuration.TestResult.Enabled = $true - $configuration.TestResult.OutputPath = 'PesterTestResults.xml' - $configuration.TestResult.OutputFormat = 'NUnitXml' - $configuration.Run.PassThru = $true - $configuration.Run.Exit = $true - $configuration.Output.Verbosity = 'Detailed' - $result = Invoke-Pester -configuration $configuration - - if ($result.FailedCount -gt 0) { - exit 1 - } + Invoke-PesterTests } else { Write-Output "-SkipPester was specified, skipping pester tests" } diff --git a/build-virtualbox.ps1 b/build-virtualbox.ps1 index 2f565f8a2..20eb5be59 100644 --- a/build-virtualbox.ps1 +++ b/build-virtualbox.ps1 @@ -33,22 +33,7 @@ Test-PluginInstalled "vagrant-winrm-file-download" Remove-OldLogsBeforeNewRun if(-not $SkipPester) { - Write-Output "Importing Pester module" - Import-PowerShellModule -Name "Pester" -MinimumVersion "5.2.1" - Import-PowerShellModule -Name "PSScriptAnalyzer" -MinimumVersion "1.19.0" - - Write-Output "Running Pester Tests" - $configuration = [PesterConfiguration]::Default - $configuration.TestResult.Enabled = $true - $configuration.TestResult.OutputPath = 'PesterTestResults.xml' - $configuration.TestResult.OutputFormat = 'NUnitXml' - $configuration.Run.PassThru = $true - $configuration.Run.Exit = $true - $configuration.Output.Verbosity = 'Detailed' - $result = Invoke-Pester -configuration $configuration - if ($result.FailedCount -gt 0) { - exit 1 - } + Invoke-PesterTests } else { Write-Output "-SkipPester was specified, skipping pester tests" }