diff --git a/avm/utilities/tools/Test-ModuleLocally.ps1 b/avm/utilities/tools/Test-ModuleLocally.ps1 index f29c2c90c1..277d96d476 100644 --- a/avm/utilities/tools/Test-ModuleLocally.ps1 +++ b/avm/utilities/tools/Test-ModuleLocally.ps1 @@ -138,6 +138,9 @@ function Test-ModuleLocally { [Parameter(Mandatory = $false)] [switch] $PesterTest, + [Parameter(Mandatory = $false)] + [switch] $PesterTestRecurse, + [Parameter(Mandatory = $false)] [switch] $DeploymentTest, @@ -167,7 +170,7 @@ function Test-ModuleLocally { ################ # PESTER Tests # ################ - if ($PesterTest) { + if ($PesterTest -or $PesterTestRecurse) { Write-Verbose "Pester Testing Module: $ModuleName" try { @@ -176,11 +179,18 @@ function Test-ModuleLocally { (Join-Path $moduleRoot 'tests' 'unit') # Module Unit Tests ) + $moduleFolderPaths = @(Split-Path $TemplateFilePath -Parent) + if ($PesterTestRecurse) { + $moduleFolderPaths += (Get-ChildItem -Path $moduleFolderPaths -Recurse -Directory -Force).FullName | Where-Object { + (Get-ChildItem $_ -File -Depth 0 -Include @('main.json', 'main.bicep') -Force).Count -gt 0 + } + } + Invoke-Pester -Configuration @{ Run = @{ Container = New-PesterContainer -Path $testFiles -Data @{ repoRootPath = $repoRootPath - moduleFolderPaths = Split-Path $TemplateFilePath -Parent + moduleFolderPaths = $moduleFolderPaths } } Output = @{