Make Plugins public
Review and improve the api of Pester plugins, to be well factored. Think about how each extension point could be used, and how we could extend the api in the future.
Then expose the plugins publicly, and think about how others could register theirs. Especially when they would like to inject them in the middle of our plugins, or replace ours with theirs. And how they would get config.
replace ours with theirs. And how they would get config.
The config part is important 👍 We soon (if not already) have configuration options to disable most built-in plugins (only Mock left in 5.3.0?
So third party plugins should rely on their own config-options.
As requested in #2020, just to let you know I'm now using the additionalPlugins to workaround code coverage configuration. It ain't pretty, and perhaps I'm missing something but I cannot find a way to make get StartLine/EndLine/... from Invoke-Pester into Enter-CoverageAnalysis; the legacy parameter set doesn't accept a hashtable for -CodeCoverage (well it does but it turns it into the string "System.Collections.HashTable") and PesterConfiguration.CodeCoverage only has Paths and enforces that to be a string array. So now I'm doing something like this:
$ccPlug = & (Get-Module Pester) {Get-CoveragePlugin}
$ccPlugStart = $ccPlug.RunStart
$ccPlugEnd = $ccPlug.End
$ccPlug.RunStart = {
param($Context)
$Context.Configuration['Coverage'] = @{
Enabled = $True
OutputFormat = 'JaCoCo'
OutputPath = (Join-Path $PSScriptRoot 'coverage.xml')
OutputEncoding = 'UTF8'
Path = 'MyFile.ps1'
StartLine = 0
EndLine = 150
ExcludeTests = $True
RecursePaths = $True
CoveragePercentTarget = 75
UseBreakpoints = $True
UseSingleHitBreakpoints = $True
}
& $ccPlugStart $Context
}
$ccPlug.End = {
param($Context)
& $ccPlugEnd $Context
# Make pester do the post-processing now.
$Context.TestRun.Configuration.CodeCoverage.Enabled = $True
}
& (Get-Module Pester) {
$Script:additionalPlugins = $ccPlug
}
Notes:
- ideally I'd like to specify an array of path/startline/endline and while Enter-CoverageAnalysis supports that since it takes such array, the way Get-CoveragePlugin calls it only supports one single configuration object:
Enter-CoverageAnalysis -CodeCoverage $config -Logger $logger -UseBreakpoints $config.UseBreakpoints - https://github.com/pester/Pester/search?q=ExcludeTests is declared but not used anywhere? Get-CoverageInfoFromUserInput only refers to
IncludeTests
After writing the above I realize it's perhaps better to report this as a bunch separate issues, but I'm new to Pester so perhaps all of this is known already? Otherwise let me know how to proceed.
For reference, the Pester Tests adapter utilizes this API to report test results in real time so it doesn't have to wait for the final output or interpret text output. https://github.com/pester/vscode-adapter/blob/ebfe917658cf2a310ea0520d42b57ef54d54fb26/Scripts/PesterInterface.ps1#L60-L80