Run stubCall/expectCalled/expectNotCalled rewrites in setUp/tearDown/beforeEach/afterEach hooks#403
Open
chrisdp wants to merge 2 commits into
Open
Run stubCall/expectCalled/expectNotCalled rewrites in setUp/tearDown/beforeEach/afterEach hooks#403chrisdp wants to merge 2 commits into
chrisdp wants to merge 2 commits into
Conversation
The bsc-plugin previously only walked the bodies of @it-decorated methods, so m.stubCall / m.expectCalled / m.expectNotCalled inside @setup / @teardown / @beforeeach / @afterEach were left as-is and the underlying call executed unmodified. Walk each hook method once per build alongside test cases so the same AST rewrites run there.
TwitchBronBron
approved these changes
Jun 10, 2026
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
m.stubCall(...),m.expectCalled(...), andm.expectNotCalled(...)are compile-time AST rewrites performed by the bsc-plugin. Until now the plugin only walked the bodies of@it-decorated methods, so the same calls inside@setup/@tearDown/@beforeEach/@afterEachhooks were left untouched and the underlying call executed unmodified at runtime.m.testSuiteinstance the tests use, and per-testcleanMocks/cleanStubsalready happens after each test — so stubs and expectations set up inbeforeEachpersist into the test and are cleaned correctly afterwards.Code changes
src/lib/rooibos/TestGroup.ts— extracted the per-function walk intomodifyAssertionsInFunction; addedmodifyAssertionsForHook(hookFuncName, ...)that reuses it.src/lib/rooibos/MockUtil.ts—gatherGlobalMethodMocksnow walks each group's hook methods too, so free functions referenced only from a hook get registered in efficient global-stub mode.src/plugin.ts—beforeFileTranspilewalks each group's four hook methods once per build (separatemodifiedHookFunctionsSet keyed on suite + path + lowercased funcName) before processing test cases.Tests
transpilation in setup hooksinsrc/plugin.spec.tscovering: stubCall in@beforeEach, expectCalled with the early-exit guard, expectNotCalled in@afterEach, stubCall in both@setupand@tearDown, global-stub registration from@beforeEach(efficient mode), and the no-double-walk de-dup across groups that share a method name.test-project/src/source/HookStubs.spec.bs(no existing samples changed) demonstrating each form for documentation/regression purposes.