How to use the istanbul-lib-coverage.classes.FileCoverage function in istanbul-lib-coverage

To help you get started, we’ve selected a few istanbul-lib-coverage 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 istanbuljs / istanbuljs / test / util / verifier.js View on Github external
import Instrumenter from '../../src/instrumenter';
import {classes} from 'istanbul-lib-coverage';
import {assert} from 'chai';
import clone from 'clone';
import readInitialCoverage from '../../src/read-coverage';

var FileCoverage = classes.FileCoverage;

function pad(str, len) {
    var blanks = '                                             ';
    if (str.length >= len) {
        return str;
    }
    return blanks.substring(0, len - str.length) + str;
}

function annotatedCode(code) {
    var codeArray = code.split('\n'),
        line = 0,
        annotated = codeArray.map(function (str) {
            line += 1;
            return pad(line, 6) + ': ' + str;
        });
github istanbuljs / istanbuljs / packages / istanbul-lib-instrument / src / source-coverage.js View on Github external
line: loc && loc.end.line,
            column: loc && loc.end.column
        }
    };
}
/**
 * SourceCoverage provides mutation methods to manipulate the structure of
 * a file coverage object. Used by the instrumenter to create a full coverage
 * object for a file incrementally.
 *
 * @private
 * @param pathOrObj {String|Object} - see the argument for {@link FileCoverage}
 * @extends FileCoverage
 * @constructor
 */
class SourceCoverage extends classes.FileCoverage {
    constructor(pathOrObj) {
        super(pathOrObj);
        this.meta = {
            last: {
                s: 0,
                f: 0,
                b: 0
            }
        };
    }

    newStatement(loc) {
        const s = this.meta.last.s;
        this.data.statementMap[s] = cloneLocation(loc);
        this.data.s[s] = 0;
        this.meta.last.s += 1;