Skip to content
22 changes: 4 additions & 18 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your PR description, you wrote:

Make -Path parameter on Start-PSPester the 0th parameter to so that Restore-PSPester $Path works without needing to specify -Path as a named parameter.

I'm confused about the Restore-PSPester $Path part. You are not calling Restore-PSPester with $Path in your change.

Copy link
Contributor Author

@bergmeister bergmeister Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was for easier interactive usage only when running a test locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned about Restore-PSPester $Path in your description, but I don't see how making -Path positional affect your use of Restore-PSPester.

Do you mean without needing to specify -Path for Start-PSPester ?

Copy link
Contributor Author

@bergmeister bergmeister Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad. I meant to write Start-PSPester $Path, you are right. I corrected the PR description

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update your PR description? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. Sorry for that mistake.

[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'),
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions docs/testing-guidelines/testing-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 1 addition & 3 deletions test/powershell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down