Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the '*' keyword in a step name #86

Merged
merged 2 commits into from
Feb 15, 2022

Conversation

josef-kriz
Copy link
Contributor

There is a possibility to use the '*' keyword in the Gherkin language instead of one of the other common keywords (like Given or And). This can be handy when listing things, as for example

Scenario: All done
  Given I am out shopping
  * I have eggs
  * I have milk
  * I have butter
  When I check my list
  Then I don't need anything

(See Gherkin syntax)

Unfortunately this is not supported for some reason by the json reporter.

Is there a reason why this keyword is explicitly filtered out from the list of keywords (utils.ts:20)?

public getStepKeywords ( language: string ): string[] {
        const dialect = dialects[language];
        return ( [] as string[] )
            .concat( dialect.given, dialect.when, dialect.then, dialect.and )
            .map( keyword => keyword.replace( /\s*$/, '' ) )
            .filter( keyword => keyword !== '*' ); // <---
    }

As of now, steps defined like this have their names parsed incorrectly and this results in meaningless step names, like in this report:

Screenshot 2022-02-09 at 14 05 43

Whereas with this fix, the names are displayed correctly:

Screenshot 2022-02-09 at 14 04 02

This fix removes the filtering out of the '*' keywords and also escapes the strings so that they don't break the regular expressions. The escape regex originally comes from MDN.

Note: Technically there will be duplicate '*'s in the keywords array (stepKeywords), if that is an issue the duplicates can be removed.

Copy link
Collaborator

@wswebcreation wswebcreation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR

As far as I can remember there was no specific reason to filter out the *.
Can you also create a unit test that would cover this case so it won't be broken in the future?

@josef-kriz
Copy link
Contributor Author

@wswebcreation Thanks for your input! I've added new unit tests for the keywordStartsWith method.

@wswebcreation
Copy link
Collaborator

Awesome, thanks!

@wswebcreation wswebcreation merged commit 7c86a3a into webdriverio-community:main Feb 15, 2022
@wswebcreation
Copy link
Collaborator

I've released a new version @josef-kriz , see https://github.com/webdriverio-community/wdio-cucumberjs-json-reporter/releases/tag/v4.4.0

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants