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.