fix(testing): top-level hook outside describe no longer inflates step count#7138
Open
fibibot wants to merge 1 commit into
Open
fix(testing): top-level hook outside describe no longer inflates step count#7138fibibot wants to merge 1 commit into
describe no longer inflates step count#7138fibibot wants to merge 1 commit into
Conversation
…ep count A top-level `beforeAll`/`afterAll`/`beforeEach`/`afterEach` call creates a synthetic "global" `TestSuite` to host the hook. Previously that suite was also eagerly registered as a top-level `Deno.test`, so any nested `describe` would be reported as a child step of `global` — inflating the step count by one and changing the test output. Now the synthetic suite is only registered with `Deno.test` if a top-level `it()` is actually added to it. Otherwise, each child `describe` is promoted to its own `Deno.test` and inherits the global hooks at run time (so `beforeAll`/`afterAll` wrap the nested tests, and the `active` stack picks up the global `beforeEach`/`afterEach`). Fixes #7056
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7138 +/- ##
=======================================
Coverage 94.61% 94.61%
=======================================
Files 634 634
Lines 51822 51866 +44
Branches 9336 9348 +12
=======================================
+ Hits 49029 49072 +43
Misses 2218 2218
- Partials 575 576 +1 ☔ View full report in Codecov by Sentry. 🚀 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.
Summary
A top-level
beforeAll/afterAll/beforeEach/afterEachcall creates a synthetic"global"TestSuiteto host the hook. Previously that suite was also eagerly registered as a top-levelDeno.test, so any nesteddescribewas reported as a child step ofglobal— inflating the step count by one and changing the test output.For example, this file:
reported
FAILED | 0 passed | 1 failed (3 steps)even though only two tests existed. With this PR it reports(2 steps), matching the file's contents.How the fix works
"global"suite is now only registered withDeno.testlazily — only if a top-levelit()is actually added to it. Otherwise the wrapper never surfaces as a counted test/step.describeof the synthetic suite is promoted to its own top-levelDeno.test. It keeps a back-reference to the synthetic suite (syntheticParent) so the global hooks still wrap its tests at run time:beforeAll/afterAllare invoked around the promoted child's body.symbolis pushed ontoTestSuiteInternal.activefor the duration of the run, sorunTest's normal traversal picks upbeforeEach/afterEachfrom the global suite just like any other parent.it()calls under a synthetic suite still work exactly as before: the synthetic suite is registered lazily on the firstit()and theit()s become its steps.Behavior preserved
describe→ fixed: nested describes register as their ownDeno.tests, hooks still run around their tests (regression test added).it()→ unchanged: a single"global"Deno.testwraps theit()s (existing tests still pass).it.only()propagation to the synthetic global → unchanged (existing test still passes).it()+ nesteddescribe) → describes are promoted; the synthetic wrapper remains for the top-levelit()s. Hooks fire around both, which meansbeforeAllruns once per top-levelDeno.testrather than strictly once across the file. Acceptance criteria only requires the hook still "runs around tests" in this case.Tests
Added three regression tests in
testing/bdd_test.ts:Deno.testnamed after the user'sdescribe, two steps, hooks fire correct number of times.Deno.test.Closes bartlomieju/orchid-inbox#68
Test plan
(2 steps)instead of(3 steps).deno test -A --parallel --no-check testing/— 137 passed (159 steps), 0 failed.deno test -A --parallel --no-check expect/— 167 passed, 0 failed (expectbuilds onbdd).deno fmt --check— clean.deno lint— clean.deno test --doc testing/bdd.ts— doc examples still pass.