Open darcyrush opened 3 months ago
Hey @darcyrush,
Can I assume that what you want to achieve is to have a cover script in package.json that is sort of pre-parameterized, and you'd like to be able to add some additional flags when you execute it?
Like:
{
"scripts": {
"cover": "c8 --src=src/ npm run test"
}
}
And using it this way, to add the HTML reporter:
npm run cover -- --reporter=html
Is it what you are trying to achieve?
Is it what you are trying to achieve?
Yes exactly, but I need to test more to see if this is a c8 specific issue - this could be the effect of a different underlying library I am using within npm run test
Actually, this is an issue from npm itself, that has been around forever: it is not possible to decide where the additional arguments passed when running the script are injected. In your case, the additional arguments would need to be injected before "npm run test" so that they apply to C8 instead of "npm run test"…but with npm scripts there is no way to achieve such a thing.
The only solution would be to be able to reverse the way the script is executed, to have c8 as the last execute program of the script:
"cover": "npm run test | c8 --src=src/"
But this is not possible because c8 doesn't receive the result of the executed command: it actually executes the passed command, so there is no way to write it like above.
The actual solution would be to have c8 expose a dedicated command to run the passed command, and then another dedicated one to output the report. This is what tools like Coverage.py for Python or my own One Double Zero provide.
By having a dedicated command to run "npm run test", and some dedicated ones to emit the report and check, you can write your npm script this way:
"cover": "odz run npm run test && odz report --src=src/"
With this approach, the additional arguments passed after --
would apply to odz report
, achieving what you need.
v22.4.0
Linux M720q 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
I am executing c8 like so;
Where
npm run test
is a custom defined npm command with its own parameters.Sometimes I need to generate a report, so I do
All good.
Looking at help, it appears that c8 allows additional parameters after the
script
I tried to execute flags like so, but the flags after the
npm run test
script are ignoredHow can I add the flags after the
npm run test
script?