<# .SYNOPSIS Tests a project in the Alkami.PowerShell module system .EXAMPLE .\test-project.ps1 .\Alkami.PowerShell.IIS\ .PARAMETER FolderPath The name of the folder to examine all files under .PARAMETER FilenameMatch A wildcard pattern to match for the testing scope. This limits how many files are looked at. Matching pattern is *$FilenameMatch*.test?.ps1 .PARAMETER Noisy Show the output of the process instead of a synopsis .PARAMETER NoAnalyzer Don't run PSScriptAnalyzer on the project #> [CmdletBinding()] Param( $FolderPath, $FilenameMatch, [switch]$AsBuildServer, [switch]$Noisy, [switch]$NoAnalyzer, [switch]$DontReloadPester ) process { $globalSuppressReloadSetAtAHigherLevel = !!$global:SuppressReload if (!$globalSuppressReloadSetAtAHigherLevel) { $global:SuppressReload = $true $DontReloadPester = $true } if ($Noisy) { Write-Host "Testing project located at $FolderPath" } $runAnalyzer = $true ## If no filename match was provided, don't run the analyzer for everything if ([string]::IsNullOrWhiteSpace($FilenameMatch)) { $runAnalyzer = $false } if ($NoAnalyzer) { $runAnalyzer = $false } if (!$DontReloadPester) { Get-Module Alkami* | Remove-Module -Force } . $PSScriptRoot\.build\Load-Includes.ps1 -DontReload:$DontReloadPester $csprojPaths = (Get-ChildItem *.csproj -Path $FolderPath) if (!$AsBuildServer -and (@($csprojPaths).Count -gt 0)) { if (!$FilenameMatch) { Write-Host "TODO: Write nunit or something test runner for C# projects" } foreach($csprojPath in $csprojPaths) { ## I don't know what to put here } return $null } elseif (Test-Path (Join-Path $FolderPath Public)) { $failingResults = @() $testPattern = "*.pester.ps1" if (!!$FilenameMatch) { $testPattern = "*$FilenameMatch*.pester.ps1" } $folderTypes = @('Public','Private') foreach ($folderType in $folderTypes) { if (Test-Path (Join-Path $FolderPath $folderType)) { $testFiles = (Get-ChildItem -Path (Join-Path $FolderPath $folderType) $testPattern -recurse) foreach ($file in $testFiles) { if ($Noisy) { Write-Host "Testing $file" Invoke-Pester $file.FullName Invoke-ScriptAnalyzer "$($file.Directory.FullName).ps1" } else { Write-Verbose "Testing $file" $failingResult = New-Object PSObject -Property @{ Filename = $file.FullName; TestResult = $null; Analyzer = $null; } ## Verbose Host Warning $testrunResults = Invoke-Pester $file.FullName -Show Summary,Failed -PassThru 4>$null 6>$null 3>$null $failingResult.TestResult = $testrunResults.TestResult | Where-Object { $_.Result -eq 'Failed'} if ($testrunResults.FailedCount -gt 0) { Write-Warning "[$($testrunResults.FailedCount)] of [$($testrunResults.TotalCount)] tests failed for [$($file.FullName)]" } if ($runAnalyzer) { if (Test-Path $baseFile) { $reportSummary += Invoke-ScriptAnalyzer "$($file.Directory.FullName).ps1" -Severity Error,Warning } $failingResult.Analyzer = $reportSummary } $failingResults += $failingResult } } } } return $failingResults } else { Write-Verbose "There was no public folder and no csproj to test in [$FolderPath]" return $null } if (!$globalSuppressReloadSetAtAHigherLevel) { $global:SuppressReload = $false } }