How to use the Instrumenter function from istanbul

Find comprehensive JavaScript istanbul.Instrumenter code examples handpicked from public code repositorys.

41
42
43
44
45
46
47
48
49

// Return a transform function that transforms a file and records the original
// source and a source map in the given sets
const transformer = (sources, maps, transformers) => {
  // Set up an instrument function that will instrument the relevant code
  const instrumenter = new istanbul.Instrumenter({
    coverageVariable: '__coverage',
    preserveComments: true
  });
fork icon89
star icon0
watch icon1

20
21
22
23
24
25
26
27
28
29

var plugin = module.exports = function (opts) {
  opts = opts || {};
  _.defaults(opts, {
    coverageVariable: COVERAGE_VARIABLE,
    instrumenter: istanbul.Instrumenter
  });
  opts.includeUntested = opts.includeUntested === true;

  return through(function (file, enc, cb) {
fork icon87
star icon186
watch icon6

+ 9 other calls in file

147
148
149
150
151
152
153
154
155
156
  collectReports(opts);
};

var istanbulMatcherRun = function istanbulMatcherRun(matchFn) {

  var instrumenter = new istanbul.Instrumenter({coverageVariable: coverageVar});
  var transformer = instrumenter.instrumentSync.bind(instrumenter);
  var hookOpts = {verbose: options.isVerbose};

  istanbul.hook.hookRequire(matchFn, transformer, hookOpts);
fork icon23
star icon28
watch icon9

+ 3 other calls in file

22
23
24
25
26
27
28
29
30
31
  return !!fileMap[path];
}, function (code, path) {
  return fileMap[path];
});

var instrumenter = new istanbul.Instrumenter(opts);

return through(function (file, enc, cb) {
  if (!(file.contents instanceof Buffer)) {
    return cb(new PluginError(PLUGIN_NAME, 'streams not supported'), undefined);
fork icon87
star icon0
watch icon2

65
66
67
68
69
70
71
72
73
74
      var transformFctName = '_' + metricMapName + 'Transformer';
      var transformedMetricMap = this[transformFctName](metricMap, metrics);
      this.coverState[metricMapName] = transformedMetricMap;
    }.bind(this));

  return istanbul.Instrumenter.prototype.getPreamble.call(this, sourceCode, emitUseStrict);
};

Instrumenter.prototype._statementMapTransformer = function(metrics) {
  return Object.keys(metrics)
fork icon102
star icon0
watch icon3

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
var fs              = require('fs');
var path            = require('path');
var istanbul        = require('istanbul');
var HttpProxy       = require('../lib/httpProxy');

var instrumenter    = new istanbul.Instrumenter({
    embedSource: true,
    noAutoWrap: true
});
fork icon17
star icon153
watch icon7

52
53
54
55
56
57
58
59
60
61

// Is coverage requested?
if (((coverage === undefined) || (coverage === true)) && globalCoverageConfig.active) {

    // Prepare coverage instrumentation
    instrumenter = new istanbul.Instrumenter({ coverageVariable: coverageVar, preserveComments: true });
    transformer = instrumenter.instrumentSync.bind(instrumenter);

    // Hook-up transformer for every new file loaded
    istanbul.hook.hookRequire(function (filePath) {
fork icon7
star icon0
watch icon2

+ 5 other calls in file

63
64
65
66
67
68
69
70
71

var FILENAME = 'freak.js';
var fs = require('fs');
var file = fs.readFileSync(FILENAME).toString();
var istanbul = require('istanbul');
var instrumenter = new istanbul.Instrumenter();
var instrumented = instrumenter.instrumentSync(file, FILENAME);
var freak = requireFromString(instrumented);
-->
fork icon0
star icon25
watch icon6

17
18
19
20
21
22
23
24
25
function Instrumenter(options) {
  if (!options) {
    options = {};
  }

  istanbul.Instrumenter.call(this, options); // Call super constructor

  return this;
}
fork icon102
star icon0
watch icon2

+ 3 other calls in file

12
13
14
15
16
17
18
19
20
var temp = require('temp');

var mkdirp = require('mkdirp');

var istanbul = require('istanbul');
var Instrumenter = istanbul.Instrumenter;
var Collector = istanbul.Collector;
var Report = istanbul.Report;
var Store = istanbul.Store;
fork icon3
star icon2
watch icon2

5
6
7
8
9
10
11
12
13
14

let testNumber = parseInt(process.env.TESTNUMBER, 10)

let istanbul = require('istanbul')

let localInstrumenter = new istanbul.Instrumenter({
  coverageVariable: '__coverage__',
  instrumenter: istanbul.Instrumenter
})
let localCollector = new istanbul.Collector()
fork icon0
star icon0
watch icon2

+ 3 other calls in file

-1
fork icon0
star icon0
watch icon16

+ 7 other calls in file

85
86
87
88
89
90
91
92
93
if(error) {
        return console.error(error);
}

var coverageVar = '$$cov_' + new Date().getTime() + '$$';
var instrumenter = new istanbul.Instrumenter({
        coverageVariable: coverageVar,
        preserveComments: true
});
fork icon0
star icon0
watch icon2

+ 7 other calls in file

40
41
42
43
44
45
46
47
48
49
options = options || {};
options.coverageVariable = '__coverageId';
if (this.instrumenter) {
    return;
}
this.instrumenter = new istanbul.Instrumenter(options);
var transformer = this.instrumenter.instrumentSync.bind(this.instrumenter);
var me = this;
var hook = istanbul.hook;
hook.hookRequire(matchFunc, transformer, {
fork icon0
star icon0
watch icon1