Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate coverage for required files passed as args in spawn #463

Closed
jaridmargolin opened this issue Dec 6, 2016 · 2 comments
Closed

Generate coverage for required files passed as args in spawn #463

jaridmargolin opened this issue Dec 6, 2016 · 2 comments

Comments

@jaridmargolin
Copy link

Imagine the following code written inside of a testcase.

spawn('node', [
   '--require',
   './lib/index.js',
    'test/fixtures/syntax-error.js'
]);

I am attempting to generate coverage for ./lib/index.js.

Expected Behavior

Coverage is generated for ./lib/index.js

Observed Behavior

No coverage is generated.

@jaridmargolin
Copy link
Author

@bcoe do you agree that the expected behavior would be to generate coverage?

I have absolutely no insight into the inner workings of istanbul / nyc, but if you agree with the overall direction, I will take a stab at a PR. Additionally if you had any thoughts / ideas about the implementation, feel free to share :)

Thanks!

@stale stale bot added the wontfix label Jan 6, 2019
@stale stale bot added the stale label Mar 7, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Mar 7, 2019
@stale stale bot removed the stale label Mar 7, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Mar 7, 2019
@coreyfarrell
Copy link
Member

This is not directly possible. I think the problem is that --require modules are loaded before nyc can hook the loader system. To accomplish your goal you will need to pre-instrument your code using:

nyc instrument ${PWD}/lib/index.js > lib/index-covered.js

Then in your test:

spawn('node', [
   '--require',
   './lib/index-covered.js',
    'test/fixtures/syntax-error.js'
]);

FYI the ${PWD} is needed for now to work around #1014. Once that is fixed you'll be able to just nyc instrument lib/index.js > lib/index-covered.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants