Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istanbul

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

lib/configuration.js

6

CHANGELOG.md

@@ -5,2 +5,8 @@ Changelog

<table>
<tr>
<td>v0.2.3</td><td><ul>
<li>Add YAML config file. `istanbul help config` has more details</li>
<li>Support custom reporting thresholds using the `watermarks` section of the config file</li>
</ul></td>
</tr>
<tr><td>v0.2.2</td><td>update escodegen, handlebars and resolve dependency versions</td></tr>

@@ -7,0 +13,0 @@ <tr>

80

lib/command/common/run-with-cover.js

@@ -20,7 +20,10 @@ /*

resolve = require('resolve'),
configuration = require('../../configuration'),
DEFAULT_REPORT_FORMAT = 'lcov';
function usage(arg0, command) {
console.error('\nUsage: ' + arg0 + ' ' + command + ' [<options>] <executable-js-file-or-command> [-- <arguments-to-jsfile>]\n\nOptions are:\n\n'
+ [
formatOption('--config <path-to-config>', 'the configuration file to use, defaults to .istanbul.yml'),
formatOption('--root <path> ', 'the root path to look for files to instrument, defaults to .'),

@@ -31,3 +34,3 @@ formatOption('-x <exclude-pattern> [-x <exclude-pattern>]', 'one or more fileset patterns e.g. "**/vendor/**"'),

formatOption('--post-require-hook <file> | <module>', 'JS module that exports a function for post-require processing'),
formatOption('--report <report-type>', 'report type, one of html, lcov, lcovonly, none, defaults to lcov (= lcov.info + HTML)'),
formatOption('--report <format> [--report <format>] ', 'report format, defaults to lcov (= lcov.info + HTML)'),
formatOption('--dir <report-dir>', 'report directory, defaults to ./coverage'),

@@ -42,6 +45,7 @@ formatOption('--print <type>', 'type of report to print to console, one of summary (default), detail, both or none'),

var config = {
var template = {
config: path,
root: path,
x: [Array, String],
report: String,
x: [ Array, String ],
report: [Array, String ],
dir: path,

@@ -56,3 +60,24 @@ verbose: Boolean,

},
opts = nopt(config, { v : '--verbose' }, args, 0),
opts = nopt(template, { v : '--verbose' }, args, 0),
overrides = {
verbose: opts.verbose,
instrumentation: {
root: opts.root,
'default-excludes': opts['default-excludes'],
excludes: opts.x
},
reporting: {
reports: opts.report,
print: opts.print,
dir: opts.dir
},
hooks: {
'hook-run-in-context': opts['hook-run-in-context'],
'post-require-hook': opts['post-require-hook']
}
},
config = configuration.loadFile(opts.config, overrides),
watermarks = config.reporting.watermarks(),
reportOpts,
verbose = config.verbose,
cmdAndArgs = opts.argv.remain,

@@ -62,3 +87,2 @@ cmd,

reportingDir,
reportClassName,
reports = [],

@@ -87,3 +111,3 @@ runFn,

process.argv = ["node", cmd].concat(cmdArgs);
if (opts.verbose) {
if (verbose) {
console.log('Running: ' + process.argv.join(' '));

@@ -95,22 +119,22 @@ }

excludes = typeof opts['default-excludes'] === 'undefined' || opts['default-excludes'] ?
[ '**/node_modules/**', '**/test/**', '**/tests/**' ] : [];
excludes.push.apply(excludes, opts.x);
excludes = config.instrumentation.excludes(true);
if (enableHooks) {
reportingDir = opts.dir || path.resolve(process.cwd(), 'coverage');
reportingDir = path.resolve(config.reporting.dir());
reportOpts = { dir: reportingDir, watermarks: watermarks };
mkdirp.sync(reportingDir); //ensure we fail early if we cannot do this
reportClassName = opts.report || DEFAULT_REPORT_FORMAT;
reports.push(Report.create(reportClassName, { dir: reportingDir }));
if (opts.print !== 'none') {
switch (opts.print) {
reports.push.apply(reports, config.reporting.reports().map(function (r) {
return Report.create(r, reportOpts);
}));
if (config.reporting.print() !== 'none') {
switch (config.reporting.print()) {
case 'detail':
reports.push(Report.create('text'));
reports.push(Report.create('text', reportOpts));
break;
case 'both':
reports.push(Report.create('text'));
reports.push(Report.create('text-summary'));
reports.push(Report.create('text', reportOpts));
reports.push(Report.create('text-summary', reportOpts));
break;
default:
reports.push(Report.create('text-summary'));
reports.push(Report.create('text-summary', reportOpts));
break;

@@ -121,3 +145,3 @@ }

matcherFor({
root: opts.root || process.cwd(),
root: config.instrumentation.root() || process.cwd(),
includes: [ '**/*.js' ],

