Drop Run.BeforeContainer option, keep the Pester.BeforeContainer.ps1 convention#2859
Draft
nohwnd wants to merge 1 commit into
Draft
Drop Run.BeforeContainer option, keep the Pester.BeforeContainer.ps1 convention#2859nohwnd wants to merge 1 commit into
nohwnd wants to merge 1 commit into
Conversation
The experimental BeforeContainer bootstrap had two entry points: the Run.BeforeContainer scriptblock[] configuration option and a repo-root Pester.BeforeContainer.ps1 convention file. Having both created an inconsistent story for anchoring relative paths - the file always has a stable $PSScriptRoot/$PSCommandPath, while the scriptblock option only had the unstable $pwd and no file to anchor from. Remove the configuration option and keep only the zero-config convention file resolved from Run.RepoRoot, dot-sourced before each container in both sequential and parallel runs. This leaves a single, consistent mechanism. - Remove the BeforeContainer option (field, ctor assignment, default and property) from RunConfiguration.cs; document the convention file on the RepoRoot option instead. about_PesterConfiguration help regenerated. - Resolve-PesterBeforeContainer now resolves only the convention file. - Update comments in Main.ps1, Pester.Runtime.ps1 and Invoke-TestInParallel. - Tests: replace the explicit-option cases with a convention-file example that shares a single bootstrap across files in parallel via the stable $PSScriptRoot; rework the #2655 stray-output test to use the convention file instead of the option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run |
Contributor
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Summary
The experimental
BeforeContainerbootstrap shipped with two entry points:Run.BeforeContainerscriptblock[] configuration option, andPester.BeforeContainer.ps1convention file (resolved fromRun.RepoRoot).Having both created the inconsistent path story Frode raised in #2838: the file always
exposes a stable
$PSScriptRoot/$PSCommandPathto anchor relative paths against, whilethe scriptblock option only had the unstable
$pwdand no file to anchor from.This PR removes the configuration option and keeps only the zero-config convention file,
dot-sourced before each container in both sequential and parallel runs. One mechanism, one
consistent behaviour. (As Frode put it: "Do we need to support BeforeContainer as a
configuration option? While nice for debugging, it has some quirks like this.")
Compelling example
Put shared setup once at the repo root in
Pester.BeforeContainer.ps1and every test file –sequential or parallel – gets it for free. Because it is a real file,
$PSScriptRootis stableregardless of the working directory
Invoke-Pesterwas called from:This removes the ~duplicated
BeforeAll/Import-Moduleboilerplate every file would otherwiserepeat, and – crucially – makes it work under
Run.Parallel, where each worker starts from aclean runspace (the real-world ask from #2772).
Where this leaves Frode's 6.1.0 issues
$PSScriptRoot. The$pwd-only quirk is gone with the option.if ($Container.Name -like '*.Integration.Tests.ps1')) is a separate feature and is not addressed here. Removing the option narrows it to "expose the container to the convention file".Changes
src/csharp/Pester/RunConfiguration.cs— remove theBeforeContaineroption (field, ctorassignment, default initializer, property). Document the
Pester.BeforeContainer.ps1conventionon the
RepoRootoption so it stays discoverable.about_PesterConfigurationhelp regenerated.src/functions/Pester.Parallel.ps1—Resolve-PesterBeforeContainernow resolves only theconvention file; drop the worker-config sanitation line for the removed option.
src/Main.ps1,src/Pester.Runtime.ps1— comment updates.Pester.RSpec.Parallel.ts.ps1with amulti-file parallel example that shares one bootstrap via the stable
$PSScriptRoot; rework thePester crashes due to native command output in
BeforeAll#2655 stray-output test inPester.RSpec.ts.ps1to use a convention file instead of the option.Verification
./build.ps1 -Clean— succeeds; about-help regenerated without the option.Pester.RSpec.Parallel.ts.ps1(20/0) andPester.RSpec.ts.ps1pass.PesterConfiguration.Tests.ps1(23/0) — format-data view stays in sync after removing the option.Invoke-ScriptAnalyzerwith the custom build rules — no new findings in the changed files.Fix #2838
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com