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

An argument with default value from the optional regex capturing group returns null instead of a default value #720

Closed
alesiaviktorchyk opened this issue May 22, 2022 · 4 comments

Comments

@alesiaviktorchyk
Copy link

Current behavior

An argument with default value from the optional regex capturing group returns null instead of a default value.

Given I have the following step definition:

Given(/^(?:I am|I'm) logged in( as '(.*)')?$/, (userType = 'user') => {
	cy.log(userType);
});

When in my feature file I use:

Feature: Test
    Scenario: Test
        Given I am logged in as 'user'
        Given I am logged in

I see the following in cypress test runner:
screenshot-nimbusweb me-2022 05 22-18_39_59

Desired behavior

I expect that for both steps cy.log will log user.

At least this is how the old cypress-cucumber-preprocessor worked.

Here's what I see when I use the old cypress-cucumber-preprocessor:
screenshot-nimbusweb me-2022 05 22-18_38_51

Test code to reproduce

To reproduce:

To compare @badeball/cypress-cucumber-preprocessor vs. cypress-cucumber-preprocessor:

  • switch to the old-preprocessor branch and run npm run test again.

Versions

  • Cypress version: 9.6.1
  • Preprocessor version: 10.0.0
  • Node version: 15.8.0
@alesiaviktorchyk
Copy link
Author

Unrelated to the issue but just wondering why with the new processor there's an empty wrap after each cypress command:
screenshot-nimbusweb me-2022 05 22-18_39_59 (1)

@badeball
Copy link
Owner

Regarding optional capturing groups in step definitions and parameter types, it seems that unmatched capturing group in step definition changed from undefined to null in cucumber-expressions-v7.0.1, when typescript was introduced. The previous preprocessor implementation was depending on cucumber-expressions ^6.0.1, while this is now on ^15.0.1, hence the change in behavior you're experiencing.

This is how cucumber-js now behaves and I see no reason for why the preprocessor should behave any differently.

I've relased v10.0.1 which omits logging certain calls to cy.wrap. Hope that helps.

@badeball
Copy link
Owner

badeball commented May 22, 2022

You can use eg. patch-package if you want to change this behavior yourself (you will find the relevant lines in cucumber-expressions in dist/cjs/src/defineDefaultParameterTypes.js and dist/cjs/src/RegularExpression.js).

@alesiaviktorchyk
Copy link
Author

@badeball thanks for the explanation and for the quick fix of the wrap thing.

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