简体   繁体   English

如何通过 package.json 文件中的 npm test 脚本设置位置参数?

[英]How to set positional arguments via npm test script in package.json file?

I'm running AVA test now and I have 3 positional arguments that will be passed when running the command.我现在正在运行 AVA 测试,并且在运行命令时将传递 3 个位置参数。 For example:例如:

npm test <arg1> <arg2> <arg3>

But I wish to put the first 2 positional arguments inside packaga.json file so that I don't have to manually pass in 3 arguments whenever I run the test.但我希望将前 2 个位置参数放在 packaga.json 文件中,这样我就不必在运行测试时手动传入 3 个参数。

This is how my test script looks like in package.json file:这是我的测试脚本在 package.json 文件中的样子:

{
    "scripts": {
        "test": "ava -v --serial --timeout='2m'"
    }
}

I tried this but it's not working:我试过这个,但它不起作用:

{
    "scripts": {
        "test": "ava -v --serial --timeout='2m' -- -- <arg1> <arg2>"
    }
}
npm test <arg3>

NOTE: The double '--' is used to separate the ava flags with the arguments.注意:双“--”用于将 ava 标志与参数分开。 I found this from https://github.com/avajs/ava/blob/main/docs/recipes/passing-arguments-to-your-test-files.md我从https://github.com/avajs/ava/blob/main/docs/recipes/passing-arguments-to-your-test-files.md找到了这个

So, I'm wondering is it possible to achieve this?所以,我想知道是否有可能实现这一目标?

The problem was solved.问题解决了。 Here's the solution:这是解决方案:

{
    "scripts": {
        "test": "ava -v --serial --timeout='2m' -- <arg1> <arg2>"
    }
}
npm test <arg3>

I removed one of the '--' from the script and it works.我从脚本中删除了一个“--”,它可以工作。 Not sure why, feel free to tell me if anyone knows it.不知道为什么,如果有人知道,请随时告诉我。 Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM