How to use the istanbul.Instrumenter function in istanbul

To help you get started, we’ve selected a few istanbul examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / vscode-azure-blockchain-ethereum / test / index.ts View on Github external
public setupCoverage(): void {
    // Set up Code Coverage, hooking require so that instrumented code is returned
    const self = this;
    self.instrumenter = new istanbul.Instrumenter({ coverageVariable: self.coverageVar });
    const sourceRoot = paths.join(self.testsRoot, self.options.relativeSourcePath);

    // Glob source files
    const srcFiles = glob.sync('**/**.js', {
      cwd: sourceRoot,
      ignore: self.options.ignorePatterns,
    });

    // Create a match function - taken from the run-with-cover.js in istanbul.
    const decache = require('decache');
    const fileMap: any = {};
    srcFiles.forEach((file) => {
      const fullPath = paths.join(sourceRoot, file);
      fileMap[fullPath] = true;

      // On Windows, extension is loaded pre-test hooks and this mean we lose
github litleleprikon / socket-io-vscode / test / index.js View on Github external
setupCoverage() {
        // Set up Code Coverage, hooking require so that instrumented code is returned
        const self = this;
        self.instrumenter = new istanbul.Instrumenter({ coverageVariable: self.coverageVar });
        const sourceRoot = paths.join(self.testsRoot, self.options.relativeSourcePath);
        // Glob source files
        const srcFiles = glob.sync('**/**.js', {
            cwd: sourceRoot,
            ignore: self.options.ignorePatterns,
        });
        // Create a match function - taken from the run-with-cover.js in istanbul.
        const decache = require('decache');
        const fileMap = {};
        srcFiles.forEach((file) => {
            const fullPath = paths.join(sourceRoot, file);
            fileMap[fullPath] = true;
            // On Windows, extension is loaded pre-test hooks and this mean we lose
            // our chance to hook the Require call. In order to instrument the code
            // we have to decache the JS file so on next load it gets instrumented.
            // This doesn"t impact tests, but is a concern if we had some integration
github dlang-vscode / dlang-vscode / test / index.ts View on Github external
public setupCoverage(): void {
        // Set up Code Coverage, hooking require so that instrumented code is returned
        let self = this;
        self.instrumenter = new istanbul.Instrumenter({ coverageVariable: self.coverageVar });
        let sourceRoot = paths.join(self.testsRoot, self.options.relativeSourcePath);

        // Glob source files
        let srcFiles = glob.sync("**/**.js", {
            cwd: sourceRoot,
            ignore: self.options.ignorePatterns,
        });

        // Create a match function - taken from the run-with-cover.js in istanbul.
        let decache = require("decache");
        let fileMap = {};
        srcFiles.forEach((file) => {
            let fullPath = paths.join(sourceRoot, file);
            fileMap[fullPath] = true;

            // On Windows, extension is loaded pre-test hooks and this mean we lose
github maenu / grunt-template-jasmine-istanbul / src / main / js / template.js View on Github external
var instrument = function (source, tmp) {
	var instrumenter = new istanbul.Instrumenter();
	var instrumentedSourceText = instrumenter.instrumentSync(
			grunt.file.read(source), source);
	var instrumentedSource = source;
	// don't try to write "C:" as part of a folder name on Windows
	if (process.platform === 'win32') {
		instrumentedSource = instrumentedSource.replace(/^([a-z]):/i, '$1');
	}
	instrumentedSource = path.join(tmp, instrumentedSource);
	grunt.file.write(instrumentedSource, instrumentedSourceText);
	return instrumentedSource;
};
github walmartlabs / little-loader / test / func / spec / base.spec.js View on Github external
var _covered = function (filePath) {
  var fileName = path.relative(PROJECT_ROOT, filePath);
  var code = fs.readFileSync(filePath);
  var instrumenter = new istanbul.Instrumenter();
  return instrumenter.instrumentSync(code.toString(), fileName);
};
github imodeljs / imodeljs / test-apps / testbed / floss / electron / coverage.js View on Github external
constructor(root, pattern, sourceMaps, htmlReporter, debug) {
        this.root = root;
        this.sourceMaps = !!sourceMaps;
        this.pattern = pattern;
        this.htmlReporter = !!htmlReporter;
        this.debug = !!debug;
        this.instrumenter = new Instrumenter();
        this.transformer = this.instrumenter.instrumentSync.bind(this.instrumenter);
        this.cov = global.__coverage__ = {};
        this.matched = this.match();
        hook.hookRequire(this.matched, this.transformer, {});
    }
github joelpurra / bespoke-secondary / gulpfile.js View on Github external
.pipe(map(function(code, filename) {
            var instrumenter = new istanbul.Instrumenter(),
                relativePath = path.relative(__dirname, filename);
            return instrumenter.instrumentSync(code.toString(), relativePath);
        }))
        .pipe(gulp.dest('lib-instrumented'));
github aaronpowell / bespoke-markdown / gulpfile.js View on Github external
.pipe(map(function(code, filename) {
      var instrumenter = new istanbul.Instrumenter(),
        relativePath = path.relative(__dirname, filename);
      return instrumenter.instrumentSync(code.toString(), relativePath);
    }))
    .pipe(gulp.dest('lib-instrumented'));
github bespokejs / generator-bespokeplugin / app / templates / gulpfile.js View on Github external
.pipe(map(function(code, filename) {
      var instrumenter = new istanbul.Instrumenter(),
        relativePath = path.relative(__dirname, filename);
      return instrumenter.instrumentSync(code.toString(), relativePath);
    }))
    .pipe(gulp.dest('lib-instrumented'));
github taichi / grunt-istanbul / tasks / helpers.js View on Github external
addUncoveredFiles: function(coverage, options, allFiles){
      var instrumenter = new istanbul.Instrumenter({coverageVariable: options.coverageVar , preserveComments: false});
      var transformer = instrumenter.instrumentSync.bind(instrumenter);
      allFiles.forEach(function (file) {
        if (!coverage[file]) {
          transformer(fs.readFileSync(file, 'utf-8'), file);
          coverage[file] = instrumenter.coverState;
        }
      });
    },
    storeCoverage : function(coverage, options, done) {

istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests

BSD-3-Clause
Latest version published 8 years ago

Package Health Score

52 / 100
Full package analysis