Skip to content

Commit

Permalink
(#413) Refactor Measure-Koan to use SkipRun
Browse files Browse the repository at this point in the history
Pester v5.2.0 added the ability to natively run just the discovery phase
of a test suite, so we refactor Measure-Koan to utilize this and save
doing a lot of manual work.

This also obsoletes the private Measure-KoanTestBlock command that
previously supported Measure-Koan. Pester automatically does that
calculation on its own before presenting the discovery results. This
command has been removed as a result.
  • Loading branch information
vexx32 committed May 6, 2021
1 parent 0f81b2c commit 3dfd0db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
52 changes: 16 additions & 36 deletions PSKoans/Private/Measure-Koan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,31 @@
)
begin {
$KoanCount = 0
$oldModulePath = $env:PSModulePath

$env:PSModulePath = @(
$MyInvocation.MyCommand.Module.ModuleBase
$env:PSModulePath -split [System.IO.Path]::PathSeparator
) -join [System.IO.Path]::PathSeparator
$configuration = New-PesterConfiguration
$configuration.Output.Verbosity = 'None'
$configuration.Run.SkipRun = $true
$configuration.Run.PassThru = $true
$configuration.Run.TestExtension = ".Koans.ps1"
}
process {
Write-Verbose "Discovering koans in [$($KoanInfo.Name -join '], [')]"
$koanTopics = "[$($KoanInfo.Name -join '], [')]"
Write-Verbose "Discovering koans in $koanTopics"
$configuration.Run.Path = $KoanInfo.Path

$Result = & (Get-Module Pester) {
[CmdletBinding()]
param(
$Path,
$ExcludePath,
$SessionState
)
<#
Null-redirecting stream 6 is necessary because the message about skipping the test run still displays
even if the output verbosity is set to 'None' in Pester 5.2.0.
$_Pester_State_Backup = $state.PSObject.Copy()
$state.Stack = [System.Collections.Stack]@()
try {
Reset-TestSuiteState
Github issue: https://github.com/pester/Pester/issues/1933
#>
$Result = Invoke-Pester -Configuration $configuration 6> $null

# to avoid Describe thinking that we run in interactive mode
$invokedViaInvokePester = $true

$fileList = Find-File -Path $Path -ExcludePath $ExcludePath -Extension '.Koans.ps1'
$containers = foreach ($file in $fileList) {
New-BlockContainerObject -File (Get-Item $file)
}

Find-Test -BlockContainer $containers -SessionState $SessionState
}
finally {
$state = $_Pester_State_Backup
Remove-Variable -Name _Pester_State_Backup
}
} -Path $KoanInfo.Path -SessionState $PSCmdlet.SessionState

$KoanCount += Measure-KoanTestBlock $Result
Write-Debug "Found $($Result.TotalCount) koans in $koanTopics"
$KoanCount += $Result.TotalCount
}
end {
Write-Verbose "Total Koans: $KoanCount"
$KoanCount

$env:PSModulePath = $oldModulePath
}
}
23 changes: 0 additions & 23 deletions PSKoans/Private/Measure-KoanBlockTest.ps1

This file was deleted.

0 comments on commit 3dfd0db

Please sign in to comment.