package.jsopn
では
"e2e": "testcafe chrome ./test/*-test.js",
コマンド
yarn comman --hoge bar
ソースはこう
import _ from 'lodash';
/** * ["chrome:headless","./test/hoge-test.js","./test/hoge-test.js","--hoge","bar","--fuga","hogehoge"] * を {'hoge': 'bar', 'fuga': 'hogehoge'} に変換 * それからキーをもとに取得 * * @param {*} regex */ const getParam = key => { const args = process.argv.slice(2); const MY_ENV = _.reduce(args, (result, item, key) => { if(item.includes('--')) { result[item.replace('--', '')] = args[key + 1]; } return result; }, {}); if (_.isNil(MY_ENV)) { return null; } return MY_ENV[key]; }