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

Question: Docstring transformation #176

Open
viktor-silakov opened this issue Jul 10, 2024 · 5 comments
Open

Question: Docstring transformation #176

viktor-silakov opened this issue Jul 10, 2024 · 5 comments
Labels
question Further information is requested

Comments

@viktor-silakov
Copy link

Is it possible to use a similar to the defineParameterType transformation for all docstrings?
Or maybe you can suggest some workaround? I want to add some templating system across all docstrings.

@viktor-silakov viktor-silakov added the question Further information is requested label Jul 10, 2024
@vitalets
Copy link
Owner

Could you provide an example?

@viktor-silakov
Copy link
Author

@vitalets Yes sure, for example, I have step:

When I fill out the form:
"""
name: [random username]
email: [random email]
"""

And make some callback 'fillPlaceholders' which should render this template and give me the output:

name: John
email: [email protected]

Under the hood...

For usual string parameters, I can use defineParameterType transformation but for docstrings - can't

@vitalets
Copy link
Owner

At what moment fillPlaceholders should be called? During spec files generation or in runtime?
If in runtime - looks like it's custom content type for doc strings, I see it in cucumber-jvm (and don't see in cucumber-js).

I think API can be the following:

defineDocStringType({
  name: 'placeholders', // if empty -> applied to all docStrings
  transformer: (s) => fillPlaceholders(s, { name: 'John', email: '[email protected]' });
});

And in feature file:

When I fill out the form:
"""placeholders
name: [random username]
email: [random email]
"""

@viktor-silakov
Copy link
Author

Yes, it would be good to have this API on runtime.

@vitalets
Copy link
Owner

Ok. Lets track in this issue. For now the only workaround I see is to make transformation inside step:

When("I fill out the form:", async ({ page }, docStringTpl: string) => {
  const docString = fillPlaceholders(docStringTpl, { name: 'John', email: '[email protected]' });
  // ...
});

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

No branches or pull requests

2 participants