diff --git a/build.psm1 b/build.psm1 index e060ee1437e..04749c78db0 100644 --- a/build.psm1 +++ b/build.psm1 @@ -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) diff --git a/docs/testing-guidelines/testing-guidelines.md b/docs/testing-guidelines/testing-guidelines.md index 92072071e94..bc9b1a97ab1 100755 --- a/docs/testing-guidelines/testing-guidelines.md +++ b/docs/testing-guidelines/testing-guidelines.md @@ -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. diff --git a/test/powershell/README.md b/test/powershell/README.md index 5fd340a5e5c..4e8f1f4c78e 100644 --- a/test/powershell/README.md +++ b/test/powershell/README.md @@ -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.