@@ -132,4 +156,4 @@ excludes: excludes

transformer = instrumenter.instrumentSync.bind(instrumenter),
hookOpts = { verbose: opts.verbose },
postRequireHook = opts['post-require-hook'],
hookOpts = { verbose: verbose },
postRequireHook = config.hooks.postRequireHook(),
postLoadHookFile;

@@ -148,3 +172,3 @@

} catch (ex) {
if (opts.verbose) { console.error('Unable to resolve [' + postRequireHook + '] as a node module'); }
if (verbose) { console.error('Unable to resolve [' + postRequireHook + '] as a node module'); }
}

@@ -154,4 +178,4 @@ }

if (postLoadHookFile) {
if (opts.verbose) { console.log('Use post-load-hook: ' + postLoadHookFile); }
hookOpts.postLoadHook = require(postLoadHookFile)(matchFn, transformer, opts.verbose);
if (verbose) { console.error('Use post-load-hook: ' + postLoadHookFile); }
hookOpts.postLoadHook = require(postLoadHookFile)(matchFn, transformer, verbose);
}

@@ -163,3 +187,3 @@

// runInThisContext is used by RequireJS [issue #23]
if (opts['hook-run-in-context']) {
if (config.hooks.hookRunInContext()) {
hook.hookRunInThisContext(matchFn, transformer, hookOpts);

@@ -185,3 +209,3 @@ }

mkdirp.sync(reportingDir); //yes, do this again since some test runners could clean the dir initially created
if (opts.print !== 'none') {
if (config.reporting.print() !== 'none') {
console.error('=============================================================================');

@@ -193,3 +217,3 @@ console.error('Writing coverage object [' + file + ']');

collector.add(cov);
if (opts.print !== 'none') {
if (config.reporting.print() !== 'none') {
console.error('Writing coverage reports at [' + reportingDir + ']');

@@ -196,0 +220,0 @@ console.error('=============================================================================');

@@ -9,4 +9,31 @@ /*

formatOption = require('../util/help-formatter').formatOption,
VERSION = require('../../index').VERSION;
VERSION = require('../../index').VERSION,
configuration = require('../configuration'),
yaml = require('js-yaml'),
formatPara = require('../util/help-formatter').formatPara;
function showConfigHelp(toolName) {
console.error('\nConfiguring ' + toolName);
console.error('====================');
console.error('\n' +
formatPara(toolName + ' can be configured globally using a .istanbul.yml YAML file ' +
'at the root of your source tree. Every command also accepts a --config=<config-file> argument to ' +
'customize its location per command. The alternate config file can be in YAML, JSON or node.js ' +
'(exporting the config object).'));
console.error('\n' +
formatPara('The config file currently has three sections for instrumentation, reporting and hooks. ' +
'Note that certain commands (like `cover`) use information from multiple sections.'));
console.error('\n' +
formatPara('Keys in the config file usually correspond to command line parameters with the same name. ' +
'The verbose option for every command shows you the exact configuration used'));
console.error('\nThe default configuration is as follows:\n');
console.error(yaml.safeDump(configuration.defaultConfig(), { indent: 4, flowLevel: 3 }));
console.error('\n' +
formatPara('The `watermarks` section does not have a command line equivalent. It allows you to set up ' +
'low and high watermark percentages for reporting. These are honored by all reporters that colorize ' +
'their output based on low/ medium/ high coverage'));
}
function HelpCommand() {

@@ -26,3 +53,4 @@ Command.call(this);

console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <command>\n');
console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' config | <command>\n');
console.error('`config` provides help with istanbul configuration\n');
console.error('Available commands are:\n');

@@ -45,8 +73,12 @@

} else {
try {
command = Command.create(args[0]);
command.usage('istanbul', Command.resolveCommandName(args[0]));
} catch (ex) {
console.error('Invalid command: ' + args[0]);
this.usage();
if (args[0] === 'config') {
showConfigHelp(this.toolName());
} else {
try {
command = Command.create(args[0]);
command.usage('istanbul', Command.resolveCommandName(args[0]));
} catch (ex) {
console.error('Invalid command: ' + args[0]);
this.usage();
}
}

@@ -53,0 +85,0 @@ }

@@ -19,2 +19,3 @@ /*

flowControl = require('../util/flow-control'),
configuration = require('../configuration'),
verbose;

@@ -143,2 +144,3 @@

[
formatOption('--config <path-to-config>', 'the configuration file to use, defaults to .istanbul.yml'),
formatOption('--output <file-or-dir>', 'The output file or directory. This is required when the input is a directory, ' +

@@ -162,3 +164,4 @@ 'defaults to standard output when input is a file'),

var config = {
var template = {
config: path,
output: path,

@@ -175,3 +178,18 @@ x: [Array, String],

},
opts = nopt(config, { v : '--verbose' }, args, 0),
opts = nopt(template, { v : '--verbose' }, args, 0),
overrides = {
verbose: opts.verbose,
instrumentation: {
variable: opts.variable,
compact: opts.compact,
'embed-source': opts['embed-source'],
'preserve-comments': opts['preserve-comments'],
excludes: opts.x,
'complete-copy': opts['complete-copy'],
'save-baseline': opts['save-baseline'],
'baseline-file': opts['baseline-file']
}
},
config = configuration.loadFile(opts.config, overrides),
iOpts = config.instrumentation,
cmdArgs = opts.argv.remain,

@@ -182,19 +200,13 @@ file,

includes,
instrumenter = new Instrumenter({ coverageVariable: opts.variable }),
needBaseline = opts['save-baseline'],
baselineFile = opts['baseline-file'] || path.resolve(process.cwd(), 'coverage', 'coverage-baseline.json');
instrumenter,
needBaseline = iOpts.saveBaseline(),
baselineFile = path.resolve(iOpts.baselineFile()),
output = opts.output;
verbose = opts.verbose;
verbose = config.verbose;
if (cmdArgs.length !== 1) {
return callback(inputError.create('Need exactly one filename/ dirname argument for the instrument command!'));
}
if (typeof opts.compact === 'undefined') {
opts.compact = true;
}
if (typeof opts['complete-copy'] === 'undefined') {
// false for backward compatibility
opts['complete-copy'] = false;
}
if (opts['complete-copy']) {
if (iOpts.completeCopy()) {
includes = ['**/*'];

@@ -207,6 +219,6 @@ }

instrumenter = new Instrumenter({
coverageVariable: opts.variable,
embedSource: opts['embed-source'],
noCompact: !opts.compact,
preserveComments: opts['preserve-comments']
coverageVariable: iOpts.variable(),
embedSource: iOpts.embedSource(),
noCompact: !iOpts.compact(),
preserveComments: iOpts.preserveComments()
});

@@ -226,17 +238,17 @@

if (stats.isDirectory()) {
if (!opts.output) { return callback(inputError.create('Need an output directory [-o <dir>] when input is a directory!')); }
if (opts.output === file) { return callback(inputError.create('Cannot instrument into the same directory/ file as input!')); }
mkdirp.sync(opts.output);
if (!output) { return callback(inputError.create('Need an output directory [-o <dir>] when input is a directory!')); }
if (output === file) { return callback(inputError.create('Cannot instrument into the same directory/ file as input!')); }
mkdirp.sync(output);
filesFor({
root: file,
includes: includes,
excludes: opts.x || ['**/node_modules/**'],
excludes: opts.x || iOpts.excludes(false), // backwards-compat, *sigh*
relative: true
}, function (err, files) {
if (err) { return callback(err); }
processFiles(instrumenter, file, opts.output, files);
processFiles(instrumenter, file, output, files);
});
} else {
if (opts.output) {
stream = fs.createWriteStream(opts.output);
if (output) {
stream = fs.createWriteStream(output);
} else {

@@ -243,0 +255,0 @@ stream = process.stdout;

@@ -15,3 +15,4 @@ /*

util = require('util'),
Command = require('./index');
Command = require('./index'),
configuration = require('../configuration');

@@ -33,2 +34,3 @@ function ReportCommand() {

[
formatOption('--config <path-to-config>', 'the configuration file to use, defaults to .istanbul.yml'),
formatOption('--root <input-directory>', 'The input root directory for finding coverage files'),

@@ -50,3 +52,4 @@ formatOption('--dir <report-directory>', 'The output directory where files will be written. This defaults to ./coverage/'),

var config = {
var template = {
config: path,
root: path,

@@ -56,3 +59,3 @@ dir: path,

},
opts = nopt(config, { v : '--verbose' }, args, 0),
opts = nopt(template, { v : '--verbose' }, args, 0),
fmtAndArgs = opts.argv.remain,

@@ -63,3 +66,14 @@ fmt = 'lcov',

root,
collector = new Collector();
collector = new Collector(),
config = configuration.loadFile(opts.config, {
verbose: opts.verbose,
reporting: {
dir: opts.dir
}
}),
reportOpts = {
verbose: config.verbose,
dir: config.reporting.dir(),
watermarks: config.reporting.watermarks()
};

@@ -74,6 +88,4 @@ if (fmtAndArgs.length > 0) {

opts.dir = opts.dir || path.resolve(process.cwd(), 'coverage');
try {
reporter = Report.create(fmt, opts);
reporter = Report.create(fmt, reportOpts);
} catch (ex) {

@@ -80,0 +92,0 @@ return callback(inputError.create('Invalid report format [' + fmt + ']'));

@@ -8,2 +8,3 @@ /*

var handlebars = require('handlebars'),
defaults = require('./common/defaults'),
path = require('path'),

@@ -299,7 +300,7 @@ SEP = path.sep || '/',

function getReportClass(stats) {
function getReportClass(stats, watermark) {
var coveragePct = stats.pct,
identity = 1;
if (coveragePct * identity === coveragePct) {
return coveragePct >= 80 ? 'high' : coveragePct >= 50 ? 'medium' : 'low';
return coveragePct >= watermark[1] ? 'high' : coveragePct >= watermark[0] ? 'medium' : 'low';
} else {

@@ -333,2 +334,3 @@ return '';

this.opts.templateData = { datetime: Date() };
this.opts.watermarks = this.opts.watermarks || defaults.watermarks();
}

@@ -367,3 +369,3 @@

templateData.metrics = node.metrics;
templateData.reportClass = getReportClass(node.metrics.statements);
templateData.reportClass = getReportClass(node.metrics.statements, opts.watermarks.statements);
templateData.pathHtml = pathTemplate({ html: this.getPathHtml(node, linkMapper) });

@@ -413,3 +415,4 @@ templateData.prettify = {

templateData = this.opts.templateData,
children = Array.prototype.slice.apply(node.children);
children = Array.prototype.slice.apply(node.children),
watermarks = this.opts.watermarks;

@@ -426,6 +429,6 @@ children.sort(function (a, b) {

reportClasses = {
statements: getReportClass(metrics.statements),
lines: getReportClass(metrics.lines),
functions: getReportClass(metrics.functions),
branches: getReportClass(metrics.branches)
statements: getReportClass(metrics.statements, watermarks.statements),
lines: getReportClass(metrics.lines, watermarks.lines),
functions: getReportClass(metrics.functions, watermarks.functions),
branches: getReportClass(metrics.branches, watermarks.branches)
},

@@ -432,0 +435,0 @@ data = {

@@ -36,4 +36,4 @@ /*

mkdirp.sync(baseDir);
this.lcov = new LcovOnlyReport({ dir: baseDir });
this.html = new HtmlReport({ dir: htmlDir, sourceStore: opts.sourceStore});
this.lcov = new LcovOnlyReport({ dir: baseDir, watermarks: opts.watermarks });
this.html = new HtmlReport({ dir: htmlDir, watermarks: opts.watermarks, sourceStore: opts.sourceStore});
}

@@ -40,0 +40,0 @@

@@ -8,2 +8,3 @@ /*

mkdirp = require('mkdirp'),
defaults = require('./common/defaults'),
fs = require('fs'),

@@ -33,2 +34,3 @@ utils = require('../object-utils'),

this.file = opts.file;
this.watermarks = opts.watermarks || defaults.watermarks();
}

@@ -38,6 +40,7 @@

function lineForKey(summary, key) {
function lineForKey(summary, key, watermarks) {
var metrics = summary[key],
skipped,
result;
result,
clazz = defaults.classFor(key, summary, watermarks);
key = key.substring(0, 1).toUpperCase() + key.substring(1);

@@ -50,3 +53,3 @@ if (key.length < 12) { key += ' '.substring(0, 12 - key.length); }

}
return result;
return defaults.colorize(result, clazz);
}

@@ -59,2 +62,3 @@

lines = [],
watermarks = this.watermarks,
text;

@@ -68,6 +72,6 @@ collector.files().forEach(function (file) {

lines.push.apply(lines, [
lineForKey(finalSummary, 'statements'),
lineForKey(finalSummary, 'branches'),
lineForKey(finalSummary, 'functions'),
lineForKey(finalSummary, 'lines')
lineForKey(finalSummary, 'statements', watermarks),
lineForKey(finalSummary, 'branches', watermarks),
lineForKey(finalSummary, 'functions', watermarks),
lineForKey(finalSummary, 'lines', watermarks)
]);

@@ -74,0 +78,0 @@ lines.push('================================================================================');

@@ -9,2 +9,3 @@ /*

fs = require('fs'),
defaults = require('./common/defaults'),
Report = require('./index'),

@@ -42,2 +43,3 @@ TreeSummarizer = require('../util/tree-summarizer'),

this.maxCols = opts.maxCols || 0;
this.watermarks = opts.watermarks || defaults.watermarks();
}

@@ -57,3 +59,3 @@

function fill(str, width, right, tabs) {
function fill(str, width, right, tabs, clazz) {
tabs = tabs || 0;

@@ -67,17 +69,4 @@ str = String(str);

fillStr,
isNumber = !isNaN(parseFloat(str)) && isFinite(str),
strlen = str.length,
isTty = Boolean(process.stdout.isTTY);
strlen = str.length;
if (isNumber && isTty) {
// low: < 50 % medium: >= 50 % high: >= 80 %
if (str >= 80) {
str = '\033[92m' + str + '\033[0m'; // high - green
} else if (str >= 50) {
str = '\033[93m' + str + '\033[0m'; // medium - yellow
} else {
str = '\033[91m' + str + '\033[0m'; // low - red
}
}
if (remaining > 0) {

@@ -92,11 +81,13 @@ if (remaining >= strlen) {

}
fmtStr = defaults.colorize(fmtStr, clazz);
return leader + fmtStr;
}
function formatName(name, maxCols, level) {
return fill(name, maxCols, false, level);
function formatName(name, maxCols, level, clazz) {
return fill(name, maxCols, false, level, clazz);
}
function formatPct(pct) {
return fill(pct, PCT_COLS, true, 0);
function formatPct(pct, clazz) {
return fill(pct, PCT_COLS, true, 0, clazz);
}

@@ -108,2 +99,3 @@

function tableHeader(maxNameCols) {

@@ -119,3 +111,3 @@ var elements = [];

function tableRow(node, maxNameCols, level) {
function tableRow(node, maxNameCols, level, watermarks) {
var name = nodeName(node),

@@ -128,7 +120,7 @@ statements = node.metrics.statements.pct,

elements.push(formatName(name, maxNameCols, level));
elements.push(formatPct(statements));
elements.push(formatPct(branches));
elements.push(formatPct(functions));
elements.push(formatPct(lines));
elements.push(formatName(name, maxNameCols, level, defaults.classFor('statements', node.metrics, watermarks)));
elements.push(formatPct(statements, defaults.classFor('statements', node.metrics, watermarks)));
elements.push(formatPct(branches, defaults.classFor('branches', node.metrics, watermarks)));
elements.push(formatPct(functions, defaults.classFor('functions', node.metrics, watermarks)));
elements.push(formatPct(lines, defaults.classFor('lines', node.metrics, watermarks)));

@@ -164,3 +156,3 @@ return elements.join(DELIM) + DELIM;

function walk(node, nameWidth, array, level) {
function walk(node, nameWidth, array, level, watermarks) {
var line;

@@ -173,10 +165,10 @@ if (level === 0) {

} else {
array.push(tableRow(node, nameWidth, level));
array.push(tableRow(node, nameWidth, level, watermarks));
}
node.children.forEach(function (child) {
walk(child, nameWidth, array, level + 1);
walk(child, nameWidth, array, level + 1, watermarks);
});
if (level === 0) {
array.push(line);
array.push(tableRow(node, nameWidth, level));
array.push(tableRow(node, nameWidth, level, watermarks));
array.push(line);

@@ -209,3 +201,3 @@ }

}
walk(root, nameWidth, strings, 0);
walk(root, nameWidth, strings, 0, this.watermarks);
text = strings.join('\n') + '\n';

@@ -212,0 +204,0 @@ if (this.file) {

@@ -10,4 +10,9 @@ /*

STOP = 80,
wrap = require('wordwrap')(TEXT_START, STOP);
wrap = require('wordwrap')(TEXT_START, STOP),
paraWrap = require('wordwrap')(1, STOP);
function formatPara(text) {
return paraWrap(text);
}
function formatOption(option, helpText) {

@@ -24,3 +29,4 @@ var formattedText = wrap(helpText);

module.exports = {
formatPara: formatPara,
formatOption: formatOption
};
{
"name": "istanbul",
"version": "0.2.2",
"version": "0.2.3",
"description": "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 and browser tests. Built for scale",

@@ -51,3 +51,4 @@ "keywords": [ "coverage", "code coverage", "JS code coverage", "JS coverage" ],

"wordwrap": "0.0.x",
"resolve": "0.6.x"
"resolve": "0.6.x",
"js-yaml": "3.x"
},

@@ -54,0 +55,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc