我正在编写一个包含六个测试的Node JS Test Suite。在每个测试中,我传递的变量品牌等于允许我传入cookie的参数,它看起来像这样:
const Nightmare = require('nightmare')
const path = require('path')
const nightmare = Nightmare({ show: true })
var someTest = function(brand){
var brand = process.argv[2]
nightmare
.viewport(1300, 900)
.cookies.clear()
.cookies.set('brand', brand)
.wait('#auth-email')
.refresh()
.wait('#auth-email')
.screenshot(path.join(__dirname, new Date().getTime() + "3.png"))
.wait(2000)
.click('form[name=loginForm] [type=submit]')
.wait(2000)
.cookies.clear()
.end()
.then((res) => console.log('Successful'))
.catch((err) => console.error('Errror!'))
}
module.exports = someTest
我有一个index.js文件,当我在终端上使用以下命令执行它时运行所有六个测试:node index.js brand(cookie),index.js文件如下所示:
someTest = require('./someTest.js')
someTest(process.argv[2]);
someTest2 = require('./someTest2.js')
someTest2(process.argv[2]);
在这个index.js文件中,我希望能够运行一系列品牌(cookies)而不是在命令行中说明它:node index.js brand(cookie),看起来像这样:< / p>
var brand = ['cookie1', 'cookie2']
someTest = require('./someTest.js')
someTest(process.argv[2]);
someTest2 = require('./someTest2.js')
someTest2(process.argv[2]);
但是,我不确定如何将数组作为参数处理。节点对我来说是新的,我还在学习,任何见解都非常值得欣赏。谢谢你的帮助:D
答案 0 :(得分:0)
我会查看一个名为yargs的图书馆。这是一个简单的例子,可以帮助您入门:
index.js:
<_inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="-20dp"
android:insetLeft="-20dp"
android:insetRight="-20dp">
<shape android:shape="oval">
<solid android:color="#FF0000"/>
</shape>
</inset>
在终端i中运行:
var argv = require('yargs').argv,
params = argv._,
// argv has a function called _ that represents an array of all args
param1 = params[0],
param2 = params[1],
param3 = params[2],
mydefaultval = {'cat': "i'm a cat"},
// or you could destructure
[param1, param2, param3=mydefaultval] = argv._;