import TestFramework from './testFramework.js'; import TestFrameworkInstance from '../instances/testFrameworkInstance.js'; import type { Frameworks } from '@wdio/types'; import type { CucumberHook, Feature } from '../../cucumber-types.js'; type CucumberHookType = 'BEFORE_ALL' | 'AFTER_ALL' | 'BEFORE_EACH' | 'AFTER_EACH'; /** * CLI test framework for `framework: 'cucumber'` under WebdriverIO. * * Extends the BASE TestFramework, never WdioMochaTestFramework: WDIO does not call * `beforeTest`/`afterTest` or deliver titled hooks for cucumber, so mocha's INIT_TEST / TEST / * hook-boundary semantics have no source here. * * A scenario raises TEST/PRE at `beforeScenario` and TEST/POST at `afterScenario`. That is not a * preference: the binary's WDIO language index dispatches only on `TEST` and `^(BEFORE_|AFTER_)`, * so an additional state would be silently discarded on the far side. */ export default class WdioCucumberTestFramework extends TestFramework { static KEY_HOOK_LAST_STARTED: string; static KEY_HOOK_LAST_FINISHED: string; /** * The bookkeeping hook classification is derived from. A cucumber hook invocation carries no * title and `BeforeAll`/`AfterAll` pass no hook object at all, so `util.ts → getHookType()` * (Mocha quoted-title matching) can only return 'unknown' or throw on the property access. * * `stepDepth` is deliberately NOT reset per scenario. Legacy pushes to and pops from * `_cucumberData.steps` with no per-scenario reset, so a step that never reaches `afterStep` * leaves the depth above zero for the rest of the run and every later AFTER_EACH is * classified null and dropped. That is v8 behaviour and therefore the parity target * (pre-existing-bugs PB-V8-1); the per-scenario reset exists only on the v9 line. */ private cucumberData; /** * Steps of the scenario in flight, mirroring legacy's per-scenario `_tests[uniqueId].steps`. * Re-allocated (never cleared in place) at each scenario start, so a payload already built * from the previous scenario cannot observe this one's steps through a retained reference. */ private scenarioSteps; /** The hook started and not yet finished on this worker — legacy's `_currentHook`. */ private openHook; /** * Set when a hook finish arrived with no recorded start. Legacy throws at that point and the * wrapper swallows it, which drops the HookRunFinished *and* the BEFORE_ALL cascade in the * same call; this flag reproduces the second half. */ private lastHookFinishOrphaned; constructor(testFrameworks: string[], testFrameworkVersions: Record, binSessionId: string); /** * Feature bookkeeping. Raises no state — cucumber has no feature-level wire event, and * `beforeSuite`/`afterSuite` are not part of its WDIO surface. */ onFeatureStart(uri: string, feature: Feature): void; /** Step bookkeeping. Steps travel inside the scenario payload's BDD meta, never as events. */ onStepStart(step: Frameworks.PickleStep): void; onStepEnd(step: Frameworks.PickleStep, result: Frameworks.PickleResult): void; /** * Classify a cucumber hook invocation from the bookkeeping state — legacy's * `getCucumberHookType()` algorithm. * * Returns null for a step-scoped hook (`BeforeStep`/`AfterStep`), which is never reported; * reporting one would change the dashboard hook count. */ classifyHookType(test: CucumberHook | undefined): CucumberHookType | null; /** The TestFrameworkState a cucumber hook maps to, or null when it is never reported. */ classifyHookState(test: CucumberHook | undefined): State | null; /** * Whether a failed BEFORE_ALL should run the skip cascade. False when the finish that just * arrived had no recorded start — see `lastHookFinishOrphaned`. */ shouldCascadeSkippedScenarios(): boolean; /** ` for `; the separator is a literal ' for '. */ private hookName; /** * The ABSOLUTE feature path. `beforeFeature`'s uri is already absolute; path.resolve only * normalises it. The binary re-bases this itself — `path.relative(session.pathProject, …)` * for file_name/location and against the git root for vc_filepath — so sending a * pre-relativised value makes both fields depend on the binary's own cwd (SDK-7233). */ private featurePath; /** * The feature path as the bdd meta blob wants it — cwd-relative, matching legacy. * * Not `featurePath()`: the binary re-bases `test_file_path`/`location` itself but never touches * this blob, so an absolute value reaches the dashboard verbatim, home directory and all. * Legacy reads the world's `gherkinDocument.uri`, which is already cwd-relative. */ private featureUriForMeta; private featureFilePathEntries; trackEvent(testFrameworkState: State, hookState: State, args?: Record): Promise; /** * One instance per scenario. `TestFramework.instances` is keyed on * `sha256(CLIUtils.getCurrentInstanceName())` = `sha256(':')`, and every * `cli/modules/*` reads it through the single `TestFramework.getTrackedInstance()` lookup, so * that key is the only one to register under. * * WDIO forks a worker process per spec and registers its own `beforeScenario`/`afterScenario` * as cucumber Before/After hooks that cucumber awaits sequentially, so the previous scenario * has always finished before the next one mints its instance — the slot cannot be clobbered * mid-scenario the way mocha's two instance-creation triggers can. */ private resolveInstance; private trackWdioCucumberInstance; /** Scenario identity. The asymmetries between the fields are deliberate. */ private loadScenarioData; private buildBddMetaInfo; /** * Scenario result. * * KEY_TEST_RESULT_AT is set even though `testHubModule.onAllTestEvents()` cannot actually * defer a completion on this line — its `sendTestFrameworkEvent()` call sits outside the * else-if chain and runs regardless. Setting it keeps `test_deferred` off the wire and the * "dropping due to lack of results" line out of the log. */ private loadScenarioResult; /** * One detached instance per scenario the feature never reached, for the BEFORE_ALL cascade * (Rule-nested scenarios included). * * Detached is load-bearing: these are not registered via `setTrackedInstance`, so neither the * live instance nor `process.env[TEST_ANALYTICS_ID]` is disturbed, and the caller sends them * straight to TestHub. Routing them through the observers would rename the Automate session, * stop the accessibility scan and run a Percy teardown per row, none of which legacy does. */ buildSkippedScenarioInstances(): TestFrameworkInstance[]; private buildSkippedScenarioInstance; /** * Whether the scenario in flight failed in a STEP rather than only in a hook. Kept for * callers that have no access to the legacy step store. */ hasStepFailures(): boolean; /** * Route a console log to the row it belongs on: the open hook's uuid while a hook is in * flight and unfinished, otherwise the scenario's. * * The record always goes into KEY_TEST_LOGS, because the send path * (`testHubModule.onAllTestEvents`) collects the test logs plus the last FINISHED hook's — a * record parked on a still-open hook's own array would never be picked up. Routing rides on * KEY_HOOK_ID, which `sendLogCreatedEvent` reads in preference to the test uuid. * * Not delegated to `WdioMochaTestFramework.loadLogEntries()`: its hook check is * `matchHookRegex(instance.getCurrentTestState().toString())`, which tests the fully-qualified * `TestFrameworkState.BEFORE_ALL` against an anchored `^(BEFORE_|AFTER_)` and never matches. */ private loadLogEntry; /** * Hook lifecycle. Entries are keyed by the short state name, matching how the binary looks * them up via `event.test_hooks_started[request.testFrameworkState]`. * * @returns false when a finish arrived with no recorded start, so the caller emits nothing. */ private trackHookEvents; } export {}; //# sourceMappingURL=wdioCucumberTestFramework.d.ts.map