cucumber / cucumber/vscode

Reference variables in parameter type regular expressions

Open
#167 1 comment 2 reactions 0 assignees View on GitHub
:zap: enhancement
Dominant language
TypeScript
Stars
88
Forks
33
PR merge metrics
No merged PRs in 30d

Description

### 🤔 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):

```typescript
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:

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

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

type MyType = Exclude;
```
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?
-

Contributor guide

Open the contributing guide

Research direction

Start at the VSCode extension's handling of defineParameterType() and compare how it recognizes a literal regexp with a regexp constructed from a variable. Done means parameter types whose regexp is built from shared TypeScript values are recognized by the extension without duplicating the values.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.