Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Commit

Permalink
chore(release): v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Apr 3, 2015
1 parent 74cc517 commit 79d6b1e
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 275 deletions.
153 changes: 78 additions & 75 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
"use strict";
'use strict';

var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };

//

var _fs = require("fs");
var _existsSync$writeFileSync = require('fs');

var existsSync = _fs.existsSync;
var writeFileSync = _fs.writeFileSync;
var _path = require('path');

var path = _interopRequire(require("path"));
var path = _interopRequire(_path);

var Module = _interopRequire(require("module"));
var _Module = require('module');

var Module = _interopRequire(_Module);

//

var which = _interopRequire(require("which"));
var _which = require('which');

var which = _interopRequire(_which);

var _mkdirp = require('mkdirp');

var mkdirp = _interopRequire(_mkdirp);

var mkdirp = _interopRequire(require("mkdirp"));
var _partial = require('lodash.partial');

var partial = _interopRequire(require("lodash.partial"));
var partial = _interopRequire(_partial);

var nomnom = _interopRequire(require("nomnom"));
var _nomnom = require('nomnom');

var _istanbul = require("istanbul");
var nomnom = _interopRequire(_nomnom);

var hook = _istanbul.hook;
var Collector = _istanbul.Collector;
var Reporter = _istanbul.Reporter;
var matcherFor = _istanbul.matcherFor;
var configuration = _istanbul.config;
var _hook$Collector$Reporter$matcherFor$configuration = require('istanbul');

var Instrumenter = require("./instrumenter").Instrumenter;
var _Instrumenter = require('./instrumenter');

//

//

