cucumber js unable to create profiles

1.9k Views Asked by At

Have been searching for a bit and haven't found anything that answered my question.

I have a simple Cucumber.js project, was trying to implement profiles just like you can do in ruby under the cucumber.yml file, but can't really find out how to do it in Cucumber.js

Sorry for no specific info about the issue,

Thanks in advance

2

There are 2 best solutions below

0
On

At the time of writing, this question is the number one result from Google for 'cucumberjs profile', even though the CucumberJS GitHub page has a section entitled Profiles.

In order to store and reuse commonly used CLI options, you can add a cucumber.js file to your project root directory. The file should export an object where the key is the profile name and the value is a string of CLI options. The profile can be applied with -p or --profile . This will prepend the profile's CLI options to the ones provided by the command line. Multiple profiles can be specified at a time. If no profile is specified and a profile named default exists, it will be applied.

I just tried that with the following, and it seems to work: I see no results for tests tagged @full-user when I create the above-mentioned cucumber.js and fill it with this:

module.exports = {
    "delayed-user" : "--tags=@delayed-user --tags ~@full-user"
};
0
On

A general solution is to use Node's process.env

There are obviously many ways to do this, and you can fit it to your needs. Here's the way I did it which puts all the profiles into a JSON file, and also supports a default profile if none is specified when running cucumber.

Have your profiles in a file config.json

{
  "default": {
    "foo": "this is the default profile",
    "bar": 1
  },
  "profile1": {
    "foo": "this is profile 1",
    "bar": 2
  },
  "profile2": {
    "foo": "this is profile 2",
    "bar": 3
  }
} 

Require and use the config in your tests

var config = require('./config.json')[process.env.PROFILE || 'default'];

console.log(config.foo);
console.log('value of bar: ' + config.bar);

And then select a profile when running cucumber.js from the command line

Run with profile 1

PROFILE=profile1 cucumber.js

Or profile2

PROFILE=profile2 cucumber.js

Or the default profile

cucumber.js

NOTE Credit to this answer for giving me the idea of doing it this way.