Skip to content

Commit 872de16

Browse files
authored
Add support for repeated tag options (#142)
1 parent 25e63c8 commit 872de16

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,5 @@ This library provides 3 Context Types to interact with CucumberJS' World object.
379379
or the `--world-parameters` CLI option.
380380
- `CucumberLog`, which exposes the `log` method of the `World` object.
381381
- `CucumberAttachments`, which exposes the `attach` method of the `World` object.
382+
- `ScenarioInfo`, which exposes information about the running scenario and allows
383+
changing the behavior of steps and hooks based on tags easier.

cucumber-tsflow-specs/features/tag-parameters.feature

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Feature: Tag parameters
3030
assert.strictEqual(this.scenario.getOptionTag(name), undefined);
3131
}
3232
33+
@then("the multi option tag {string} is set to {}")
34+
public checkMultiOption(name: string, value: string) {
35+
assert.deepStrictEqual(this.scenario.getMultiOptionTag(name), JSON.parse(value));
36+
}
37+
3338
@then("the attribute tag {string} is set to {}")
3439
@then("the attribute tag {string} is set to:")
3540
public checkAttributes(name: string, values: string) {
@@ -145,6 +150,50 @@ Feature: Tag parameters
145150
When I run cucumber-js
146151
Then it passes
147152

153+
Scenario: Checking for multi options on the feature
154+
Given a file named "features/a.feature" with:
155+
"""feature
156+
@foo(bar)
157+
@foo(baz)
158+
Feature: Feature
159+
Scenario: One
160+
Then the multi option tag "foo" is set to ["bar", "baz"]
161+
Scenario: Two
162+
Then the multi option tag "foo" is set to ["bar", "baz"]
163+
"""
164+
When I run cucumber-js
165+
Then it passes
166+
167+
Scenario: Checking for multi options on the scenario
168+
Given a file named "features/a.feature" with:
169+
"""feature
170+
Feature: Feature
171+
@foo(bar)
172+
@foo(baz)
173+
Scenario: One
174+
Then the multi option tag "foo" is set to ["bar", "baz"]
175+
@foo(qux)
176+
@foo(zzz)
177+
Scenario: Two
178+
Then the multi option tag "foo" is set to ["qux", "zzz"]
179+
"""
180+
When I run cucumber-js
181+
Then it passes
182+
183+
Scenario: Checking for multi options on the scenario combining with multi options on the feature
184+
Given a file named "features/a.feature" with:
185+
"""feature
186+
@foo(bar)
187+
Feature: Feature
188+
Scenario: One
189+
Then the multi option tag "foo" is set to ["bar"]
190+
@foo(baz)
191+
Scenario: Two
192+
Then the multi option tag "foo" is set to ["bar", "baz"]
193+
"""
194+
When I run cucumber-js
195+
Then it passes
196+
148197
Scenario: Checking for an attribute tag on the feature
149198
Given a file named "features/a.feature" with:
150199
"""feature

cucumber-tsflow/src/scenario-info.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TagName } from "./types";
77
export class ScenarioInfo {
88
private _attributeTags?: Map<string, unknown>;
99

10-
private _optionTags?: Map<string, string>;
10+
private _optionTags?: Map<string, string[]>;
1111

1212
private _flagTags?: Set<string>;
1313

@@ -39,17 +39,23 @@ export class ScenarioInfo {
3939
return result;
4040
}
4141

42-
private static parseOptionTags(tags: TagName[]): Map<string, string> {
42+
private static parseOptionTags(tags: TagName[]): Map<string, string[]> {
4343
const RGX = /^@?(?<option>[\w-]+)\((?<value>.+?)\)$/s;
4444

45-
const result = new Map<string, string>();
45+
const result = new Map<string, string[]>();
4646

4747
for (const tag of tags) {
4848
const match = tag.match(RGX)?.groups;
4949

5050
if (match !== undefined) {
5151
const { option, value } = match;
52-
result.set(option, value);
52+
53+
const list = result.get(option)
54+
if (list === undefined) {
55+
result.set(option, [value]);
56+
} else {
57+
list.push(value);
58+
}
5359
}
5460
}
5561

@@ -89,7 +95,15 @@ export class ScenarioInfo {
8995
this._optionTags = ScenarioInfo.parseOptionTags(this.tags);
9096
}
9197

92-
return this._optionTags.get(name);
98+
return this._optionTags.get(name)?.at(-1);
99+
}
100+
101+
public getMultiOptionTag(name: string): string[] | undefined {
102+
if (this._optionTags === undefined) {
103+
this._optionTags = ScenarioInfo.parseOptionTags(this.tags);
104+
}
105+
106+
return this._optionTags.get(name) ?? [];
93107
}
94108

95109
public getFlag(name: string): boolean {

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "4.3",
3+
"version": "4.4",
44
"publicReleaseRefSpec": ["^refs/heads/master$", "^refs/heads/release/"]
55
}

0 commit comments

Comments
 (0)