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

Step definitions inside subfolders don't work when providing commonPath to the config #594

Closed
okky-rymera opened this issue Jul 7, 2021 · 3 comments · Fixed by #595
Closed
Labels

Comments

@okky-rymera
Copy link

Current behavior

When setting a custom commonPath via the config, the files in subfolders won't work. To reproduce:

  1. Set the config in package.json:
    "cypress-cucumber-preprocessor": {
      "nonGlobalStepDefinitions": true,
      "commonPath": "cypress/step_definitions/"    
    }
    
  2. Add a step definition under cypress/step_definitions/subfolder/step_def.js
  3. Try to use the step definition in a feature file

Issue: I won't be able to find the step definition

Note: If you put it under cypress/step_definitions/step_def.js, it will work.

Desired behavior

It should find the step definition even if it's inside a subfolder.

Test code to reproduce

package.json

"cypress-cucumber-preprocessor": {
  "nonGlobalStepDefinitions": true,
  "commonPath": "cypress/step_definitions/"    
}

cypress/step_definitions/subfolder/step_def.js

Given("I test something", () => {
  cy.log("Step definition is found")
})

cypress/integration/test.feature

Feature: test

  Scenario: test
    Given I test something

Possible issue

It seems under cypress-cucumber-preprocessor/lib/getStepDefinitionsPaths.js for the getStepDefinitionsPaths function, it has:

if (config.commonPath) {
  commonPath = path.resolve(appRoot, commonPath);
}

The path.resolve() will always remove the trailing slash, so even when my commonPath includes trailing slash ("cypress/step_definitions/"), the commonDefinitionsPattern will always be "cypress/step_definitions**/*.+(js|ts|tsx)"

Versions

  • Cypress version: 7.6.0
  • Preprocessor version: 4.1.3
  • Node version: 16.3.0
@fypnlp
Copy link

fypnlp commented Jul 8, 2021

Hi, you're not alone. I'm experiencing the same thing as well. Took me 3 days to figure out it was the dependency and not user error.

@lgandecki
Copy link
Collaborator

Sorry for this, you are absolutely right, and what's even worse, we have a test for this specific combinations of options and we mocked the path.resolve in a wrong way:

jest.mock("path", () => ({
      resolve(appRoot, commonPath) {
        return `./${appRoot}/${commonPath}`;
      },
      extname() {
        return ".js";
      },
    }));

which would keep the trailing slash passed from commonPath, when in reality resolve removes it. We don't even need that mock, so I removed it and fixed the issue, the release should be out there soon.

lgandecki added a commit that referenced this issue Jul 9, 2021
lgandecki added a commit that referenced this issue Jul 9, 2021
@lgandecki
Copy link
Collaborator

🎉 This issue has been resolved in version 4.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants