From 2152c644c527910544f9cdf1854e7f3ba6c5dc1b Mon Sep 17 00:00:00 2001 From: Anders Eide Date: Wed, 4 Dec 2024 12:53:08 +0100 Subject: [PATCH] feat: Added logic to find child modules when running `Test-ModuleLocally -PesterTest` (#3870) ## Description Changed logic in Test-ModuleLocally to detect child modules. Uses same code as in the GitHub Action at https://github.com/Azure/bicep-registry-modules/blob/main/.github/actions/templates/avm-validateModulePester/action.yml Closes #3869 ## Pipeline Reference | Pipeline | | -------- | | | ## Type of Change - [X] Update to CI Environment or utilities (Non-module affecting changes) - [ ] Azure Verified Module updates: - [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT bumped the MAJOR or MINOR version in `version.json`: - [ ] Someone has opened a bug report issue, and I have included "Closes #{bug_report_issue_number}" in the PR description. - [ ] The bug was found by the module author, and no one has opened an issue to report it yet. - [ ] Feature update backwards compatible feature updates, and I have bumped the MINOR version in `version.json`. - [ ] Breaking changes and I have bumped the MAJOR version in `version.json`. - [ ] Update to documentation ## Checklist - [X] I'm sure there are no other open Pull Requests for the same update/change - [ ] I have run `Set-AVMModule` locally to generate the supporting module files. - [ ] My corresponding pipelines / checks run clean and green without any errors or warnings --- avm/utilities/tools/Test-ModuleLocally.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 = @{