cypress-cucumber-preprocessor: fileServerFolder option is being used incorrectly

First off, I would like to show my appreciation for this project, it’s something that I’ve been looking for for a while now, and I’m glad you open sourced it!

The issue is that the fileServerFolder option is being used incorrectly to look for step definitions, when it actual use case is to allow cypress to start a local http static assets folder from this path.

I’ve created a PR here #17

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@lgandecki sure, the default path of installation of cypress is in the root of the project, but for me, that default doesn’t match my current scaffolding. This is directory structure:

/src <-- Source files (vuejs)
/tests <-- Test root folder
/tests/unit <-- units tests
/tests/e2e <-- Cypress content goes here

So, in my case, i don’t want to keep a cypress folder polluting the root of the project. But, this plugin has the directory /cypress/support/ hardcoded, so, what i try was just to make this module to be aware of the custom directory cypress folder.

But, if we can add to cypress.json a specific value to our step_definition folder, that should be great.

Another way is adding a custom config to the package.json file adding the route of our step definition files.

quick update - if the cypress guy don’t reply by the middle of next week I will implement it in cypress.json with the syntax proposed by @reaktivo

@brian-mann is there a best practice for defining plugin configs? I would rather read the both the cypress config and it’s plugins from the same file. And considering we have access to the parsed config at plugin loading time, we might as well pass that config:

// In cypress/plugins/index.js
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
  on('file:preprocessor', cucumber(config)) // Note that we're passing the config to the plugin here
}

in my cypress.json file:

{
  "viewportWidth": 1000,
  "viewportHeight": 660,
  "fileServerFolder": "build",
  "cypressCucumber": {
    "stepDefinitions": "tests/e2e/step_definitions"
  }
}

Yesterday I played around with some different solutions

  1. Adding a cypressCucumber key to cypress.json

I gave this idea a try and it kind of felt prone to error. Considering cypress config options may also be passed via env variables, cli --config flags, etc, having cypress-cucumber-preprocessor read the config json file directly without taking into account the previously mentioned sources of config feels like the wrong way to go.

  1. Using the config that is passed to the plugin configuration function, like so:
const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
  config.cypressCucumber = {};
  on('file:preprocessor', cucumber(config)) // notice config being passed here
}

I found out Cypress whitelists the properties that will be included in that config object, what I mean that adding a "something": "value" into your cypress.json won’t include it in the config argument passed to the plugin configuration function. Also, some refactoring would need to happen so we append browserifyOptions instead of overwriting them.

  1. Creating a new cypress-cucumber.json at project root level Although not ideal, it works in a predictable way and is guaranteed to be compatible with future cypress versions.

P.D As a temporary solution for those wanting to define fileServerFolder without your step definitions path incorrectly set, you can simply pass it as a cli option, and it will be ignored by the cypress-cucumber-preprocessor plugin.

cypress run --config fileServerFolder=build

@lgandecki that was the case.

In this scenario, i’ll vote for a package.json configuration, like the custom configurations for “jest” or “nightwatch”.

{
  "cypress-cucumber-preprocessor": {
    "stepsFolder": "/tests/e2e/steps_definition",
    "scenarios":  "/tests/e2e/scenarios"
  }
}

If you rename all of the cypress folders per configuration it should/will not create a cypress folder.

https://docs.cypress.io/guides/references/configuration.html#Folders-Files

yeah, that could make sense… I wish we had some feedback from the cypress guys here… @brian-mann @bahmutov what do you think of us (or other plugins) adding custom properties to the cypress.json ?