Created
March 12, 2025 18:47
-
-
Save HeyItsGilbert/c6d20124484eb466de8cd230180d599b to your computer and use it in GitHub Desktop.
PSWednesday Pester Containers Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$config = New-PesterConfiguration | |
$config.Run.PassThru = $true | |
$config.Output.Verbosity = 'Detailed' | |
#region An array of stuff | |
$collection = @() | |
$collection += Get-Module -ListAvailable | Where-Object { $_.Author -like 'Gilbert Sanchez' } | |
#endregion An array of stuff | |
#region Create containers | |
$job = $collection | ForEach-Object -AsJob -Parallel { | |
# Make a copy from of the config object | |
$config = $using:config | |
$containers = @() | |
$containers += New-PesterContainer -Data @{Module = $_ } -Path Module.Tests.ps1 | |
$config.Run.Container = $containers | |
Invoke-Pester -Configuration $config | |
} | |
# https://gist.github.com/stefanstranger/839044c5c5c146cb97678933e9a001cc | |
$results = ($job | Wait-Job | Receive-Job -Keep) | |
#endregion | |
#region Create new Pester Object with merged parallel Pester Tests Results. | |
$Pester = [pester.Run]::new() | |
$results | ForEach-Object { | |
$testResult = $_ | |
$pester.Containers += $testResult.Containers | |
$pester.DiscoveryDuration += $testResult.DiscoveryDuration | |
$pester.Duration += $testResult.Duration | |
$pester.Executed += $testResult.Executed | |
$pester.Failed += $testResult.Failed | |
$pester.FailedBlocks += $testResult.FailedBlocks | |
$pester.FailedBlocksCount += $testResult.FailedBlocksCount | |
$pester.FailedContainers += $testResult.FailedContainers | |
$pester.FailedContainersCount += $testResult.FailedContainersCount | |
$pester.FailedCount += $testResult.FailedCount | |
$pester.FrameworkDuration += $testResult.FrameworkDuration | |
$pester.NotRun += $testResult.NotRun | |
$pester.NotRunCount += $testResult.NotRunCount | |
$pester.Passed += $testResult.Passed | |
$pester.PassedCount += $testResult.PassedCount | |
$pester.Result += $testResult.Result | |
$pester.Skipped += $testResult.Skipped | |
$pester.SkippedCount += $testResult.SkippedCount | |
$pester.Tests += $testResult.Tests | |
$pester.TotalCount += $testResult.TotalCount | |
$pester.UserDuration += $testResult.UserDuration | |
} | |
# Update the executed at time to the earliest test run | |
$pester.ExecutedAt = $results.ExecutedAt | Sort-Object -Top 1 | |
#endregion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Module Pester | |
# Start with configuration file | |
$config = New-PesterConfiguration | |
$config.Run.PassThru = $true | |
$config.Output.Verbosity = 'Detailed' | |
#region An array of stuff | |
$collection = @() | |
$collection += Get-Module -ListAvailable | Where-Object { $_.Author -like 'Gilbert Sanchez' } | |
#endregion An array of stuff | |
#region Create containers | |
$containers = @() | |
foreach ($currentItemName in $collection) { | |
$containers += New-PesterContainer -Data @{Module = $currentItemName } -Path Module.Tests.ps1 | |
} | |
# Add the containers to the configuration | |
$config.Run.Container = $containers | |
#endregion Create containers | |
# Run the tests! | |
Invoke-Pester -Configuration $config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $true)] | |
$Module | |
) | |
Describe "<_.Name>" -ForEach $Module { | |
It 'Has a version' { | |
$_.version | Should -BeOfType [version] | |
} | |
It 'Has a description' { | |
$_.description | Should -BeOfType [String] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment