createInstrumenter
November 10, 2016 ยท View on GitHub
createInstrumenter creates a new instrumenter with the supplied options.
Parameters
optsObject instrumenter options. See the documentation for the Instrumenter class.
Instrumenter
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.
Parameters
optsObject optional.opts.coverageVariable[string] name of global coverage variable. (optional, default__coverage__)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 allowreturnstatements outside of functions. (optional, defaultfalse)opts.produceSourceMap[boolean] set to true to produce a source map for the instrumented code. (optional, defaultfalse)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)
instrumentSync
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.
Parameters
codestring the code to instrumentfilenamestring 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.
instrument
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.
Parameters
codestring the code to instrumentfilenamestring the filename against which to track coverage.callbackFunction the callbackinputSourceMapObject 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.
lastFileCoverage
returns the file coverage object for the last file instrumented.
Returns Object the file coverage object.
lastSourceMap
returns the source map produced for the last file instrumented.
Returns (null | Object) the source map object.
programVisitor
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.
Parameters