Skip to content

Commit bee7840

Browse files
authored
Cleanup about_* help topics and extract PesterConfiguration docs to about_PesterConfiguration (#2518) (#2522)
* 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 d73cbe0 commit bee7840

10 files changed

+314
-1085
lines changed

build.ps1

Lines changed: 60 additions & 67 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,45 +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/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
119-
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
120-
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
121-
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
122-
)
123-
}
124-
125-
Copy-Content -Content $content
126-
127-
if ($Clean) {
128-
# update help for New-PesterConfiguration
129-
if ($PSVersionTable.PSVersion.Major -gt 5) {
130-
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/netstandard2.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/netstandard2.0/Pester.dll")
13198
}
13299
else {
133-
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net452/Pester.dll")
100+
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.dll")
134101
}
135102

136103
function Format-NicelyMini ($value) {
@@ -177,49 +144,76 @@ if ($Clean) {
177144
foreach ($r in $section.PSObject.Properties.Name) {
178145
$option = $section.$r
179146
$default = Format-NicelyMini $option.Default
180-
" ${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"
181149
}
182150
}
183151

184-
$p = "$PSScriptRoot/src/Pester.RSpec.ps1"
152+
$helpPath = "$PSScriptRoot/src/en-US/about_PesterConfiguration.help.txt"
185153
# in older versions utf8 means with BOM
186-
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { 'utf8BOM' } else { 'utf8' }
187-
$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 { '' }
188159
$sbf = [System.Text.StringBuilder]''
189160
$generated = $false
190-
foreach ($l in $f) {
191-
if ($l -match '^(?<margin>\s*)Sections and options:\s*$') {
192-
$null = $sbf.AppendLine("$l$eol")
161+
foreach ($line in $helpContent) {
162+
if (-not $generated -and $line -match '^SECTIONS AND OPTIONS\s*$') {
193163
$generated = $true
194-
$margin = $matches.margin
195-
$null = $sbf.AppendLine("$margin``````")
164+
$null = $sbf.AppendLine("$line$eol")
196165

197-
$generatedLines = @($generatedConfig -split $eol)
198-
for ($i = 0; $i -lt $generatedLines.Count; $i++) {
199-
$l = $generatedLines[$i]
166+
foreach ($l in @($generatedConfig -split $eol)) {
200167
$m = if ($l) { $margin } else { $null }
201-
202-
if ($i -eq $generatedLines.Count - 1) {
203-
#last line should be blank - replace with codeblock end
204-
$null = $sbf.AppendLine("$margin``````$eol")
205-
}
206-
else {
207-
$null = $sbf.AppendLine("$m$l")
208-
}
168+
$null = $sbf.AppendLine("$m$l")
209169
}
210170
}
211-
elseif ($generated -and ($l -match '^\s*(.PARAMETER|.EXAMPLE).*')) {
171+
elseif ($generated -and ($line -cmatch '^SEE ALSO\s*$')) {
212172
$generated = $false
213173
}
214174

215175
if (-not $generated) {
216-
$null = $sbf.AppendLine($l)
176+
$null = $sbf.AppendLine($line)
217177
}
218178
}
219179

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

222-
# 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/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
207+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
208+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
209+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
210+
)
211+
}
212+
213+
Copy-Content -Content $content
214+
215+
if ($Clean) {
216+
# Generate PesterConfiguration.Format.ps1xml to ensure list view for all sections
223217
$configSections = $configObject.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
224218
# Get internal ctor as public ctor always returns instanceId = zero guid prior to PS v7.1.0
225219
$formatViewCtor = [System.Management.Automation.FormatViewDefinition].GetConstructors('Instance,NonPublic')
@@ -237,7 +231,7 @@ if ($Clean) {
237231

238232
# Create view for Option to ensure Table and hide IsModified
239233
$builder = [System.Management.Automation.TableControl]::Create().StartRowDefinition()
240-
[Pester.Option[bool]].GetProperties() | Where-Object Name -notin 'IsModified' | ForEach-Object {
234+
[Pester.Option[bool]].GetProperties() | Where-Object Name -NotIn 'IsModified' | ForEach-Object {
241235
$builder.AddPropertyColumn($_.Name, [System.Management.Automation.Alignment]::Undefined, $null) > $null
242236
}
243237
$tableControl = $builder.EndRowDefinition().EndTable()
@@ -249,12 +243,12 @@ if ($Clean) {
249243
Export-FormatData -InputObject $typeDefs -Path "$PSScriptRoot/bin/PesterConfiguration.Format.ps1xml"
250244
}
251245

252-
if (-not $PSBoundParameters.ContainsKey("Inline")) {
246+
if (-not $PSBoundParameters.ContainsKey('Inline')) {
253247
# Force inlining by env variable, build.ps1 is used in
254248
# multiple places and passing the $inline everywhere is
255249
# difficult.
256250
# Only read this option here. Don't write it.
257-
if ($env:PESTER_BUILD_INLINE -eq "1") {
251+
if ($env:PESTER_BUILD_INLINE -eq '1') {
258252
$Inline = $true
259253
}
260254
else {
@@ -268,7 +262,6 @@ else {
268262
$env:PESTER_BUILD_INLINE = [string][int][bool] $Inline
269263
}
270264

271-
272265
$null = New-Item "$PSScriptRoot/bin" -ItemType Directory -Force
273266

274267
$script = @(

publish/release.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ $files = @(
6464
'bin/net452/Pester.pdb'
6565
'bin/netstandard2.0/Pester.dll'
6666
'bin/netstandard2.0/Pester.pdb'
67-
'en-US/about_BeforeEach_AfterEach.help.txt'
68-
'en-US/about_Mocking.help.txt'
6967
'en-US/about_Pester.help.txt'
70-
'en-US/about_Should.help.txt'
71-
'en-US/about_TestDrive.help.txt'
68+
'en-US/about_PesterConfiguration.help.txt'
7269
'schemas/JaCoCo/report.dtd'
7370
'schemas/JUnit4/junit_schema_4.xsd'
7471
'schemas/NUnit25/nunit_schema_2.5.xsd'

src/Main.ps1

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,8 @@ function Invoke-Pester {
419419
https://github.com/danielpalme/ReportGenerator
420420
421421
.PARAMETER Configuration
422-
(Introduced v5)
423-
[PesterConfiguration] object for Advanced Configuration
424-
425-
Pester supports Simple and Advanced Configuration.
426-
427-
Invoke-Pester -Configuration <PesterConfiguration> [<CommonParameters>]
428-
429-
Default is New-PesterConfiguration.
430-
431-
For help on each option see New-PesterConfiguration, or inspect the object it returns.
422+
[PesterConfiguration] object for Advanced Configuration created using `New-PesterConfiguration`.
423+
For help on each option see about_PesterConfiguration or inspect the object.
432424
433425
.PARAMETER Container
434426
Specifies one or more ContainerInfo-objects that define containers with tests.
@@ -571,7 +563,7 @@ function Invoke-Pester {
571563
even if the first fails.
572564
573565
.EXAMPLE
574-
$config = [PesterConfiguration]::Default
566+
$config = New-PesterConfiguration
575567
$config.TestResult.Enabled = $true
576568
Invoke-Pester -Configuration $config
577569

src/Pester.RSpec.ps1

Lines changed: 5 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -288,151 +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. 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: EXPERIMENTAL: When false, use Profiler based tracer to do CodeCoverage instead of using breakpoints.
367-
Default value: $true
368-
369-
SingleHitBreakpoints: Remove breakpoint when it is hit.
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-
Debug:
393-
ShowFullErrors: Show full errors including Pester internal stack. This property is deprecated, and if set to true it will override Output.StackTraceVerbosity to 'Full'.
394-
Default value: $false
395-
396-
WriteDebugMessages: Write Debug messages to screen.
397-
Default value: $false
398-
399-
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.
400-
Default value: @('Discovery', 'Skip', 'Mock', 'CodeCoverage')
401-
402-
ShowNavigationMarkers: Write paths after every block and test, for easy navigation in VSCode.
403-
Default value: $false
404-
405-
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.
406-
Default value: $false
407-
408-
Output:
409-
Verbosity: The verbosity of output, options are None, Normal, Detailed and Diagnostic.
410-
Default value: 'Normal'
411-
412-
StackTraceVerbosity: The verbosity of stacktrace output, options are None, FirstLine, Filtered and Full.
413-
Default value: 'Filtered'
414-
415-
CIFormat: The CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions.
416-
Default value: 'Auto'
417-
418-
CILogLevel: The CI log level in build logs, options are Error and Warning.
419-
Default value: 'Error'
420-
421-
RenderMode: The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext.
422-
Default value: 'Auto'
423-
424-
TestDrive:
425-
Enabled: Enable TestDrive.
426-
Default value: $true
427-
428-
TestRegistry:
429-
Enabled: Enable TestRegistry.
430-
Default value: $true
431-
```
291+
For a complete list of options, see `Get-Help about_PesterConfiguration` or https://pester.dev/docs/usage/configuration
432292
433293
.PARAMETER Hashtable
434294
Override the default values for the options defined in the provided dictionary/hashtable.
435-
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
436296
available options.
437297
438298
.EXAMPLE
@@ -476,6 +336,9 @@ function New-PesterConfiguration {
476336
477337
.LINK
478338
https://pester.dev/docs/commands/Invoke-Pester
339+
340+
.LINK
341+
about_PesterConfiguration
479342
#>
480343
[CmdletBinding()]
481344
param(

0 commit comments

Comments
 (0)