CodeceptJS
CodeceptJS copied to clipboard
Codeceptjs doesn't support to use minimist to pass environment variable
What are you trying to achieve?
Using minimist to use -e to passing environment variable. For example adding the following script in package.json
"ci_xxx": "codeceptjs run -c codecept.ci.conf.js --grep @test -e prod",
"stage_xxx": "codeceptjs run -c codecept.ci.conf.js --grep @test -e staging",
"local_xxx": "codeceptjs run -c codecept.ci.conf.js --grep @test -e dev",
What do you get instead?
an error:
unknown option `-e'
Details
It looks like all the supported args are already pre-defined here: https://github.com/codeceptjs/CodeceptJS/blob/3.x/bin/codecept.js
Can we update codeceptjs to support to use minimist? Much Thanks!
hey @YSuMinto how about using this https://www.npmjs.com/package/dotenv?
Creating the according .env files like .dev.env, etc.
In your codecept.conf.js:
...
switch (process.env.ENV) {
case 'dev':
require('dotenv').config({ path: '.dev.env' });
break;
case 'prod':
require('dotenv').config({ path: '.prod.env' });
break;
default:
require('dotenv').config({ path: '.staging.env' });
}
...
following script in package.json
"ci_xxx": "export ENV=prod && codeceptjs run -c codecept.ci.conf.js --grep @test",
"stage_xxx": "export ENV=staging && codeceptjs run -c codecept.ci.conf.js --grep @test",
"local_xxx": "export ENV=dev && codeceptjs run -c codecept.ci.conf.js --grep @test",
Then I believe you'd achieve the same expectations.
Thank you @PeterNgTr for the reply!
So far We don't have anything need to be stored in .env file, so it's kind of redundant to add 3 empty files...
Also we need to be able to run the automation code under different OS (want to avoid editing code for different OS) and "cross-env" can surely achieve it with "cross-env TEST_ENV=prod".
Just thought minimist can make things a little easier and more flexible...so want to ask whether codeceptjs has the plan to support it.
Oh, so @YSuMinto what you wanna pass is only one env var right? Then why not just export ENV=xxx then in your code you can access this environment var like process.env.ENV whenever you need. Not sure if I understand correctly.
Hey @PeterNgTr we want to keep the same copy for different OS, export ENV=xxx will not work for Windows
we are using cross-env TEST_ENV=prod for all different OS right now, which works fine.
While the request may be a little bit aggressive here...
We also want to keep the script/commend shorter. so with minimist it will only need -e prod
Not sure whether it's the intention of codeceptjs on hardcoding the acceptable args, then it kind of results limiting the choices.
Yes, we don't support minimist as we use different option to parse arguments and options.
to introduce custom options use environment variables:
TEST_ENV=production codeceptjs run
``