Closed bryant-svedin-gehc closed 1 year ago
Cucumber's beforeAll
and afterAll
hooks do not support tags at all. They are executed before/after the entire test suite while tags in Cucumber are processed per scenario, so they are not available for those hooks.
We reused the types when defining our decorators incorrectly, I'll get this fixed right away, thanks for the report.
If you want to conditionally run global hooks you'd need to use some other mechanism, like checking an environment variable yourself:
@beforeAll()
public async beforeAllScenarioFoo(): Promise<void> {
if (!process.env.FOO) return;
// ...
}
Then run with FOO=1 npx cucumber-js -p default
.
This looks like an interesting use case for tags, but it would be a feature request on CucumberJS.
Thanks for your quick response and suggested workaround
I have several beforeAll decorators with different tags. When running
npx cucumber-js -p default --tags=@foo
all given/when/then/before/after work as expected, EXCEPT the beforeALL steps. It will run all beforeAll regardless of tags in decorator input. For example, the below steps would run both beforeAll but only the foo before. I have not checked if this problem also exists in afterAll because I don't currently use it but after decorator does respect tag.