//package.json
"scripts": {
"run-tests": "node scripts/run-tests.js"
}
When I run my test suite using npm run run-tests --env=integration --variant=alpha, I get undefined argument values:
//run-tests.js
console.log(argv.env) //undefined
console.log(argv.variant) //undefined
However, when I run my test suite with two dashes (--) npm run run-tests -- --env=integration --variant=alpha, I get my argument values:
//run-tests.js
console.log(argv.env) //integration
console.log(argv.variant) //alpha
Can I somehow get my argument values in run-test.js without using --?
Based on the discussion in this pull request, I believe the answer to your question is no :(
However, a workaround is to specify your arguments in the package.json file in the scripts block. This is preferred in a CI/CD context, as you want less coupling with your CI/CD provider.
In package.json
"scripts": {
"test:int:a": "node scripts/run-tests.js --env=integration --variant=alpha",
"test:int:b": "node scripts/run-tests.js --env=integration --variant=bravo"
}
Then on command-line:
npm run test:int:a
If you are going more for a command-line tool, I suggest looking into creating a CLI tool with node.js, such as this example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With