Replace usage of $MyInvocation.MyCommand.Path with $PSScriptRoot and cleanup tests as a preparation for Pester v5 by bergmeister · Pull Request #1438 · PowerShell/PSScriptAnalyzer
PR Summary
Pester v5 won't support $MyInvocation.MyCommand.Path in the BeforeAll block any more (in Pester v5 all code will need to be moved into Pester controlled blocks) because of scoping issues, therefore changing to $PSScriptRoot and replacing test variables called $directory with a direct call to it for better readability and easier maintenance.
Also cleanup some tests that import the PSScriptAnalyzerTestHelper.psm1 module only for calling Test-PSEditionCoreCLR, which is just [bool] $IsCoreClr. Therefore inlining this expression for better readability and reduced maintenance. This change would be needed for Pester v5 as well because the -Skip expression is evaluated at discovery time where the module function wouldn't be available.
This will not make the repo ready for Pester v5 yet, this is just the necessary cleanup without making breaking changes.
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix