Skip to content

Report which Pester.BeforeContainer.ps1 files applied to a container - #3028

Merged
nohwnd merged 6 commits into
mainfrom
fix-3007-report-applied-setup-files
Sep 5, 2026
Merged

Report which Pester.BeforeContainer.ps1 files applied to a container#3028
nohwnd merged 6 commits into
mainfrom
fix-3007-report-applied-setup-files

Conversation

@nohwnd

@nohwnd nohwnd commented Sep 5, 2026

Copy link
Copy Markdown
Member

Fix #3007

Based on #3023, not on main. It needs the discovery-only path to receive the map, otherwise Run.SkipRun would report an empty list. Retarget to main once #3023 merges.

A container's setup comes from every Pester.BeforeContainer.ps1 between Run.RepoRoot and the test file's own folder, and nothing in the result said which ones were used. Opening tests/unit/Foo.Tests.ps1 shows no BeforeAll and gives no sign that two folder setups ran before it. Reading the directory tree does not answer it either, because #pester:no-inherit can cut the chain short.

The applied files are on the container now, outermost first, in the order they ran:

U.Tests.ps1:
    <root>/Pester.BeforeContainer.ps1
    <root>/tests/Pester.BeforeContainer.ps1
    <root>/tests/unit/Pester.BeforeContainer.ps1
D.Tests.ps1:
    <root>/tests/docs/Pester.BeforeContainer.ps1

D.Tests.ps1 sits under a folder marked #pester:no-inherit, so it reports only its own file. That is the case the folder tree cannot tell you.

On the container rather than the block, as the issue suggested. It is a property of the file being run, post-processors already walk containers, and it leaves the block model unchanged.

Verification

tst/Pester.RSpec.Parallel.ts.ps1 47/47, tst/Pester.RSpec.ts.ps1 128/128.

Two tests added next to the other cascade tests, one for the full chain and one for the #pester:no-inherit truncation.

I checked that Remove-RSpecNonPublicProperties does not drop the new property. Its property lists are commented out, it only nulls the plugin fields, so the property survives to PassThru.

🤖

Run.SkipRun returns the discovered tree without executing anything, which is the path
the VS Code Test Explorer uses to populate. It goes through Discover-Test, a batch
discovery over all containers, and that function never took the BeforeContainer map,
so it called Invoke-ContainerDiscovery without -BeforeContainerFile. A file whose
discovery depends on the setup discovered fine in a normal run and came back empty
when only discovery was requested.

Discover-Test now takes the same map the interleaved discover -> run path gets, and
resolves it per container, because which files apply depends on where the container is
after #2993. Find-Test forwards it too.

The per container lookup was written inline in Invoke-Test and is now a function that
both paths call, so they cannot drift apart again. That also removes the case-insensitive
variable name trap the inline version needed a comment to explain.

Fix #3008

🤖
…recontainer

# Conflicts:
#	docs/NEXT-RELEASE.md
See #3026. This PR appending to the shared list is what causes the conflicts.

🤖
A container's setup comes from every Pester.BeforeContainer.ps1 between Run.RepoRoot and
the test file's own folder, and nothing in the result said which ones were used. That
makes "where did this function come from" unanswerable from the outside: opening
tests/unit/Foo.Tests.ps1 shows no BeforeAll and gives no sign that two folder setups ran
before it. Reading the directory tree is not enough either, because #pester:no-inherit
can cut the chain short.

The applied files are on the container now, outermost first, matching the order they ran
in. On the container rather than the block, because it is a property of the file being
run, and post-processors already walk containers.

Fix #3007
Base automatically changed from fix-3008-skiprun-beforecontainer to main September 5, 2026 09:10
…ed-setup-files

# Conflicts:
#	tst/Pester.RSpec.Parallel.ts.ps1
@nohwnd
nohwnd enabled auto-merge (squash) September 5, 2026 09:17
@nohwnd
nohwnd merged commit 7b71e4a into main Sep 5, 2026
13 checks passed
@nohwnd
nohwnd deleted the fix-3007-report-applied-setup-files branch September 5, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report which Pester.BeforeContainer.ps1 files applied to a container

1 participant