nomnom.command("cover").help("transparently adds coverage information to a node command. Saves coverage.json and reports at the end of execution").option("cmd", {
nomnom.command('cover').help('transparently adds coverage information to a node command. Saves coverage.json and reports at the end of execution').option('cmd', {
required: true,
position: 1,
help: "ES6 js files to cover (using babel)"
}).option("config", {
metavar: "<path-to-config>",
help: "the configuration file to use, defaults to .istanbul.yml"
}).option("report", {
"default": "lcv",
metavar: "<format>",
help: 'ES6 js files to cover (using babel)'
}).option('config', {
metavar: '<path-to-config>',
help: 'the configuration file to use, defaults to .istanbul.yml'
}).option('report', {
'default': 'lcv',
metavar: '<format>',
list: true,
help: "report format, defaults to ['lcv']"
}).option("root", {
metavar: "<path>",
help: "the root path to look for files to instrument, defaults to ."
}).option("verbose", {
help: 'report format, defaults to [\'lcv\']'
}).option('root', {
metavar: '<path>',
help: 'the root path to look for files to instrument, defaults to .'
}).option('verbose', {
flag: true,
abbr: "v",
help: "verbose mode"
abbr: 'v',
help: 'verbose mode'
}).callback(coverCmd);

nomnom.nom();
Expand All @@ -71,23 +74,23 @@ function callback(err) {
function coverCmd(opts) {

var config = overrideConfigWith(opts);
var reporter = new Reporter(config);
var reporter = new _hook$Collector$Reporter$matcherFor$configuration.Reporter(config);

var cmd = opts.cmd;

var cmdArgs = opts["--"] || [];
var cmdArgs = opts['--'] || [];

if (!existsSync(cmd)) {
if (!_existsSync$writeFileSync.existsSync(cmd)) {
try {
cmd = which.sync(cmd);
} catch (ex) {
return callback("Unable to resolve file [" + cmd + "]");
return callback('Unable to resolve file [' + cmd + ']');
}
} else {
cmd = path.resolve(cmd);
}

if (opts.verbose) console.error("Isparta options : \n ", opts);
if (opts.verbose) console.error('Isparta options : \n ', opts);

var excludes = config.instrumentation.excludes(true);
enableHooks();
Expand All @@ -100,51 +103,51 @@ function coverCmd(opts) {
verbose: opts.verbose,
instrumentation: {
root: opts.root,
"default-excludes": opts["default-excludes"],
'default-excludes': opts['default-excludes'],
excludes: opts.x,
"include-all-sources": opts["include-all-sources"],
"preload-sources": opts["preload-sources"]
'include-all-sources': opts['include-all-sources'],
'preload-sources': opts['preload-sources']
},
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"],
"handle-sigint": opts["handle-sigint"]
'hook-run-in-context': opts['hook-run-in-context'],
'post-require-hook': opts['post-require-hook'],
'handle-sigint': opts['handle-sigint']
}
};

return configuration.loadFile(opts.config, overrides);
return _hook$Collector$Reporter$matcherFor$configuration.config.loadFile(opts.config, overrides);
}

function enableHooks() {
opts.reportingDir = path.resolve(config.reporting.dir());
mkdirp.sync(opts.reportingDir);
reporter.addAll(config.reporting.reports());

if (config.reporting.print() !== "none") {
if (config.reporting.print() !== 'none') {
switch (config.reporting.print()) {
case "detail":
reporter.add("text");
case 'detail':
reporter.add('text');
break;
case "both":
reporter.add("text");
reporter.add("text-summary");
case 'both':
reporter.add('text');
reporter.add('text-summary');
break;
default:
reporter.add("text-summary");
reporter.add('text-summary');
break;
}
}

excludes.push(path.relative(process.cwd(), path.join(opts.reportingDir, "**", "*")));
excludes.push(path.relative(process.cwd(), path.join(opts.reportingDir, '**', '*')));

matcherFor({
_hook$Collector$Reporter$matcherFor$configuration.matcherFor({
root: config.instrumentation.root() || process.cwd(),
includes: ["**/*.js"],
includes: ['**/*.js'],
excludes: excludes
}, function (err, matchFn) {
if (err) {
Expand All @@ -157,55 +160,55 @@ function coverCmd(opts) {
}

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

hook.hookRequire(matchFn, transformer, { verbose: opts.verbose });
_hook$Collector$Reporter$matcherFor$configuration.hook.hookRequire(matchFn, transformer, { verbose: opts.verbose });

global[coverageVar] = {};

if (config.hooks.handleSigint()) {
process.once("SIGINT", process.exit);
process.once('SIGINT', process.exit);
}

process.once("exit", function () {
var file = path.resolve(opts.reportingDir, "coverage.json");
process.once('exit', function () {
var file = path.resolve(opts.reportingDir, 'coverage.json');
var cov = undefined,
collector = undefined;

if (typeof global[coverageVar] === "undefined" || Object.keys(global[coverageVar]).length === 0) {
console.error("No coverage information was collected, exit without writing coverage information");
if (typeof global[coverageVar] === 'undefined' || Object.keys(global[coverageVar]).length === 0) {
console.error('No coverage information was collected, exit without writing coverage information');
return;
} else {
cov = global[coverageVar];
}

mkdirp.sync(opts.reportingDir);
if (config.reporting.print() !== "none") {
console.error(Array(80 + 1).join("="));
console.error("Writing coverage object [" + file + "]");
if (config.reporting.print() !== 'none') {
console.error(Array(80 + 1).join('='));
console.error('Writing coverage object [' + file + ']');
}
writeFileSync(file, JSON.stringify(cov), "utf8");
collector = new Collector();
_existsSync$writeFileSync.writeFileSync(file, JSON.stringify(cov), 'utf8');
collector = new _hook$Collector$Reporter$matcherFor$configuration.Collector();
collector.add(cov);
if (config.reporting.print() !== "none") {
console.error("Writing coverage reports at [" + opts.reportingDir + "]");
console.error(Array(80 + 1).join("="));
if (config.reporting.print() !== 'none') {
console.error('Writing coverage reports at [' + opts.reportingDir + ']');
console.error(Array(80 + 1).join('='));
}
reporter.write(collector, true, callback);
});

if (config.instrumentation.includeAllSources()) {
matchFn.files.forEach(function (file) {
if (opts.verbose) {
console.error("Preload " + file);
console.error('Preload ' + file);
}
try {
require(file);
} catch (ex) {
if (opts.verbose) {
console.error("Unable to preload " + file);
console.error('Unable to preload ' + file);
}
// swallow
}
Expand All @@ -214,9 +217,9 @@ function coverCmd(opts) {
}

function runCommandFn() {
process.argv = ["node", cmd].concat(cmdArgs);
process.argv = ['node', cmd].concat(cmdArgs);
if (opts.verbose) {
console.log("Running: " + process.argv.join(" "));
console.log('Running: ' + process.argv.join(' '));
}
process.env.running_under_istanbul = 1;
Module.runMain(cmd, null, true);
Expand Down
4 changes: 2 additions & 2 deletions lib/cover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";
'use strict';

var a = require("istanbul").a;
var _a = require('istanbul');
Loading

0 comments on commit 79d6b1e

Please sign in to comment.