-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make Start-PSPester more user friendly by calling Restore-Pester automatically when needed and not having to specify -Path as a named parameter for Start-PSPester #7210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…o RestorePesterAutomatically
…without having to specify -Path
| # Restore the Pester module | ||
| if ($CI) { | ||
| Restore-PSPester -Destination (Join-Path $publishPath "Modules") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is still useful -- I want to build powershell and then manually run some Pester tests, but not Start-PSPester. In this case, I can run Start-PSBuild -Clean -CI and Pester will be installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I misunderstood the usage of this line by making the assumption that the function is only useful for Start-PSPester. Because I made Start-PSPester restore Pester if needed, I thought, I could remove this line. I would be happy to revert this change but would also be interested in why one would want/need Pester to be installed when building PowerShell (my guess is that your use case is to call Start-DevPowerShell and run the pester test from there?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also be interested in why one would want/need Pester to be installed when building PowerShell (my guess is that your use case is to call Start-DevPowerShell and run the pester test from there?)
When I'm wringing Pester tests for some code changes and just want to run the tests I'm working on, I would build the code base, start pwsh from the bin folder, and run Invoke-Pester -Script <path-of-my-test-file>. Or when I'm investigating a test failure from daily build, I might want to sync master branch, build, start the pwsh produced from the build, run Invoke-Pester with the file where the test fails.
Sure, we can install Pester to user module path, so it will always be available, but install the Pester module while build powershell could be useful in case you don't have Pester in other module paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see. I will revert this change then.
When I run tests locally, then my workflow is Start-PSBuild ... and then Start-PSPester $TestFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sometimes I expect some of my tests to fail initially, and it's easier for me to keep the pwsh instance around for some ad-hoc verifications.
| [CmdletBinding(DefaultParameterSetName='default')] | ||
| param( | ||
| [Parameter(Position=0)] | ||
| [string[]]$Path = @("$PSScriptRoot/test/common","$PSScriptRoot/test/powershell"), |
There was a problem hiding this comment.
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
-Pathparameter onStart-PSPesterthe 0th parameter to so thatRestore-PSPester $Pathworks 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
build.psm1
Outdated
|
|
||
| $getModuleResults = Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | ||
| if (-not $getModuleResults) | ||
| if (-not ($getModuleResults | Where-Object { $_.Version -ge "4.2" } )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving Where-Object part after the Get-Module call? Like Get-Module ... | Where-Object .... Then the if check would be simpler to read here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
|
Restarted Travis CI build because of this error on Mac: |
PR Summary
Start-PSPesterautomatically callRestore-PSPesterwhen needed. This simplifies it and reduces manual steps when running it interactively (I tend to usegit clean -dfxorStart-PSBuild -Cleanrelatively often as I do not work with the code base every day). I am running Pester tests usually usingStart-PSPester-Pathparameter onStart-PSPesterthe 0th parameter to so thatStart-PSPester$Path works without needing to specify-Pathas a named parameter (useful when using the cmdlet interactively for running tests locally). Yes, I know, named parameters should be encouraged but for cmdlets that are used interactively a lot and where mostly just one parameter is used, I think it is fine and I rather prefer the lazy option in this case (PSSA 'allows' for up to 3 parameters to be not named before warning btw).PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests