将命令行参数传递给测试脚本

时间:2018-06-08 10:37:20

标签: node.js npm

package.json我有:

"scripts": {
  "test": "for f in test/*; do echo \"$f\"; node \"$f\"; done; echo 'passed!'; exit 0",
  "pack": "npm version patch --no-git-tag-version; npm pack"
},

test.js我有:

var program = require("commander");

program.option('--sendtestdata', 'Send test data').parse(process.argv);

if (program.sendtestdata) console.log(' - With sending data option');

我希望我的测试命令类似于:

$ npm run test -- sendtestdata=true

所以我需要sendtestdata=true传入for f in test/*; do echo \"$f\"; node \"$f\"; done; echo 'passed!'; exit 0

我试过了:

`"for f in test/*; do echo \"$f\"; node \"$f\" $0; done; echo 'passed!'; exit 0",`

`"for f in test/*; do echo \"$f\"; node \"$f\" $*; done; echo 'passed!'; exit 0",`

但他们都没有奏效。

0 个答案:

没有答案