feat(browserstack-service): test-level custom metadata hook handling (beforeEach/afterEach) for WDIO+Mocha#60
Open
anish353 wants to merge 1 commit into
Open
feat(browserstack-service): test-level custom metadata hook handling (beforeEach/afterEach) for WDIO+Mocha#60anish353 wants to merge 1 commit into
anish353 wants to merge 1 commit into
Conversation
…(beforeEach/afterEach) for WDIO+Mocha Adds correct beforeEach/afterEach hook-timing handling for the setCustomTags feature already on main. WDIO's Mocha runner fires user hooks OUTSIDE the SDK's per-test tracking span: beforeEach runs before beforeTest tracks the test instance, and afterEach runs after afterTest finishes it — so tags set in those hooks previously either landed on the wrong test or missed the payload. - Buffer tags set before a per-test context exists (e.g. from beforeEach) and flush them into the test at test start (a new TEST/PRE observer in CustomTagsModule minting an onBeforeTest flush). - The service layer records the open Mocha hook window (beforeHook/afterHook) so CustomTagsModule can route a setCustomTags call to the right test. - Defer the TestRunFinished (TEST/POST) send past the after-each hook window so tags set in afterEach still make the payload; flushed at the next test's boundary, or from service.after() for the worker's last test. Ports webdriverio PR anish353/webdriverio#3 into the migrated standalone repo, reconciling against pre-existing drift in testHubModule.ts and service.ts. Standalone on main, independent of the title-based-TC work. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What is this about?
Adds correct
beforeEach/afterEachhook-timing handling for thebrowser.setCustomTagsfeature already onmain, for the WDIO + Mocha framework.WDIO's Mocha runner fires user hooks outside the SDK's per-test tracking span:
beforeEachruns beforebeforeTesttracks the test instance, andafterEachruns afterafterTestfinishes it. As a result, custom tags set inside those hooks previously either attached to the wrong test or were dropped from the payload. This change makes hook-set tags land on the intended test:beforeEach— tags set before a per-test context exists are buffered and flushed into the test at test start, via a newTEST/PREobserver inCustomTagsModule(mints anonBeforeTestflush). Parity with Java@Before.beforeHook/afterHook) soCustomTagsModulecan route asetCustomTagscall to the right test (the CLI framework never sees Mocha'sbeforeEach/afterEach).TestRunFinishedpastafterEach— theTEST/POSTsend is deferred past the after-each hook window so tags set inafterEachstill make the payload (serialized from the instance's live data at send time). Flushed at the next test's boundary, or fromservice.after()for the worker's last test.This ports webdriverio PR
anish353/webdriverio#3(commit5f377f114) into the migrated standalone repo, rewriting thepackages/wdio-browserstack-service/→packages/browserstack-service/path prefix and reconciling against pre-existing drift intestHubModule.ts(LOG_REPORT/deferred re-entrancy) andservice.ts(CLI-flow early-return inbeforeHook; the mocha-window-set is placed before the CLI early-return so it runs in CLI mode).customTags.tsandcustomTagsModule.tsapplied verbatim. It is standalone and independent of the title-based-TC work — no title-derived tagging symbols are introduced.Verification (live)
Built and injected
@wdio/browserstack-serviceinto a real WDIO + Mocha sample and ran a hook spec (beforeEach/ test-body /afterEachall callingsetCustomTags).TestRunFinishedcustom_metadata(fromsdk-cli.log, buildtdznh5vc…) shows the expected union across all three hook windows:testTagBefore=["Browserstack","Before"](set inbeforeEach→ buffered + flushed at test start)testTagInTest=["Browserstack"](set in test body)testTagAfter=["Browserstack","After","BrowserstackAfterChanged"](in-test value union'd with theafterEachvalue — proves the after-each deferral)service.after()) carries only its owntestTagInTest2=["SecondTest"]with no cross-test leakage — proving both flush paths (next-test boundary and worker end) and correct per-test routing.npm run build— 0 TypeScript errors.npm run lint— passes.Related Jira task/s
SDK-6843 (test-level custom metadata hook handling for WDIO + Mocha
setCustomTags).Release (mandatory for every PR — required for the
ready-for-reviewlabel)Version bump: (required — tick exactly one)
Release notes type: (optional)
Release notes (customer-facing): (optional but encouraged)
browser.setCustomTags) set inside MochabeforeEach/afterEachhooks now reliably land on the intended test's custom metadata, unioning and deduping with tags set in the test body (parity with Java@Before/@After).Release notes (internal): (required — engineer-facing; what actually changed / why)
CustomTagsModuleand flushing them via a newTEST/PREonBeforeTestobserver; (b) recording the open Mocha hook window inservice.beforeHook/afterHook(viacustomTags.tsclassifyMochaHookTitle/setCurrentMochaHookWindow) sosetCustomTagsroutes to the correct test; (c) deferring theTEST/POST(TestRunFinished) send inTestHubModulepast the after-each window (pendingTestFinish+flushPendingTestFinishEvent,stateOverrideTEST/POST), flushed at the next test's INIT_TEST boundary or fromservice.after()for the last test.anish353/webdriverio#3; reconciled against pre-existing drift intestHubModule.tsandservice.tson the standalonemain. Changeset added (minor).Checklist
PR Validations
Run Tests: Comment RUN_TESTS to trigger sanity tests.