Skip to content

Latest commit

 

History

History
136 lines (93 loc) · 5.61 KB

api.md

File metadata and controls

136 lines (93 loc) · 5.61 KB

Table of Contents

createInstrumenter

createInstrumenter creates a new instrumenter with the supplied options.

Parameters

  • opts Object 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

  • opts Object optional. (optional, default defaultOpts())
    • opts.coverageVariable string name of global coverage variable. (optional, default __coverage__)
    • opts.preserveComments boolean preserve comments in output (optional, default false)
    • opts.compact boolean generate compact code. (optional, default true)
    • opts.esModules boolean set to true to instrument ES6 modules. (optional, default false)
    • opts.autoWrap boolean set to true to allow return statements outside of functions. (optional, default false)
    • opts.produceSourceMap boolean set to true to produce a source map for the instrumented code. (optional, default false)
    • 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, default null)
    • opts.debug boolean turn debugging on (optional, default false)
    • opts.staticType string one of flow or typescript (optional, default 'flow')
    • opts.plugins array set plugins (optional, default [])

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

  • code string the code to instrument
  • filename 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.

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

  • code string the code to instrument
  • filename string the filename against which to track coverage.
  • callback Function the callback
  • 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.

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

  • types Object an instance of babel-types
  • sourceFilePath string the path to source file (optional, default 'unknown.js')
  • opts Object additional options (optional, default defaultProgramVisitorOpts)
    • opts.coverageVariable string the global coverage variable name. (optional, default __coverage__)
    • 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, default undefined)