Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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;
};
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);
};
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, {});
}
.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'));
.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'));
.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'));
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) {