Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Plugins public #2021

Open
nohwnd opened this issue Jul 2, 2021 · 3 comments
Open

Make Plugins public #2021

nohwnd opened this issue Jul 2, 2021 · 3 comments
Labels
Milestone

Comments

@nohwnd
Copy link
Member

nohwnd commented Jul 2, 2021

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.

@fflaten
Copy link
Collaborator

fflaten commented Jul 2, 2021

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.

@stinos
Copy link

stinos commented Nov 8, 2021

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.

@JustinGrote
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants