test/!RunAllTests.ps1
|
Param( [Parameter(Mandatory)] [string]$folder, [Parameter(Mandatory=$false)] [string]$TestFilenameFilter = "*", [Parameter(Mandatory=$false)] [Switch]$MajorRelease, [Parameter(Mandatory=$false)] [string]$ResultOutputFormat = "NUnitXml", [Parameter(Mandatory=$true)] [Switch]$InstallModules ) Write-Host " ========= ENVIRONMENT ==========" Write-Host "Host Name: $($Host.name)" Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)" $rootPath = $PSScriptRoot $folder = Split-Path $rootPath -Parent # $MajorRelease = $false # $TestFilenameFilter = "*" Write-Host "Setting new location: $folder" Push-Location "$folder" Get-Location Write-Host " ========= ENVIRONMENT ==========" # Add the module location to the value of the PSModulePath environment variable #$p = [Environment]::GetEnvironmentVariable("PSModulePath") #$p += ";$folder" #[Environment]::SetEnvironmentVariable("PSModulePath", $p) Write-Host "=============== PowerShell Repositories ================" Get-PSRepository Write-Host "Installing PS modules..." if ($InstallModules) { # Set a process scoped flag so we can run tests while developing without waiting for modules to load again if ($null -eq [Environment]::GetEnvironmentVariable("azure.datafactory.tools.unitTestInstalledModules", 'Process')){ [Environment]::SetEnvironmentVariable("azure.datafactory.tools.unitTestInstalledModules", $false, 'Process'); } if ([Environment]::GetEnvironmentVariable("azure.datafactory.tools.unitTestInstalledModules", 'Process') -eq $false){ #Install-Module 'Az.DataFactory' -Force -MinimumVersion 1.16.0 -Repository 'PSGallery' #Install-Module 'PSScriptAnalyzer' -Force #Install-Module 'Pester' -Force -MinimumVersion 5.1.1 Install-Module 'Az.Storage' -Force -AllowClobber -Repository 'PSGallery' [Environment]::SetEnvironmentVariable("azure.datafactory.tools.unitTestInstalledModules", $true, 'Process'); } } else { Write-Host "Installation skipped." } # Tests require Pester 6+ (e.g. CI runners ship only Pester 5.x) if (-not (Get-Module Pester -ListAvailable | Where-Object Version -ge '6.0.0')) { Write-Host "Installing Pester 6+..." Install-Module 'Pester' -MinimumVersion 6.0.0 -Force -SkipPublisherCheck -Scope CurrentUser -Repository 'PSGallery' } # Unload older Pester (e.g. built-in 3.4.0) so its Should doesn't shadow the newer one Get-Module Pester | Where-Object Version -lt '6.0.0' | Remove-Module -Force Import-Module 'Pester' -MinimumVersion 6.0.0 Import-Module 'PSScriptAnalyzer' Import-Module 'Az.Storage' Import-Module "$folder\azure.datafactory.tools.psd1" Write-Host "=============== Modules ================" Get-Module | Out-Host try { $r = $null $VerbosePreference = 'SilentlyContinue' $ErrorActionPreference = 'Stop' #Important!!! #Set-Location "X:\!WORK\GitHub\!SQLPlayer\azure.datafactory.tools\test" $configuration = [PesterConfiguration]::Default $configuration.Run.Exit = $true $configuration.Should.ErrorAction = 'Continue' $configuration.CodeCoverage.Enabled = $false $configuration.TestResult.OutputFormat = "JUnitXml" $configuration.TestResult.OutputPath = "$folder\TEST-Results.xml" $configuration.TestResult.Enabled = $true $configuration.Output.Verbosity = 'Detailed' if ($MajorRelease -eq $false) { $configuration.Filter.ExcludeTag = 'Integration' } $configuration.Run.Path = "$folder" $configuration.Run.TestExtension = "$TestFilenameFilter.Tests.ps1" $configuration.Run.PassThru = $true $r = Invoke-Pester -Configuration $configuration $r.Result #$r.Failed #$r.Passed[0] $r.Failed | Format-Table -Property Result, StartLine, Duration, Path #Get-ChildItem -Path $folder | Format-Table } finally { Pop-Location } # Connect-AzAccount # . ".\test\!RunAllTests.ps1" -folder '.\test' -TestFilenameFilter 'Inc*' -MajorRelease:$true -InstallModules:$false |