11Describe ' Get-TitlePanel' {
22 BeforeAll {
3+ . (Join-Path $PSScriptRoot ' Helpers.ps1' )
34 $manifest = Import-PowerShellDataFile - Path $env: BHPSModuleManifest
45 $outputDir = Join-Path - Path $env: BHProjectPath - ChildPath ' Output'
56 $outputModDir = Join-Path - Path $outputDir - ChildPath $env: BHProjectName
@@ -11,16 +12,8 @@ Describe 'Get-TitlePanel' {
1112 Get-Module $env: BHProjectName | Remove-Module - Force - ErrorAction Ignore
1213 Import-Module - Name $outputModVerManifest - Verbose:$false - ErrorAction Stop
1314
14- InModuleScope $env: BHProjectName {
15- $script :ContainerWidth = 80
16- $script :ContainerHeight = 5
17- $size = [Spectre.Console.Size ]::new($containerWidth , $containerHeight )
18- $script :renderOptions = [Spectre.Console.Rendering.RenderOptions ]::new(
19- [Spectre.Console.AnsiConsole ]::Console.Profile.Capabilities,
20- $size
21- )
22- $script :renderOptions.Justification = $null
23- $script :renderOptions.Height = $null
15+ InModuleScope $env: BHProjectname {
16+ $script :pesterResult = Invoke-Pester - PassThru - Path " $PSScriptRoot \fixtures\Example.ps1" - Output ' None'
2417 }
2518 }
2619 It ' should return a Spectre.Console.Panel object' {
@@ -34,28 +27,48 @@ Describe 'Get-TitlePanel' {
3427 InModuleScope $env: BHProjectName {
3528 Mock - CommandName ' Get-Date' - MockWith { ' 2025-01-10 12:00:00' }
3629 $title = Get-TitlePanel
37- $render = $title.Render ($script :renderOptions , $script :ContainerWidth )
38- # These are rendered segments.
39- (
40- ' Pester' ,
41- ' Explorer' ,
42- ' 2025-01-10' ,
43- ' 12:00:00'
44- ) | ForEach-Object {
45- $render.Text | Should - Contain $_
46- }
30+ global:Get-RenderedText - Panel $title |
31+ Should - Contain ' Pester Explorer - 2025-01-10 12:00:00'
32+ }
33+ }
34+
35+ It ' should print pester run name and type' {
36+ InModuleScope $env: BHProjectName {
37+ $titleWithItem = Get-TitlePanel - Item $script :pesterResult
38+ $renderWithItem = global:Get-RenderedText - Panel $titleWithItem
39+ $renderWithItem | Should -Match ' Run: . Pester.Run'
40+ }
41+ }
42+
43+ It ' should print container name and type' {
44+ InModuleScope $env: BHProjectName {
45+ $titleWithItem = Get-TitlePanel - Item $script :pesterResult.Containers [0 ]
46+ $renderWithItem = global:Get-RenderedText - Panel $titleWithItem
47+ $renderWithItem | Should - BeLike ' *Container:*Example.ps1'
4748 }
4849 }
4950
50- It ' should include the Pester object type and name if provided ' {
51+ It ' should print block name and type ' {
5152 InModuleScope $env: BHProjectName {
52- $pesterBlock = [Pester.Block ]::Create()
53- $pesterBlock.Name = ' Blockhead'
54- $pesterBlock.Result = ' Failed'
55- $titleWithItem = Get-TitlePanel - Item $pesterBlock
56- $renderWithItem = $titleWithItem.Render ($script :renderOptions , $script :ContainerWidth )
57- $renderWithItem.Text | Should - Contain ' Block:'
58- $renderWithItem.Text | Should - Contain ' Blockhead'
53+ $titleWithItem = Get-TitlePanel - Item $script :pesterResult.Containers [0 ].Blocks[0 ]
54+ $renderWithItem = global:Get-RenderedText - Panel $titleWithItem
55+ $renderWithItem | Should -Match ' Block: . Example Tests'
56+ }
57+ }
58+
59+ Context ' Tests' {
60+ BeforeDiscovery {
61+ $pesterResult = Invoke-Pester - PassThru - Path " $PSScriptRoot \fixtures\Example.ps1" - Output ' None'
62+ $tests = $pesterResult.Containers [0 ].Blocks[0 ].Tests
63+ }
64+
65+ It ' should print test name <_>' - ForEach $tests {
66+ InModuleScope $env: BHProjectName - ArgumentList $_ - ScriptBlock {
67+ param ($test )
68+ $titleWithItem = Get-TitlePanel - Item $test
69+ $renderWithItem = global:Get-RenderedText - Panel $titleWithItem
70+ $renderWithItem | Should -Match " Test: .*$ ( $test.Name ) "
71+ }
5972 }
6073 }
6174}
0 commit comments