Skip to content

Apply Pester.BeforeContainer.ps1 when only discovery runs - #3023

Merged
nohwnd merged 4 commits into
mainfrom
fix-3008-skiprun-beforecontainer
Sep 5, 2026
Merged

Apply Pester.BeforeContainer.ps1 when only discovery runs#3023
nohwnd merged 4 commits into
mainfrom
fix-3008-skiprun-beforecontainer

Conversation

@nohwnd

@nohwnd nohwnd commented Sep 5, 2026

Copy link
Copy Markdown
Member

Fix #3008

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.

# <root>/Pester.BeforeContainer.ps1
BeforeDiscovery { $script:Cases = 1..3 }

# <root>/tests/Some.Tests.ps1
Describe 'd' {
    It 'case <_>' -ForEach $Cases { }
}
6.1.0, Run.SkipRun          discovered 0
this branch, Run.SkipRun    discovered 3
this branch, normal run     discovered 3

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 a function now 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.

Verification

tst/Pester.RSpec.Parallel.ts.ps1 45/45 in the cascade block, whole file green. tst/Pester.Runtime.ts.ps1 and tst/Pester.RSpec.ts.ps1 green as well, since this touches shared discovery code.

Added a test next to the other cascade tests that asserts Run.SkipRun and a normal run find the same tests.

🤖

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
@nohwnd
nohwnd merged commit e9bd23c into main Sep 5, 2026
20 of 22 checks passed
@nohwnd
nohwnd deleted the fix-3008-skiprun-beforecontainer branch September 5, 2026 09:10
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.

Pester.BeforeContainer.ps1 is not applied during Run.SkipRun discovery

1 participant