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

IParameterTypeDefinition should have parameter "transformer" set to optional #1179

Closed
3 tasks done
hammzj opened this issue Apr 16, 2024 · 2 comments
Closed
3 tasks done

Comments

@hammzj
Copy link

hammzj commented Apr 16, 2024

Current behavior

export interface IParameterTypeDefinition<T, C extends Mocha.Context> {
name: string;
regexp: RegExp;
transformer: (this: C, ...match: string[]) => T;
}

transformer is required, but should be optional. If a transformer is not provided for a parameter type that returns a single capture group, then it will return the original value as a string.

However, if a parameter type has two capture groups, it needs a transformer that returns all arguments, or else it only returns only the first found argument in a capture group. That, however, does not require a transformer as the code will still execute.

Desired behavior

Make transformer be optional:

export interface IParameterTypeDefinition<T, C extends Mocha.Context> {
  name: string;
  regexp: RegExp;
  transformer?: (this: C, ...match: string[]) => T;
}

Test code to reproduce

defineParameterType({
	name: "threeChoices",
	regexp: /(now|later|maybe)/
});

defineParameterType({
	name: "someNumber",
	regexp: /(\d+)/
});


Given('call me {threeChoices}', function(choice) {
  cy.log(choice, typeof choice) // => string
});


Given('number of {someNumber}', function(x) {
  cy.log(x, typeof x) // => string
});
Feature: Demo

  Scenario Outline: Test
    * call me <choice>
    * number of 2
    * number of 3.14
    Examples:
      | choice |
      | now    |
      | later  |
      | maybe  |

Versions

  • Cypress version: 13.1
  • Preprocessor version: 18.0.6
  • Node version: 18.15.0

Checklist

  • I've read the FAQ.
  • I've read instructions for logging issues.
  • I'm not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).
@hammzj
Copy link
Author

hammzj commented Apr 16, 2024

See constructor: https://github.com/cucumber/cucumber-expressions/blob/b4d5d7025ecfe7405b5235bade7acce1d827b30b/javascript/src/ParameterType.ts#L45-L62

This also supports type to directly define the type, but not sure if needed.

@badeball
Copy link
Owner

Hi @hammzj, I've fixed with this v20.0.4.

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

No branches or pull requests

2 participants