createInstrumenter creates a new instrumenter with the supplied options.
opts
Object instrumenter options. See the documentation for the Instrumenter class.
Instrumenter is the public API for the instrument library.
It is typically used for ES5 code. For ES6 code that you
are already running under babel
use the coverage plugin
instead.
opts
Object optional. (optional, default{}
)opts.coverageVariable
string name of global coverage variable. (optional, default__coverage__
)opts.reportLogic
boolean report boolean value of logical expressions. (optional, defaultfalse
)opts.preserveComments
boolean preserve comments in output. (optional, defaultfalse
)opts.compact
boolean generate compact code. (optional, defaulttrue
)opts.esModules
boolean set to true to instrument ES6 modules. (optional, defaultfalse
)opts.autoWrap
boolean set to true to allowreturn
statements outside of functions. (optional, defaultfalse
)opts.produceSourceMap
boolean set to true to produce a source map for the instrumented code. (optional, defaultfalse
)opts.ignoreClassMethods
Array set to array of class method names to ignore for coverage. (optional, default[]
)opts.sourceMapUrlCallback
Function a callback function that is called when a source map URL is found in the original code. This function is called with the source file name and the source map URL. (optional, defaultnull
)opts.debug
boolean turn debugging on. (optional, defaultfalse
)opts.parserPlugins
array? set babel parser plugins, see @istanbuljs/schema for defaults.opts.coverageGlobalScope
string the global coverage variable scope. (optional, defaultthis
)opts.coverageGlobalScopeFunc
boolean use an evaluated function to find coverageGlobalScope. (optional, defaulttrue
)opts.generatorOpts
Object? set babel generator options
instrument the supplied code and track coverage against the supplied
filename. It throws if invalid code is passed to it. ES5 and ES6 syntax
is supported. To instrument ES6 modules, make sure that you set the
esModules
property to true
when creating the instrumenter.
code
string the code to instrumentfilename
string the filename against which to track coverage.inputSourceMap
object? the source map that maps the not instrumented code back to it's original form. Is assigned to the coverage object and therefore, is available in the json output and can be used to remap the coverage to the untranspiled source.
Returns string the instrumented code.
callback-style instrument method that calls back with an error as opposed to throwing one. Note that in the current implementation, the callback will be called in the same process tick and is not asynchronous.
code
string the code to instrumentfilename
string the filename against which to track coverage.callback
Function the callbackinputSourceMap
Object the source map that maps the not instrumented code back to it's original form. Is assigned to the coverage object and therefore, is available in the json output and can be used to remap the coverage to the untranspiled source.
returns the file coverage object for the last file instrumented.
Returns Object the file coverage object.
returns the source map produced for the last file instrumented.
Returns (null | Object) the source map object.
programVisitor is a babel
adaptor for instrumentation.
It returns an object with two methods enter
and exit
.
These should be assigned to or called from Program
entry and exit functions
in a babel visitor.
These functions do not make assumptions about the state set by Babel and thus
can be used in a context other than a Babel plugin.
The exit function returns an object that currently has the following keys:
fileCoverage
- the file coverage object created for the source file.
sourceMappingURL
- any source mapping URL found when processing the file.
types
Object an instance of babel-types.sourceFilePath
string the path to source file. (optional, default'unknown.js'
)opts
Object additional options. (optional, default{}
)opts.coverageVariable
string the global coverage variable name. (optional, default__coverage__
)opts.reportLogic
boolean report boolean value of logical expressions. (optional, defaultfalse
)opts.coverageGlobalScope
string the global coverage variable scope. (optional, defaultthis
)opts.coverageGlobalScopeFunc
boolean use an evaluated function to find coverageGlobalScope. (optional, defaulttrue
)opts.ignoreClassMethods
Array names of methods to ignore by default on classes. (optional, default[]
)opts.inputSourceMap
object the input source map, that maps the uninstrumented code back to the original code. (optional, defaultundefined
)