Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.3] 2025-06-03

### Fixed

- Inconclusive tests are now darkorange because orange isn't a valid Spectre
color.

## [0.3.2] 2025-05-31

### Added
Expand All @@ -19,7 +26,7 @@

### Added

- Add VIM (i.e. `hjkl`) navigation support.

Check warning on line 29 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (hjkl) Suggestions: (hulk, hail, hake, haku, hall)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion PesterExplorer/PesterExplorer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PesterExplorer.psm1'

# Version number of this module.
ModuleVersion = '0.3.2'
ModuleVersion = '0.3.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
2 changes: 1 addition & 1 deletion PesterExplorer/Private/Format-PesterObjectName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
'Passed' { 'green' }
'Failed' { 'red' }
'Skipped' { 'yellow' }
'Inconclusive' { 'orange' }
'Inconclusive' { 'darkorange' }

Check warning on line 64 in PesterExplorer/Private/Format-PesterObjectName.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (darkorange)
default { 'white' }
}
$finalName = if ($NoColor) {
Expand Down
18 changes: 3 additions & 15 deletions tests/Get-PreviewPanel.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Describe 'Get-PreviewPanel' {
BeforeAll {
. (Join-Path $PSScriptRoot 'Helpers.ps1')
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest

Check warning on line 4 in tests/Get-PreviewPanel.tests.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (BHPS) Suggestions: (baps, bops, bhp, BHP, bps)
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
Expand All @@ -15,13 +15,6 @@
InModuleScope $env:BHProjectName {
$script:ContainerWidth = 80
$script:ContainerHeight = 200
$size = [Spectre.Console.Size]::new($containerWidth, $containerHeight)
$script:renderOptions = [Spectre.Console.Rendering.RenderOptions]::new(
[Spectre.Console.AnsiConsole]::Console.Profile.Capabilities,
$size
)
$script:renderOptions.Justification = $null
$script:renderOptions.Height = $null
$container = New-PesterContainer -Scriptblock {
Describe 'Demo Tests' {
Context 'Contextualize It' {
Expand Down Expand Up @@ -69,7 +62,7 @@
PreviewWidth = $script:ContainerWidth
}
$panel = Get-PreviewPanel @getPreviewPanelSplat
global:Get-RenderedText -panel $panel -renderOptions $script:renderOptions -containerWidth $script:ContainerWidth |
global:Get-RenderedText -Panel $panel |
Should -BeLike "*Please select an item.*"
}
}
Expand All @@ -78,11 +71,6 @@
InModuleScope $env:BHProjectName {
$Items = Get-ListFromObject -Object $script:run.Containers[0].Blocks[0].Order[0]
$height = 5
$size = [Spectre.Console.Size]::new(80, $height)
$renderOptions = [Spectre.Console.Rendering.RenderOptions]::new(
[Spectre.Console.AnsiConsole]::Console.Profile.Capabilities,
$size
)
$getPreviewPanelSplat = @{
Items = $Items
SelectedItem = 'Test1'
Expand All @@ -91,7 +79,7 @@
PreviewWidth = $script:ContainerWidth
}
$panel = Get-PreviewPanel @getPreviewPanelSplat
global:Get-RenderedText -panel $panel -renderOptions $renderOptions -containerWidth $script:ContainerWidth |
global:Get-RenderedText -Panel $panel |
Should -BeLike "*resize your terminal*"
}
}
Expand All @@ -106,7 +94,7 @@
PreviewWidth = $script:ContainerWidth
}
$panel = Get-PreviewPanel @getPreviewPanelSplat
global:Get-RenderedText -panel $panel -renderOptions $script:renderOptions -containerWidth $script:ContainerWidth |
global:Get-RenderedText -panel $panel |
Should -BeLike '*$true | Should -Be $true*'
}
}
Expand Down
69 changes: 41 additions & 28 deletions tests/Get-TitlePanel.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Describe 'Get-TitlePanel' {
BeforeAll {
. (Join-Path $PSScriptRoot 'Helpers.ps1')
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest

Check warning on line 4 in tests/Get-TitlePanel.tests.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (BHPS) Suggestions: (baps, bops, bhp, BHP, bps)
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
Expand All @@ -11,16 +12,8 @@
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop

InModuleScope $env:BHProjectName {
$script:ContainerWidth = 80
$script:ContainerHeight = 5
$size = [Spectre.Console.Size]::new($containerWidth, $containerHeight)
$script:renderOptions = [Spectre.Console.Rendering.RenderOptions]::new(
[Spectre.Console.AnsiConsole]::Console.Profile.Capabilities,
$size
)
$script:renderOptions.Justification = $null
$script:renderOptions.Height = $null
InModuleScope $env:BHProjectname {

Check warning on line 15 in tests/Get-TitlePanel.tests.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (Projectname) Suggestions: (projectile, projective)
$script:pesterResult = Invoke-Pester -PassThru -Path "$PSScriptRoot\fixtures\Example.ps1" -Output 'None'
}
}
It 'should return a Spectre.Console.Panel object' {
Expand All @@ -34,28 +27,48 @@
InModuleScope $env:BHProjectName {
Mock -CommandName 'Get-Date' -MockWith { '2025-01-10 12:00:00' }
$title = Get-TitlePanel
$render = $title.Render($script:renderOptions, $script:ContainerWidth)
# These are rendered segments.
(
'Pester',
'Explorer',
'2025-01-10',
'12:00:00'
) | ForEach-Object {
$render.Text | Should -Contain $_
}
global:Get-RenderedText -Panel $title |
Should -Contain 'Pester Explorer - 2025-01-10 12:00:00'
}
}

It 'should print pester run name and type' {
InModuleScope $env:BHProjectName {
$titleWithItem = Get-TitlePanel -Item $script:pesterResult
$renderWithItem = global:Get-RenderedText -Panel $titleWithItem
$renderWithItem | Should -Match 'Run: . Pester.Run'
}
}

It 'should print container name and type' {
InModuleScope $env:BHProjectName {
$titleWithItem = Get-TitlePanel -Item $script:pesterResult.Containers[0]
$renderWithItem = global:Get-RenderedText -Panel $titleWithItem
$renderWithItem | Should -BeLike '*Container:*Example.ps1'
}
}

It 'should include the Pester object type and name if provided' {
It 'should print block name and type' {
InModuleScope $env:BHProjectName {
$pesterBlock = [Pester.Block]::Create()
$pesterBlock.Name = 'Blockhead'
$pesterBlock.Result = 'Failed'
$titleWithItem = Get-TitlePanel -Item $pesterBlock
$renderWithItem = $titleWithItem.Render($script:renderOptions, $script:ContainerWidth)
$renderWithItem.Text | Should -Contain 'Block:'
$renderWithItem.Text | Should -Contain 'Blockhead'
$titleWithItem = Get-TitlePanel -Item $script:pesterResult.Containers[0].Blocks[0]
$renderWithItem = global:Get-RenderedText -Panel $titleWithItem
$renderWithItem | Should -Match 'Block: . Example Tests'
}
}

Context 'Tests' {
BeforeDiscovery {
$pesterResult = Invoke-Pester -PassThru -Path "$PSScriptRoot\fixtures\Example.ps1" -Output 'None'
$tests = $pesterResult.Containers[0].Blocks[0].Tests
}

It 'should print test name <_>' -ForEach $tests {
InModuleScope $env:BHProjectName -ArgumentList $_ -ScriptBlock {
param($test)
$titleWithItem = Get-TitlePanel -Item $test
$renderWithItem = global:Get-RenderedText -Panel $titleWithItem
$renderWithItem | Should -Match "Test: .*$($test.Name)"
}
}
}
}
50 changes: 45 additions & 5 deletions tests/Helpers.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@

function global:Get-RenderedText {
<#
.SYNOPSIS
Returns the rendered text from a panel object.

.DESCRIPTION
This function processes a panel object to extract and return the rendered
text. It filters out control codes and specific characters, joining the
remaining text segments into a single string.

.PARAMETER Panel
The panel object to be processed. It should have a Render method that
returns a collection of text segments.

.PARAMETER RenderOptions
Options to control the rendering of the panel. This is passed to the Render method of the panel.

.PARAMETER ContainerWidth
The width of the container in which the panel is rendered. This is also passed to the Render method of the panel.

.EXAMPLE
$panel = Get-PanelObject -Name "ExamplePanel"
$renderOptions = Get-RenderOptions -SomeOption "Value"
$containerWidth = 80
$renderedText = global:Get-RenderedText -panel $panel -renderOptions $renderOptions -containerWidth $containerWidth

This example retrieves a panel object, specifies rendering options and
container width, and then calls the function to get the rendered text.
.NOTES
This is a helper function we can use for our tests.
#>
param (
$panel,
$renderOptions,
$containerWidth
[Parameter(Mandatory = $true)]
#[Spectre.Console.Panel]
$Panel,
[Parameter()]
[int]
$ContainerHeight = 200,
[Parameter()]
[int]
$ContainerWidth = 100
)
$size = [Spectre.Console.Size]::new($ContainerWidth, $ContainerHeight)
$renderOptions = [Spectre.Console.Rendering.RenderOptions]::new(
[Spectre.Console.AnsiConsole]::Console.Profile.Capabilities,
$size
)
$render = $panel.Render($renderOptions, $ContainerWidth)
$render = $Panel.Render($RenderOptions, $ContainerWidth)

# These are rendered segments.
$onlyText = $render |
Expand Down
25 changes: 25 additions & 0 deletions tests/fixtures/Example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Describe 'Example Tests' {
BeforeAll {
$script:TestVariable = "Initial Value"
}

It 'should pass' {
$script:TestVariable | Should -Be "Initial Value"
}

It 'should skip this' {
Set-ItResult -Skipped 'This test is skipped intentionally.'
}

It 'should be inconclusive' {
Set-ItResult -Inconclusive 'This test is inconclusive.'
}

It 'should be pending' {
Set-ItResult -Pending 'This test is pending.'
}

AfterAll {
$script:TestVariable = $null
}
}
Loading