@watershed-labs/hooks
v0.1.0
Published
Cucumber hook library with enforced execution order
Readme
@watershed-labs/hooks
Side-effect hook registration for the Watershed ecosystem.
Part of the Watershed testing ecosystem.
Usage
// support/hooks.js — one import registers all hooks
import '@watershed-labs/hooks';
// Add template-specific hooks after the import
import { Before } from '@cucumber/cucumber';
Before({ tags: '@login' }, async function () {
await this.page.login(this.config.get('testUser'));
});What it does
The package registers six hooks when imported:
Before— stores the pickle reference (this._pickle); detects@SharedDrivertag and reuses a cached browser driver across scenarios in the same feature fileBeforeStep— logs each step's text at debug levelAfterStep— attaches per-step log chunks to the Cucumber report whenlogging.perStepis enabledAfter— flushes buffered logs whenlogging.bufferedis enabled; runs an@AccessibilityWCAG scan when the tag is present andthis.a11yis available; manages@SharedDriverdriver lifecycle (cache on first use, quit when refcount reaches zero); then callsthis.teardown()
It also sets a default Cucumber timeout of 60 seconds.
@SharedDriver
Scenarios tagged @SharedDriver within the same feature file reuse a single browser driver. The driver is cached after the first scenario and automatically quit when the last referencing scenario completes.
@SharedDriver
Scenario: Login
Given I am on the login page
@SharedDriver
Scenario: Dashboard
Given I am on the dashboard # reuses driver from Login scenarioDrivers are keyed by feature file URI and managed per-worker, making them safe in parallel execution.
@Accessibility
Scenarios tagged @Accessibility trigger an automated WCAG scan via this.a11y.scan() after the scenario completes. Critical and serious violations are attached as JSON to the report. If violations are found and the scenario has not already failed, the scenario is marked as failed.
@Accessibility
Scenario: Homepage is accessible
Given I open the homepageRequires this.a11y (an A11yScanner instance) on the World. Templates that provide it (e.g., create-otter) get this automatically.
Exports
| Export | Purpose |
| ----------------------- | --------------------------------------------- |
| _resetSharedDrivers() | Clears the shared driver cache (testing only) |
What it does NOT do
- Validate environment configuration
- Provision shared resources
- Capture screenshots on failure
- Generate reports or merge worker output
Those responsibilities belong to each template's support/hooks.js.
Licence
MIT — part of the Watershed ecosystem.
