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

Use istanbul-lib-hook to wrap require and support vm hooks #308

Merged
merged 3 commits into from
Jul 14, 2016

Conversation

gotwarlost
Copy link
Collaborator

@gotwarlost gotwarlost commented Jul 10, 2016

Interface changes

  • Add --hook-run-in-context (default: true) to the nyc command line
  • Add --temp-directory <dir> to the report command line. This is not a full implementation of a customizable tmpdir but only the bare minimum required to support self-coverage reporting for nyc. The full implementation is described in Add the ability to specify a custom tempDirectory #171

Misc changes

  • Remove istanbul dev dependency in favor of APIs that are already being used, so that we don't accidentally use code from the old module any more. (I think the text reporter was being pulled in from the old lib).
  • Coverage reporting is now done by nyc itself at the end of tests and this necessitates the custom temp-directory option for reporting.

Implementation

  • Use istanbul-lib-hook to wrap require and hook vm.runInThisContext
  • Add --hook-run-in-context option and propagate to subprocesses using the NYC_HOOK_RUN_IN_CONTEXT environment var
  • Add a test that will succeed only if runInThisContext is successfully hooked.
  • Replace istanbul API use with istanbul-lib-instrument and command line use with nyc itself.

@gotwarlost
Copy link
Collaborator Author

Some questions:

  • I added requirejs as a dev dependency although it is actually a dependency of the test project. Is this correct or should we be doing an npm install from the test project directory before running its test?
  • there is no equivalent test for these hooks apart from the CLI test. Is this needed?

Link main issue for cross-ref: #292

@coveralls
Copy link

coveralls commented Jul 10, 2016

Coverage Status

Changes Unknown when pulling d28153c on gotwarlost:libhook into * on istanbuljs:master*.

@gotwarlost
Copy link
Collaborator Author

No idea why the appveyor build is failing. Need help.

@bcoe
Copy link
Member

bcoe commented Jul 10, 2016

@gotwarlost AppVeyor just fails a good chunk of the time, nothing to do with this pull as long as I can tell. re-kicked it off.

description: 'should nyc wrap vm.runInThisContext?'
})
.option('hook-create-script', {
default: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've tried to be fairly batteries included so far, for instance we already instrument subprocesses right out of the gate. I might be tempted to default this to true. I'm happy with the argument name 👍

@bcoe
Copy link
Member

bcoe commented Jul 10, 2016

This is looking great 🎉 to land this I think all we'd need to to do would be:

  • add a test for vm.createScript, I don't think I saw one?
  • address the couple small issues:
    • I think that enabling the new instrumentation settings by default would be smart (@jamestalmage what are your thoughts?).
    • I'd be tempted to use 'enable' rather than 'true' when passing configuration around in the env.
  • finally, I'd also like to spin up my Windows VM and run this against a few projects once we're happy.

@gotwarlost
Copy link
Collaborator Author

Thanks for the detailed feedback.

  • I think I'm going to remove the vm.createScript hook. The problem is that there is no place to stash the original code that was used for createScript. This is because, the instrumenter no longer supports the notion of embedding the source as part of the file coverage object. So if we ended up hooking vm.createScript the HTML report won't be able to find the original source. If someone really, really needs this we can add back the notion of embedding the source into the instrumenter and then implementing this. Even in istanbul this is a fairly exotic case and I don't believe it works correctly even today.
  • I will change the setting to enable|disable instead of true|false and enable it by default

@bcoe
Copy link
Member

bcoe commented Jul 11, 2016

@gotwarlost awesome, are you feeling like we're getting close to being able to point existing Istanbul users towards the Istanbul 1.0 APIs, and nyc? I've been having great luck as I test the new libraries against everything I throw at them, awesome work :) I wish we'd kicked this in motion sooner!

@gotwarlost gotwarlost changed the title [Do not merge: sketch] Use istanbul-lib-hook to wrap require and support vm hooks Use istanbul-lib-hook to wrap require and support vm hooks Jul 11, 2016
@coveralls
Copy link

coveralls commented Jul 11, 2016

Coverage Status

Changes Unknown when pulling 03866c9 on gotwarlost:libhook into * on istanbuljs:master*.

@gotwarlost
Copy link
Collaborator Author

@bcoe I think we are getting real close, it's probably already much better than istanbul. One problem is that it is not backwards compatible and we need to go through a documentation exercise and more importantly, provide a conversion program that will take a istanbul.yaml and turn it into a nyc config file, showing warnings with unsupported features etc.

I think a big gap from istanbul.yaml is the inability to configure reporting details in nyc (e.g. set the text reporter to write to a file, for example), but those are minority use-cases.

@gotwarlost
Copy link
Collaborator Author

OK, the latest commit has all the PR comments included in it. Please take a look. I can squash commits after things look ok. Specifically, please check bundle dependency changes in package.json - I'm not quite sure abut what I did there.

@gotwarlost
Copy link
Collaborator Author

Also, I'm not sure if coveralls not being able to tell how coverage changed is a regression in the way lcov info is being fed to it (lcov now generated using nyc instead of istanbul)

@bcoe
Copy link
Member

bcoe commented Jul 12, 2016

@gotwarlost this is feeling like a coveralls.io issue, I find there's a lot of weirdness with various services when I transfer repo ownership.

@bcoe bcoe merged commit 2b64cf8 into istanbuljs:master Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants