How to use istanbul

Comprehensive istanbul code examples:

How to use istanbul.call:

8
9
10
11
12
13
14
15
16
var util = require('util')
var Store = require('istanbul').Store

// Constructor
var SourceCacheStore = module.exports = function (opts) {
  Store.call(this, opts)
  opts = opts || {}
  this.sourceCache = opts.sourceCache
}

How to use istanbul._yuiLoadHook:

72
73
74
75
76
77
78
79
80
81
  }
});
Object.defineProperty(exports, '_yuiLoadHook', {
  enumerable: true,
  get: function get() {
    return _istanbul._yuiLoadHook;
  }
});
Object.defineProperty(exports, 'TreeSummarizer', {
  enumerable: true,

How to use istanbul.Writer:

54
55
56
57
58
59
60
61
62
63
  }
});
Object.defineProperty(exports, 'Writer', {
  enumerable: true,
  get: function get() {
    return _istanbul.Writer;
  }
});
Object.defineProperty(exports, 'ContentWriter', {
  enumerable: true,

How to use istanbul.assetsDir:

84
85
86
87
88
89
90
91
92
93
  }
});
Object.defineProperty(exports, 'assetsDir', {
  enumerable: true,
  get: function get() {
    return _istanbul.assetsDir;
  }
});

var _instrumenter = require('./instrumenter');

How to use istanbul.FileWriter:

66
67
68
69
70
71
72
73
74
75
  }
});
Object.defineProperty(exports, 'FileWriter', {
  enumerable: true,
  get: function get() {
    return _istanbul.FileWriter;
  }
});
Object.defineProperty(exports, '_yuiLoadHook', {
  enumerable: true,

How to use istanbul.ContentWriter:

60
61
62
63
64
65
66
67
68
69
  }
});
Object.defineProperty(exports, 'ContentWriter', {
  enumerable: true,
  get: function get() {
    return _istanbul.ContentWriter;
  }
});
Object.defineProperty(exports, 'FileWriter', {
  enumerable: true,

How to use istanbul.hookRequire:

100
101
102
103
104
105
106
107
108

var coverageVar = "$$cov_" + Date.now() + "$$";
var instrumenter = new Instrumenter({ coverageVariable: coverageVar });
var transformer = instrumenter.instrumentSync.bind(instrumenter);

hook.hookRequire(matchFn, transformer, { verbose: opts.verbose });

//initialize the global variable to stop mocha from complaining about leaks
global[coverageVar] = {};

How to use istanbul.TreeSummarizer:

78
79
80
81
82
83
84
85
86
87
  }
});
Object.defineProperty(exports, 'TreeSummarizer', {
  enumerable: true,
  get: function get() {
    return _istanbul.TreeSummarizer;
  }
});
Object.defineProperty(exports, 'assetsDir', {
  enumerable: true,

How to use istanbul.Store:

15
16
17
18
19
20
21
22
23
24

var istanbul = require('istanbul');
var Instrumenter = istanbul.Instrumenter;
var Collector = istanbul.Collector;
var Report = istanbul.Report;
var Store = istanbul.Store;


function isMyIp(ip) {
    var networkInterfaces = os.networkInterfaces();

How to use istanbul.matcherFor:

20
21
22
23
24
25
26
27
28
29
};
core.getCoverageObject = getCoverageObject;

//returns a matcher that returns all JS files under root
//except when the file is anywhere under `node_modules`
//does not use istanbul.matcherFor() so as to expose
//a synchronous interface
function getRootMatcher(root) {
    return function (file) {
        if (file.indexOf(root) !== 0) {

How to use istanbul.config:

30
31
32
33
34
35
36
37
38
39
  }
});
Object.defineProperty(exports, 'config', {
  enumerable: true,
  get: function get() {
    return _istanbul.config;
  }
});
Object.defineProperty(exports, 'Reporter', {
  enumerable: true,

How to use istanbul.Reporter:

264
265
266
267
268
269
270
271
272
273
var options = this.coverage;
if (!options) {
  return;
}

var reporter = new istanbul.Reporter(false, options.dir);
var collector = new istanbul.Collector();
var formats = options.reporters ? _.toArray(options.reporters) : ['text'];

// If we are reporting text to the command line we need to add a newline

How to use istanbul.utils:

109
110
111
112
113
114
115
116
117
118

  if (!global[opts.coverageVariable]) throw new Error('no coverage data found, run tests before calling `summarizeCoverage`');

  var collector = new Collector();
  collector.add(global[opts.coverageVariable]);
  return istanbul.utils.summarizeCoverage(collector.getFinalCoverage());
};

plugin.writeReports = function (opts) {
  if (typeof opts === 'string') opts = { dir: opts };

How to use istanbul.Report:

5
6
7
8
9
10
11
12
13
14
// Make sure istanbul is `require`d after the istanbul-threshold-checker to use the istanbul version
// defined in this package.json instead of the one defined in istanbul-threshold-checker.
var istanbul = require('istanbul');
var _ = require('lodash');
var applySourceMap = require('vinyl-sourcemaps-apply');
var Report = istanbul.Report;
var Collector = istanbul.Collector;
var PluginError = require('plugin-error');

var PLUGIN_NAME = 'gulp-istanbul';

How to use istanbul.hook:

135
136
137
138
139
140
141
142
143
144
// match our instrumentMatcher
const sources = {};
const maps = [];
const transformers = [];
if (commander.istanbul)
  istanbul.hook.hookRequire(
    instrumentMatcher(commander.istanbulIncludes),
    transformer(sources, maps, transformers));

// Save the original process send method as it may be mocked by the tests

How to use istanbul.Instrumenter:

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
  });

How to use istanbul.Collector:

6
7
8
9
10
11
12
13
14
15
// defined in this package.json instead of the one defined in istanbul-threshold-checker.
var istanbul = require('istanbul');
var _ = require('lodash');
var applySourceMap = require('vinyl-sourcemaps-apply');
var Report = istanbul.Report;
var Collector = istanbul.Collector;
var PluginError = require('plugin-error');

var PLUGIN_NAME = 'gulp-istanbul';
var COVERAGE_VARIABLE = '$$cov_' + new Date().getTime() + '$$';