I'm looking for ways to pass arguments to my ava test file via command line and I found this documentation. https://github.com/avajs/ava/blob/main/docs/recipes/passing-arguments-to-your-test-files.md
// test.js const test = require('ava');
test('argv', t => {
t.deepEqual(process.argv.slice(2), ['--hello', 'world']);
});
$ npx ava -- --hello world
I was wondering that what this code is actually doing but I can't find other related topic online talking about this. Is there anyone who can explain to me?
This code is just showing you that in node - and therefore also in
ava, the arguments are available on the arrayprocess.argv. You can find it documented hereThe
slice(2)just trims off the first two elements of the array. From the documentation I linked above, this is because:So your arguments start at
process.argv[2].The
t.deepEqualis just illustrative to show the reader that the value ofprocess.argv.slice(2)is: