You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
Activity
ericmorand commentedon Jul 24, 2024
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:
Is it what you are trying to achieve?
darcyrush commentedon Jul 26, 2024
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 testericmorand commentedon Jul 26, 2024
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:
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:
With this approach, the additional arguments passed after
--would apply toodz report, achieving what you need.