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

570 views Asked by At

I'm running AVA test now and I have 3 positional arguments that will be passed when running the command. 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.

This is how my test script looks like in package.json file:

{
    "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. I found this from 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?

1

There are 1 answers

2
jialeee17 On

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!