amiceli/vitest-cucumber

Proposition: Optional expressions

Opened this issue ยท 4 comments

The proposition is to implement the well known optional expressions.

Description

A common feature is the abiity to offer optional text attached to words. It can generally be used to deal with singular/plural nouns.

I have {int} cucumber(s) in my belly

This would match either of those texts:

I have 1 cucumber in my belly
I have 42 cucumbers in my belly

References

https://github.com/cucumber/cucumber-expressions?tab=readme-ov-file#optional-text
https://docs.specflow.org/projects/specflow/en/latest/Bindings/Cucumber-Expressions.html#optionals-alternatives

Notes

I am not really sure if this feature can be in conflicts with other existing features. If that's so, we could consider adding a new variable to enable/disable this feature, either globally or per feature.

I understand alternative text feature, but apart from reduce step title length in tests (Given parameter) I don't see it useful.
Im my company/side projects never we used it, maybe I don't see a good use case.

If we write Given I have 2 cucumber(s) in my belly/stomach in our feature file, why we will use another step title ?

I myself sometimes use Optional text because the french language has some deviations when dealing with singular/plural.

However, for Alternative text, never used it. IMO, this is a niche feature and variable expression seems to do the trick on thie one. Maybe someone that will use this library uses this pattern. But in the meantime, I suppose we can wait for feedback on this one.

OK we can ignore Alternative text, waiting another issue.
Optional text will support only (s) ? If we take french as example ๐Ÿ˜…, we can handle "social" and "sociaux" ?

Ok. I splitted this proposition into 2 issues to keep them aside of each other.

OK we can ignore Alternative text, waiting another issue. Optional text will support only (s) ? If we take french as example ๐Ÿ˜…, we can handle "social" and "sociaux" ?

Well, the optional part is a really simple feature that avoid the need for a regex capture group. In your example, it is not possible because the one on the right is not an extension of the left, you cannot write social(ux). With a regex, you would do socia(l|ux). I am not sure if we should also implement this kind of alternative pattern in the optional expression feature. Well, we can somehow improve that in different ways but we also have to take into account the associated tooling that should also handle these cases (like the Gherkin VSCode extension).

So, I would be in favor to stick with the specified implementation and try to improve it upfront. I can see there is a request for something similar here: cucumber/cucumber-expressions#305

Note: Escaping must also be implemented when you really do want to use parentheses in a step, see https://github.com/cucumber/cucumber-expressions?tab=readme-ov-file#escaping