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

Reference variables in parameter type regular expressions #167

Open
MiladSadinam opened this issue Jun 12, 2023 · 0 comments
Open

Reference variables in parameter type regular expressions #167

MiladSadinam opened this issue Jun 12, 2023 · 0 comments
Labels
⚡ enhancement Request for new functionality

Comments

@MiladSadinam
Copy link

MiladSadinam commented Jun 12, 2023

🤔 What's the problem you're trying to solve?

We have some large parameter-types which we would like to use both in *.feature files and also in our typescript code. Small example how we have to do it currently (some of our types are much, much larger):

defineParameterType({
	name: 'MyType',
	regexp: /"(Value1|Value2|Value3)"/,
	transformer: (s) => s,
});

type MyType = 'Value1' | 'Value2' | 'Value3';

As you can see, we need to duplicate all type values.

✨ What's your proposed solution?

We tried a solution like this:

const typeValues = [ 'Value1', 'Value2', 'Value3' ];

defineParameterType({
	name: 'MyType',
	regexp: new RegExp(`"(${typeValues.join('|')})"`),
	transformer: (s) => s,
});

type MyType = Exclude<typeof typeValues[number], undefined>;

Here the values are only defined once in typeValues without needing to repeat them. The CucumberJS runner also runs the scenario fine. But, the VSCode extension does not recognize the step anymore and marks it as not existing.

Is it possible that defineParameterType() can accept a variable for the regexp parameter?

⛏ Have you considered any alternatives or workarounds?

📚 Any additional context?

@kieran-ryan kieran-ryan added the ⚡ enhancement Request for new functionality label Dec 3, 2023
@kieran-ryan kieran-ryan changed the title defineParameterType > regexp parameter should recognize variables Support referencing variables in parameter type regular expressions Jan 2, 2024
@kieran-ryan kieran-ryan added the good first issue Good for newcomers label Jan 3, 2024
@kieran-ryan kieran-ryan changed the title Support referencing variables in parameter type regular expressions Reference variables in parameter type regular expressions Jan 7, 2024
@kieran-ryan kieran-ryan removed the good first issue Good for newcomers label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants