Update 'Start-PSPester' to make it more user friendly (#7210)

- Make `Start-PSPester` call `Restore-Pester` automatically when needed,
- Make `-Path` a positional parameter for `Start-PSPester`.
This commit is contained in:
Christoph Bergmeister 2018-07-03 19:16:37 +01:00 committed by Dongbo Wang
parent 55bbc3fcd1
commit 56e50ce632
3 changed files with 5 additions and 24 deletions

View file

@ -981,11 +981,12 @@ function Publish-PSTestTools {
function Start-PSPester {
[CmdletBinding(DefaultParameterSetName='default')]
param(
[Parameter(Position=0)]
[string[]]$Path = @("$PSScriptRoot/test/common","$PSScriptRoot/test/powershell"),
[string]$OutputFormat = "NUnitXml",
[string]$OutputFile = "pester-tests.xml",
[string[]]$ExcludeTag = 'Slow',
[string[]]$Tag = @("CI","Feature"),
[string[]]$Path = @("$PSScriptRoot/test/common","$PSScriptRoot/test/powershell"),
[switch]$ThrowOnFailure,
[string]$binDir = (Split-Path (Get-PSOptions -DefaultToNew).Output),
[string]$powershell = (Join-Path $binDir 'pwsh'),
@ -1001,24 +1002,9 @@ function Start-PSPester {
[switch]$IncludeFailingTest
)
$getModuleResults = Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue
if (-not $getModuleResults)
if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge "4.2" } ))
{
Write-Warning @"
Pester module not found.
Restore the module to '$Pester' by running:
Restore-PSPester
"@
return;
}
if (-not ($getModuleResults | Where-Object { $_.Version -ge "4.2" } )) {
Write-Warning @"
No Pester module of version 4.2 and higher.
Restore the required module version to '$Pester' by running:
Restore-PSPester
"@
return;
Restore-PSPester
}
if ($IncludeFailingTest.IsPresent)

View file

@ -108,14 +108,11 @@ Currently, we have a minuscule number of tests which are run by using xUnit.
When working on new features or fixes, it is natural to want to run those tests locally before making a PR.
Three helper functions are part of the build.psm1 module to help with that:
* `Restore-PSPester` will restore Pester, which is needed to run `Start-PSPester`
* `Start-PSPester` will execute all Pester tests which are run by the CI system
* `Start-PSxUnit` will execute the available xUnit tests run by the CI system
Our CI system runs these as well; there should be no difference between running these on your dev system, versus in CI.
Make sure that you run `Restore-PSPester` before running `Start-PSPester`, or it will fail to run.
When running tests in this way, be sure that you have started PowerShell with `-noprofile` as some tests will fail if the
environment is not the default or has any customization.

View file

@ -5,9 +5,7 @@ document.
## Running Pester Tests
First, restore the correct version of Pester using `Restore-PSPester`.
Then, go to the top level of the PowerShell repository and run: `Start-PSPester`
Go to the top level of the PowerShell repository and run: `Start-PSPester`
inside a self-hosted copy of PowerShell.
You can use `Start-PSPester -Tests SomeTestSuite*` to limit the tests run.