Repository navigation
Conversation
BeforeEach and AfterEach so far only run around each test. This exposes the
block level variants that were scaffolded in the runtime but never had a public
setter, so you can run a setup or teardown around each Context or Describe.
Describe 'd' {
BeforeEach -Context { <# runs before every Context in here #> }
AfterEach -Context { <# runs after every Context in here #> }
}
No switch keeps the classic per-test behavior, and the switches combine, so
BeforeEach -Context -It runs before the Context and before each test in it.
-Describe and -Context inherit top down like the other setups (a setup on an
outer block runs before every matching nested block), teardowns run in the
opposite order.
The scriptblock is stored on the block as EachContextSetup / EachDescribeSetup,
and Invoke-Test walks up the ancestors and picks the one that matches how the
child block was defined (FrameworkData.CommandUsed). It runs on the block's
existing OuterSetup/OuterTeardown, so no extra scope is introduced.
Dropped the OneTimeBlock* leftovers while here, BeforeAll -Context makes no
sense since BeforeAll already runs once and its side effects persist for the
whole subtree.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
I think we'll quickly need a A workaround would be to use nested |
|
Should also work for root block? Currently blocked in |
|
Parking this as a draft. @fflaten is right that block level setups need a way to stop propagating, and that is a bigger question than this PR. It touches what Nobody is waiting on #1219, so this waits until we settle that. The branch 🤖 |
Draft. Implements #1219.
BeforeEachandAfterEachonly run around each test today. This exposes the block level variants that were scaffolded in the runtime but never had a public setter, using the switches I sketched in the issue:-It).BeforeEach -Context -Itruns before the Context and before each test in it.-DescribetargetsDescribeblocks,-ContexttargetsContextblocks, using how the block was defined (FrameworkData.CommandUsed).No
BeforeAll -Context, that one is redundant,BeforeAllalready runs once and its side effects persist for the whole subtree. I dropped the now unusedOneTimeBlock*leftovers while here.Scoping: it runs on the block's existing
OuterSetup/OuterTeardown, the same pathBeforeEach/BeforeAllalready use, so no extra scope is introduced, the setup is just inherited down to the child.Verification
Full
test.ps1run passes (2617 passed, 0 failed). New tests inSetupTeardown.Tests.ps1cover:-Contextwrapping each Context and not the direct tests, inheritance into nested Contexts,-Describetargeting only Describe blocks, and the combined-Context -Itorder.Still todo before this leaves draft