0

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?

jialeee17
  • 601
  • 2
  • 7
  • 12

1 Answers1

0

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!

jialeee17
  • 601
  • 2
  • 7
  • 12
  • 1
    The double `--` are when you use `npm test`, so `npm test --` terminates the npm arguments, passing everything to the last command in the `test` script; so then the second `--` terminates the AVA arguments. Because you're updating the `test` script itself you don't need the `--` to terminate the npm arguments. – Mark Wubben Nov 09 '21 at 09:52
  • I see. Thanksss! – jialeee17 Nov 10 '21 at 00:17