Build-Run-Tests.ps1

Param(
    $Path=$null
)

Write-Host "Starting Script ""Build-Run-Tests.ps1""" -ForegroundColor Gray -BackgroundColor White

Write-Host "Try to set SourceDir from Build-variable"
$SourceDir=$Path
 
if([String]::IsNullOrEmpty($SourceDir)) {
    $SourceDir=$($PSScriptRoot)
    Write-Host "Build-variable was not given. Using PSScriptRoot"
}
Write-Host "SourceDir is ""$sourceDir"""


$modulePath = Join-Path $($env:TEMP) Pester-master\Pester.psm1
Write-Host "Module directory for Pester module is ""$modulePath"""

$outputFile = Join-Path $SourceDir "TEST-pester.xml"
Write-Host "All output will be written to file $outputFile"

Write-Host "Check if Pester Module must be imported"
if((Get-Module Pester) -eq $null) {
    Write-Host "Pester not available in current session. Import module"
    Import-Module $modulePath -DisableNameChecking -Verbose
}

Write-Host "Import Module from directory $SourceDir"
Import-Module "$SourceDir" -Force -Verbose

Write-Host "Start Tests in folder ""$SourceDir"""
Invoke-Pester -Path "$SourceDir" -PassThru -OutputFile $outputFile -OutputFormat NUnitXml
Write-Host "Tests finished"

Write-Host "Finished Script ""Build-Run-Tests.ps1""" -ForegroundColor Gray -BackgroundColor White