Repository navigation
Conversation
Invoke-InNewScriptScope dot-sourced a wrapper bound to the caller's session state, so the wrapper's parameters $p and $d were bound in the caller's current scope. Invoke-Pester replaced the caller's $p with the path to Pester.ScriptScope.ps1 and $d with a hashtable of its own. Calling the wrapper with & gives it its own scope. The script file it runs still pushes the new script scope, as in Invoke-File. 🤖
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3061 +/- ##
=======================================
Coverage ? 91.72%
=======================================
Files ? 2
Lines ? 8359
Branches ? 0
=======================================
Hits ? 7667
Misses ? 692
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Invoke-Pesterreplaced the caller's$pand$dwith Pester internals: the path toPester.ScriptScope.ps1and a hashtable with the scriptblock to run. A script that kept its own path in$pand wrote to it after running tests wrote into Pester's installation instead.The cause is in
Invoke-InNewScriptScope. It dot-sourced its wrapper, which is bound to the caller's session state, so the wrapper's parameters$pand$dwere bound in the caller's current scope.private:does not prevent that.The fix calls the wrapper with
&instead of.. The wrapper gets its own scope, andPester.ScriptScope.ps1still runs as a script file, so the new script scope is still pushed.Invoke-Filealready calls its wrapper this way.Tests added in
tst/Pester.RSpec.ts.ps1:$pand$dkeep their values afterInvoke-Pester;Invoke-Pesterdoes not create$por$din the caller's scope.Both fail without the fix and pass with it.
Local runs on Windows 11:
./test.ps1on PowerShell 7.6.7 with the en-US UI culture: all P tests pass; 2946 Pester tests pass and 1 fails. The same test fails on unmodifiedmainon this machine:Mock.Tests.ps1"mocks without extension and calls with extension", becausenotepadresolves to Git for Windows'usr/bin/notepadhere.tst/Pester.RSpec.ts.ps1on Windows PowerShell 5.1: 130 of 130 pass.Fix #3060
PR Checklist
🤖