Skip to content

Commit 6754b26

Browse files
authored
Cleanup about_* help topics and extract PesterConfiguration docs to about_PesterConfiguration (#2518)
* Remove outdated docs * Include option types in PesterConfiguration docs * Add draft for about_PesterConfiguration help topic * Move PesterConfiguration options reference to help topic * Minor text updates * wip * Update Invoke-Pester help for Configuration * Update build script * Update help for Invoke-Pester -Configuration * Fix build script * Update about_Pester.help.txt * Update release script
1 parent 718ba6d commit 6754b26

10 files changed

+316
-1085
lines changed

build.ps1

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ if ($Clean -and (Test-Path "$PSScriptRoot/bin")) {
7676
}
7777

7878
if ($Clean) {
79-
# Import-LocalizedData (and ModuleVersion-property) used as workaround due to unknown error on PS3 build with Test-ModuleManifest
80-
# and because Test-ModuleManifest needs the psd1 and psm1 to be complete, but we want to generate help for config from the type
81-
# so we need to build up here, and not after the module build, so xml based solution is better than one that validates the manifest
79+
# Using Import-LocalizedData over Test-ModuleManifest because the latter requires psm1 and
80+
# PesterConfiguration.Format.xml to exists which are both generated later in build script
8281
$manifest = Import-LocalizedData -FileName 'Pester.psd1' -BaseDirectory "$PSScriptRoot/src"
8382
if (-not $LockedRestore) {
8483
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln"
@@ -92,43 +91,13 @@ if ($Clean) {
9291
}
9392
}
9493

95-
function Copy-Content ($Content) {
96-
foreach ($c in $content) {
97-
$source, $destination = $c
98-
99-
$null = New-Item -Force $destination -ItemType Directory
100-
101-
Get-ChildItem $source -File | Copy-Item -Destination $destination
102-
}
103-
}
104-
105-
$content = @(
106-
, ("$PSScriptRoot/src/en-US/*.txt", "$PSScriptRoot/bin/en-US/")
107-
, ("$PSScriptRoot/src/Pester.ps1", "$PSScriptRoot/bin/")
108-
, ("$PSScriptRoot/src/Pester.psd1", "$PSScriptRoot/bin/")
109-
, ("$PSScriptRoot/src/Pester.Format.ps1xml", "$PSScriptRoot/bin/")
110-
)
111-
11294
if ($Clean) {
113-
$content += @(
114-
, ("$PSScriptRoot/src/schemas/JUnit4/*.xsd", "$PSScriptRoot/bin/schemas/JUnit4/")
115-
, ("$PSScriptRoot/src/schemas/NUnit25/*.xsd", "$PSScriptRoot/bin/schemas/NUnit25/")
116-
, ("$PSScriptRoot/src/schemas/NUnit3/*.xsd", "$PSScriptRoot/bin/schemas/NUnit3/")
117-
, ("$PSScriptRoot/src/schemas/JaCoCo/*.dtd", "$PSScriptRoot/bin/schemas/JaCoCo/")
118-
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll", "$PSScriptRoot/bin/bin/net462/")
119-
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll", "$PSScriptRoot/bin/bin/net6.0/")
120-
)
121-
}
122-
123-
Copy-Content -Content $content
124-
125-
if ($Clean) {
126-
# update help for New-PesterConfiguration
127-
if ($PSVersionTable.PSVersion.Major -gt 5) {
128-
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net6.0/Pester.dll")
95+
# Update PesterConfiguration help in about_PesterConfiguration
96+
if ($PSVersionTable.PSVersion.Major -ge 6) {
97+
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll")
12998
}
13099
else {
131-
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net462/Pester.dll")
100+
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll")
132101
}
133102

134103
function Format-NicelyMini ($value) {
@@ -175,49 +144,74 @@ if ($Clean) {
175144
foreach ($r in $section.PSObject.Properties.Name) {
176145
$option = $section.$r
177146
$default = Format-NicelyMini $option.Default
178-
" ${r}: $($option.Description)$eol Default value: ${default}$eol"
147+
$type = $option.Default.GetType() -as [string]
148+
" ${r}: $($option.Description)$eol Type: ${type}$eol Default value: ${default}$eol"
179149
}
180150
}
181151

182-
$p = "$PSScriptRoot/src/Pester.RSpec.ps1"
152+
$helpPath = "$PSScriptRoot/src/en-US/about_PesterConfiguration.help.txt"
183153
# in older versions utf8 means with BOM
184-
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { 'utf8BOM' } else { 'utf8' }
185-
$f = Get-Content $p -Encoding $e
154+
$enc = if ($PSVersionTable.PSVersion.Major -ge 7) { 'utf8BOM' } else { 'utf8' }
155+
$helpContent = Get-Content $helpPath -Encoding $enc
156+
157+
# Get section margin from the topic name on line 2
158+
$margin = if ($helpContent[1] -match '^(?<margin>\s*)about_') { $matches.margin } else { '' }
186159
$sbf = [System.Text.StringBuilder]''
187160
$generated = $false
188-
foreach ($l in $f) {
189-
if ($l -match '^(?<margin>\s*)Sections and options:\s*$') {
190-
$null = $sbf.AppendLine("$l$eol")
161+
foreach ($line in $helpContent) {
162+
if (-not $generated -and $line -match '^SECTIONS AND OPTIONS\s*$') {
191163
$generated = $true
192-
$margin = $matches.margin
193-
$null = $sbf.AppendLine("$margin``````")
164+
$null = $sbf.AppendLine("$line$eol")
194165

195-
$generatedLines = @($generatedConfig -split $eol)
196-
for ($i = 0; $i -lt $generatedLines.Count; $i++) {
197-
$l = $generatedLines[$i]
166+
foreach ($l in @($generatedConfig -split $eol)) {
198167
$m = if ($l) { $margin } else { $null }
199-
200-
if ($i -eq $generatedLines.Count - 1) {
201-
#last line should be blank - replace with codeblock end
202-
$null = $sbf.AppendLine("$margin``````$eol")
203-
}
204-
else {
205-
$null = $sbf.AppendLine("$m$l")
206-
}
168+
$null = $sbf.AppendLine("$m$l")
207169
}
208170
}
209-
elseif ($generated -and ($l -match '^\s*(.PARAMETER|.EXAMPLE).*')) {
171+
elseif ($generated -and ($line -cmatch '^SEE ALSO\s*$')) {
210172
$generated = $false
211173
}
212174

213175
if (-not $generated) {
214-
$null = $sbf.AppendLine($l)
176+
$null = $sbf.AppendLine($line)
215177
}
216178
}
217179

218-
Set-Content -Encoding $e -Value $sbf.ToString().TrimEnd() -Path $p
180+
Set-Content -Encoding $enc -Value $sbf.ToString().TrimEnd() -Path $helpPath
181+
}
219182

220-
# generate PesterConfiguration.Format.ps1xml to ensure list view for all sections
183+
function Copy-Content ($Content) {
184+
foreach ($c in $content) {
185+
$source, $destination = $c
186+
187+
$null = New-Item -Force $destination -ItemType Directory
188+
189+
Get-ChildItem $source -File | Copy-Item -Destination $destination
190+
}
191+
}
192+
193+
$content = @(
194+
, ("$PSScriptRoot/src/en-US/*.txt", "$PSScriptRoot/bin/en-US/")
195+
, ("$PSScriptRoot/src/Pester.ps1", "$PSScriptRoot/bin/")
196+
, ("$PSScriptRoot/src/Pester.psd1", "$PSScriptRoot/bin/")
197+
, ("$PSScriptRoot/src/Pester.Format.ps1xml", "$PSScriptRoot/bin/")
198+
)
199+
200+
if ($Clean) {
201+
$content += @(
202+
, ("$PSScriptRoot/src/schemas/JUnit4/*.xsd", "$PSScriptRoot/bin/schemas/JUnit4/")
203+
, ("$PSScriptRoot/src/schemas/NUnit25/*.xsd", "$PSScriptRoot/bin/schemas/NUnit25/")
204+
, ("$PSScriptRoot/src/schemas/NUnit3/*.xsd", "$PSScriptRoot/bin/schemas/NUnit3/")
205+
, ("$PSScriptRoot/src/schemas/JaCoCo/*.dtd", "$PSScriptRoot/bin/schemas/JaCoCo/")
206+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll", "$PSScriptRoot/bin/bin/net462/")
207+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll", "$PSScriptRoot/bin/bin/net6.0/")
208+
)
209+
}
210+
211+
Copy-Content -Content $content
212+
213+
if ($Clean) {
214+
# Generate PesterConfiguration.Format.ps1xml to ensure list view for all sections
221215
$configSections = $configObject.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
222216
# Get internal ctor as public ctor always returns instanceId = zero guid prior to PS v7.1.0
223217
$formatViewCtor = [System.Management.Automation.FormatViewDefinition].GetConstructors('Instance,NonPublic')
@@ -235,7 +229,7 @@ if ($Clean) {
235229

236230
# Create view for Option to ensure Table and hide IsModified
237231
$builder = [System.Management.Automation.TableControl]::Create().StartRowDefinition()
238-
[Pester.Option[bool]].GetProperties() | Where-Object Name -notin 'IsModified' | ForEach-Object {
232+
[Pester.Option[bool]].GetProperties() | Where-Object Name -NotIn 'IsModified' | ForEach-Object {
239233
$builder.AddPropertyColumn($_.Name, [System.Management.Automation.Alignment]::Undefined, $null) > $null
240234
}
241235
$tableControl = $builder.EndRowDefinition().EndTable()
@@ -247,12 +241,12 @@ if ($Clean) {
247241
Export-FormatData -InputObject $typeDefs -Path "$PSScriptRoot/bin/PesterConfiguration.Format.ps1xml"
248242
}
249243

250-
if (-not $PSBoundParameters.ContainsKey("Inline")) {
244+
if (-not $PSBoundParameters.ContainsKey('Inline')) {
251245
# Force inlining by env variable, build.ps1 is used in
252246
# multiple places and passing the $inline everywhere is
253247
# difficult.
254248
# Only read this option here. Don't write it.
255-
if ($env:PESTER_BUILD_INLINE -eq "1") {
249+
if ($env:PESTER_BUILD_INLINE -eq '1') {
256250
$Inline = $true
257251
}
258252
else {
@@ -266,7 +260,6 @@ else {
266260
$env:PESTER_BUILD_INLINE = [string][int][bool] $Inline
267261
}
268262

269-
270263
$null = New-Item "$PSScriptRoot/bin" -ItemType Directory -Force
271264

272265
$script = @(

publish/release.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ $files = @(
6262
'PesterConfiguration.Format.ps1xml'
6363
'bin/net462/Pester.dll'
6464
'bin/net6.0/Pester.dll'
65-
'en-US/about_BeforeEach_AfterEach.help.txt'
66-
'en-US/about_Mocking.help.txt'
6765
'en-US/about_Pester.help.txt'
68-
'en-US/about_Should.help.txt'
69-
'en-US/about_TestDrive.help.txt'
66+
'en-US/about_PesterConfiguration.help.txt'
7067
'schemas/JaCoCo/report.dtd'
7168
'schemas/JUnit4/junit_schema_4.xsd'
7269
'schemas/NUnit25/nunit_schema_2.5.xsd'

src/Main.ps1

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,8 @@ function Invoke-Pester {
400400
https://github.com/danielpalme/ReportGenerator
401401
402402
.PARAMETER Configuration
403-
(Introduced v5)
404-
[PesterConfiguration] object for Advanced Configuration
405-
406-
Pester supports Simple and Advanced Configuration.
407-
408-
Invoke-Pester -Configuration <PesterConfiguration> [<CommonParameters>]
409-
410-
Default is New-PesterConfiguration.
411-
412-
For help on each option see New-PesterConfiguration, or inspect the object it returns.
403+
[PesterConfiguration] object for Advanced Configuration created using `New-PesterConfiguration`.
404+
For help on each option see about_PesterConfiguration or inspect the object.
413405
414406
.PARAMETER Container
415407
Specifies one or more ContainerInfo-objects that define containers with tests.
@@ -552,7 +544,7 @@ function Invoke-Pester {
552544
even if the first fails.
553545
554546
.EXAMPLE
555-
$config = [PesterConfiguration]::Default
547+
$config = New-PesterConfiguration
556548
$config.TestResult.Enabled = $true
557549
Invoke-Pester -Configuration $config
558550

src/Pester.RSpec.ps1

Lines changed: 5 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -288,154 +288,11 @@ function New-PesterConfiguration {
288288
289289
Calling New-PesterConfiguration is equivalent to calling [PesterConfiguration]::Default which was used in early versions of Pester 5.
290290
291-
Sections and options:
292-
293-
```
294-
Run:
295-
Path: Directories to be searched for tests, paths directly to test files, or combination of both.
296-
Default value: @('.')
297-
298-
ExcludePath: Directories or files to be excluded from the run.
299-
Default value: @()
300-
301-
ScriptBlock: ScriptBlocks containing tests to be executed.
302-
Default value: @()
303-
304-
Container: ContainerInfo objects containing tests to be executed.
305-
Default value: @()
306-
307-
TestExtension: Filter used to identify test files.
308-
Default value: '.Tests.ps1'
309-
310-
Exit: Exit with non-zero exit code when the test run fails. Exit code is always set to `$LASTEXITCODE` even when this option is `$false`. When used together with Throw, throwing an exception is preferred.
311-
Default value: $false
312-
313-
Throw: Throw an exception when test run fails. When used together with Exit, throwing an exception is preferred.
314-
Default value: $false
315-
316-
PassThru: Return result object to the pipeline after finishing the test run.
317-
Default value: $false
318-
319-
SkipRun: Runs the discovery phase but skips run. Use it with PassThru to get object populated with all tests.
320-
Default value: $false
321-
322-
SkipRemainingOnFailure: Skips remaining tests after failure for selected scope, options are None, Run, Container and Block.
323-
Default value: 'None'
324-
325-
Filter:
326-
Tag: Tags of Describe, Context or It to be run.
327-
Default value: @()
328-
329-
ExcludeTag: Tags of Describe, Context or It to be excluded from the run.
330-
Default value: @()
331-
332-
Line: Filter by file and scriptblock start line, useful to run parsed tests programmatically to avoid problems with expanded names. Explicit filter that overrides -Skip. Example: 'C:\tests\file1.Tests.ps1:37'
333-
Default value: @()
334-
335-
ExcludeLine: Exclude by file and scriptblock start line, takes precedence over Line.
336-
Default value: @()
337-
338-
FullName: Full name of test with -like wildcards, joined by dot. Example: '*.describe Get-Item.test1'
339-
Default value: @()
340-
341-
CodeCoverage:
342-
Enabled: Enable CodeCoverage.
343-
Default value: $false
344-
345-
OutputFormat: Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters
346-
Default value: 'JaCoCo'
347-
348-
OutputPath: Path relative to the current directory where code coverage report is saved.
349-
Default value: 'coverage.xml'
350-
351-
OutputEncoding: Encoding of the output file.
352-
Default value: 'UTF8'
353-
354-
Path: Directories or files to be used for code coverage, by default the Path(s) from general settings are used, unless overridden here.
355-
Default value: @()
356-
357-
ExcludeTests: Exclude tests from code coverage. This uses the TestFilter from general configuration.
358-
Default value: $true
359-
360-
RecursePaths: Will recurse through directories in the Path option.
361-
Default value: $true
362-
363-
CoveragePercentTarget: Target percent of code coverage that you want to achieve, default 75%.
364-
Default value: 75
365-
366-
UseBreakpoints: When false, use Profiler based tracer to do CodeCoverage instead of using breakpoints.
367-
Default value: $false
368-
369-
SingleHitBreakpoints: Remove breakpoint when it is hit. This increases performance of breakpoint based CodeCoverage.
370-
Default value: $true
371-
372-
TestResult:
373-
Enabled: Enable TestResult.
374-
Default value: $false
375-
376-
OutputFormat: Format to use for test result report. Possible values: NUnitXml, NUnit2.5, NUnit3 or JUnitXml
377-
Default value: 'NUnitXml'
378-
379-
OutputPath: Path relative to the current directory where test result report is saved.
380-
Default value: 'testResults.xml'
381-
382-
OutputEncoding: Encoding of the output file.
383-
Default value: 'UTF8'
384-
385-
TestSuiteName: Set the name assigned to the root 'test-suite' element.
386-
Default value: 'Pester'
387-
388-
Should:
389-
ErrorAction: Controls if Should throws on error. Use 'Stop' to throw on error, or 'Continue' to fail at the end of the test.
390-
Default value: 'Stop'
391-
392-
DisableV5: Disables usage of Should -Be assertions, that are replaced by Should-Be in version 6.
393-
Default value: $false
394-
395-
Debug:
396-
ShowFullErrors: Show full errors including Pester internal stack. This property is deprecated, and if set to true it will override Output.StackTraceVerbosity to 'Full'.
397-
Default value: $false
398-
399-
WriteDebugMessages: Write Debug messages to screen.
400-
Default value: $false
401-
402-
WriteDebugMessagesFrom: Write Debug messages from a given source, WriteDebugMessages must be set to true for this to work. You can use like wildcards to get messages from multiple sources, as well as * to get everything.
403-
Default value: @('Discovery', 'Skip', 'Mock', 'CodeCoverage')
404-
405-
ShowNavigationMarkers: Write paths after every block and test, for easy navigation in VSCode.
406-
Default value: $false
407-
408-
ReturnRawResultObject: Returns unfiltered result object, this is for development only. Do not rely on this object for additional properties, non-public properties will be renamed without previous notice.
409-
Default value: $false
410-
411-
Output:
412-
Verbosity: The verbosity of output, options are None, Normal, Detailed and Diagnostic.
413-
Default value: 'Normal'
414-
415-
StackTraceVerbosity: The verbosity of stacktrace output, options are None, FirstLine, Filtered and Full.
416-
Default value: 'Filtered'
417-
418-
CIFormat: The CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions.
419-
Default value: 'Auto'
420-
421-
CILogLevel: The CI log level in build logs, options are Error and Warning.
422-
Default value: 'Error'
423-
424-
RenderMode: The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext.
425-
Default value: 'Auto'
426-
427-
TestDrive:
428-
Enabled: Enable TestDrive.
429-
Default value: $true
430-
431-
TestRegistry:
432-
Enabled: Enable TestRegistry.
433-
Default value: $true
434-
```
291+
For a complete list of options, see `Get-Help about_PesterConfiguration` or https://pester.dev/docs/usage/configuration
435292
436293
.PARAMETER Hashtable
437294
Override the default values for the options defined in the provided dictionary/hashtable.
438-
See Description in this help or inspect a PesterConfiguration-object to learn about the schema and
295+
See about_PesterConfiguration help topic or inspect a PesterConfiguration-object to learn about the schema and
439296
available options.
440297
441298
.EXAMPLE
@@ -479,6 +336,9 @@ function New-PesterConfiguration {
479336
480337
.LINK
481338
https://pester.dev/docs/commands/Invoke-Pester
339+
340+
.LINK
341+
about_PesterConfiguration
482342
#>
483343
[CmdletBinding()]
484344
param(

0 commit comments

Comments
 (0)