jeffrifwald / babel-istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
144 stars 23 forks source link

When using the option --use-babel-runtime the generated code will not require the runtime #7

Closed silkentrance closed 9 years ago

silkentrance commented 9 years ago

I am trying to instrument a source that uses generators and iterators.Invoking

babel-istanbul instrument --use-babel-runtime src/ --output instrumented/

will produce instrumented code that does not include the required runtime.

Which might be due to the fact that

optional    []  Array of transformers to optionally use. Run babel --help to see a full list of transformers. Optional transformers displayed inside square brackets.

and you simply pass in

lines 444ff@lib/instrumenter.js

            if (this.opts.useBabelRuntime) {
                babelConfig.optional = 'runtime';
            }

Yet, when patching the code so that it will pass in an array, it will still not work. Might this be related to the fact, that the babel specific options are never actually processed in lib/command/instrument.js?

jeffrifwald commented 9 years ago

Are you wanting the whole runtime included in your instrumented code? I'm not sure I see a use case there, as you'll be including a bunch of code that might not get covered.

--use-babel-runtime passes a flag to babel tells the compiler to use the babel-runtime instead of generating verbose code every time. The instrumented code should never include the actual runtime, but it will reference helper functions from babel-runtime instead.

silkentrance commented 9 years ago

No, of course not, it should still be optional. It seems though, as if the option is not being evaluated at all:

This is the this.opts from the instrumenter:

{"coverageVariable":"__coverage__","embedSource":false,"noCompact":false,"preserveComments":false}

As you can see, the instrument command will not properly configure the options from the command line...

jeffrifwald commented 9 years ago

Ah, I set up the commands for run-with-cover specifically. You are using the instrument command. I can update the instrument command to utilize the applicable arguments.

silkentrance commented 9 years ago

Okay, I see. This would be great since it actually makes more sense to have the instrumented code use the runtime, too!

And that way, the boilerplate code would not be analysed for coverage...

TIA!

silkentrance commented 9 years ago

Please do not forget to also change the following lines in lib/instrumenter.js

 444             if (this.opts.useBabelRuntime) {                                                                     
 445                 babelConfig.optional = ['runtime'];                                                              
 446             }

According to the spec, babel expects this to be an array, dunno if it will work with just a string.

jeffrifwald commented 9 years ago

Just published 0.2.5, it should be updated. Thanks!

silkentrance commented 9 years ago

Great, thanks.