2017-12-31 19:36:51 +00:00
|
|
|
param(
|
|
|
|
|
[string[]]$Tasks
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function Install-Dependency([string] $Name)
|
|
|
|
|
{
|
|
|
|
|
$policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy"
|
|
|
|
|
if($policy -ne "Trusted") {
|
|
|
|
|
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(Get-Module -Name $Name -ListAvailable)) {
|
|
|
|
|
Install-Module -Name $Name -Scope CurrentUser
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Run-Tests
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Path = "$PSScriptRoot\SnipeitPS"
|
|
|
|
|
)
|
|
|
|
|
|
2017-12-31 19:42:27 +00:00
|
|
|
$results = Invoke-Pester -PassThru
|
2017-12-31 19:36:51 +00:00
|
|
|
if($results.FailedCount -gt 0) {
|
|
|
|
|
Write-Output " > $($results.FailedCount) tests failed. The build cannot continue."
|
|
|
|
|
foreach($result in $($results.TestResult | Where {$_.Passed -eq $false} | Select-Object -Property Describe,Context,Name,Passed,Time)){
|
|
|
|
|
Write-Output " > $result"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EXIT 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach($task in $Tasks){
|
|
|
|
|
switch($task)
|
|
|
|
|
{
|
|
|
|
|
"test" {
|
2017-12-31 19:42:27 +00:00
|
|
|
Install-Dependency -Name "PSScriptAnalyzer"
|
2017-12-31 19:36:51 +00:00
|
|
|
Install-Dependency -Name "Pester"
|
|
|
|
|
Write-Output "Running Pester Tests..."
|
|
|
|
|
Run-Tests
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|