Skip to content

Commit 4862d21

Browse files
feat: optimize module test suite handling by using ArrayList for dynamic additions
1 parent 14d20f5 commit 4862d21

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

scripts/main.ps1

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ process {
220220
}
221221

222222
LogGroup 'Module Local Test Suites:' {
223-
$moduleTestSuites = if ($settings.Test.Module.Skip) {
223+
if ($settings.Test.Module.Skip) {
224224
Write-Host 'Skipping all module tests.'
225+
$moduleTestSuites = @()
225226
} else {
226227
# Locate the tests directory.
227228
$testsPath = Resolve-Path 'tests' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Path
@@ -295,32 +296,33 @@ process {
295296

296297
$allTestFolders = @($testsPath) + (Find-TestDirectory -Path $testsPath)
297298

299+
$moduleTestSuites = [System.Collections.ArrayList]::new()
298300
foreach ($folder in $allTestFolders) {
299301
$testItems = Get-TestItemsFromFolder -FolderPath $folder
300302
foreach ($item in $testItems) {
301303
if (-not $settings.Test.Linux.Skip -and -not $settings.Test.Module.Linux.Skip) {
302-
[pscustomobject]@{
303-
RunsOn = $linux.RunsOn
304-
OSName = $linux.OSName
305-
TestPath = Resolve-Path -Path $item.FullName -Relative
306-
TestName = ($item.BaseName).Split('.')[0]
307-
}
304+
[void]$moduleTestSuites.Add([pscustomobject]@{
305+
RunsOn = $linux.RunsOn
306+
OSName = $linux.OSName
307+
TestPath = Resolve-Path -Path $item.FullName -Relative
308+
TestName = ($item.BaseName).Split('.')[0]
309+
})
308310
}
309311
if (-not $settings.Test.MacOS.Skip -and -not $settings.Test.Module.MacOS.Skip) {
310-
[pscustomobject]@{
311-
RunsOn = $macOS.RunsOn
312-
OSName = $macOS.OSName
313-
TestPath = Resolve-Path -Path $item.FullName -Relative
314-
TestName = ($item.BaseName).Split('.')[0]
315-
}
312+
[void]$moduleTestSuites.Add([pscustomobject]@{
313+
RunsOn = $macOS.RunsOn
314+
OSName = $macOS.OSName
315+
TestPath = Resolve-Path -Path $item.FullName -Relative
316+
TestName = ($item.BaseName).Split('.')[0]
317+
})
316318
}
317319
if (-not $settings.Test.Windows.Skip -and -not $settings.Test.Module.Windows.Skip) {
318-
[pscustomobject]@{
319-
RunsOn = $windows.RunsOn
320-
OSName = $windows.OSName
321-
TestPath = Resolve-Path -Path $item.FullName -Relative
322-
TestName = ($item.BaseName).Split('.')[0]
323-
}
320+
[void]$moduleTestSuites.Add([pscustomobject]@{
321+
RunsOn = $windows.RunsOn
322+
OSName = $windows.OSName
323+
TestPath = Resolve-Path -Path $item.FullName -Relative
324+
TestName = ($item.BaseName).Split('.')[0]
325+
})
324326
}
325327
}
326328
}

0 commit comments

Comments
 (0)