Comparing version 0.1.22 to 0.1.23
@@ -17,4 +17,31 @@ /* | ||
Command = require('./index'), | ||
Collector = require('../collector'), | ||
verbose; | ||
function BaselineCollector(instrumenter) { | ||
this.instrumenter = instrumenter; | ||
this.collector = new Collector(); | ||
this.instrument = instrumenter.instrument.bind(this.instrumenter); | ||
var origInstrumentSync = instrumenter.instrumentSync; | ||
this.instrumentSync = function () { | ||
var args = Array.prototype.slice.call(arguments), | ||
ret = origInstrumentSync.apply(this.instrumenter, args), | ||
baseline = this.instrumenter.lastFileCoverage(), | ||
coverage = {}; | ||
coverage[baseline.path] = baseline; | ||
this.collector.add(coverage); | ||
return ret; | ||
}; | ||
//monkey patch the instrumenter to call our version instead | ||
instrumenter.instrumentSync = this.instrumentSync.bind(this); | ||
} | ||
BaselineCollector.prototype = { | ||
getCoverage: function () { | ||
return this.collector.getFinalCoverage(); | ||
} | ||
}; | ||
function processFiles(instrumenter, inputDir, outputDir, relativeNames) { | ||
@@ -91,3 +118,5 @@ var processor = function (name, callback) { | ||
formatOption('--embed-source', 'embed source code into the coverage object, defaults to false'), | ||
formatOption('--[no-]compact', 'produce [non]compact output, defaults to compact') | ||
formatOption('--[no-]compact', 'produce [non]compact output, defaults to compact'), | ||
formatOption('--save-baseline', 'produce a baseline coverage.json file out of all files instrumented'), | ||
formatOption('--baseline-file <file>', 'filename of baseline file, defaults to coverage/coverage-baseline.json') | ||
].join('\n\n') + '\n'); | ||
@@ -105,2 +134,4 @@ console.error('\n'); | ||
verbose: Boolean, | ||
'save-baseline': Boolean, | ||
'baseline-file': path, | ||
'embed-source': Boolean | ||
@@ -113,3 +144,5 @@ }, | ||
stream, | ||
instrumenter = new Instrumenter({ coverageVariable: opts.variable }); | ||
instrumenter = new Instrumenter({ coverageVariable: opts.variable }), | ||
needBaseline = opts['save-baseline'], | ||
baselineFile = opts['baseline-file'] || path.resolve(process.cwd(), 'coverage', 'coverage-baseline.json'); | ||
@@ -130,2 +163,11 @@ verbose = opts.verbose; | ||
if (needBaseline) { | ||
mkdirp.sync(path.dirname(baselineFile)); | ||
instrumenter = new BaselineCollector(instrumenter); | ||
process.on('exit', function () { | ||
util.puts('Saving baseline coverage at: ' + baselineFile); | ||
fs.writeFileSync(baselineFile, JSON.stringify(instrumenter.getCoverage()), 'utf8'); | ||
}); | ||
} | ||
file = path.resolve(cmdArgs[0]); | ||
@@ -132,0 +174,0 @@ stats = fs.statSync(file); |
@@ -416,3 +416,14 @@ /* | ||
}, | ||
/** | ||
* returns the file coverage object for the code that was instrumented | ||
* just before calling this method. Note that this represents a | ||
* "zero-coverage" object which is not even representative of the code | ||
* being loaded in node or a browser (which would increase the statement | ||
* counts for mainline code). | ||
* @return {Object} a "zero-coverage" file coverage object for the code last instrumented | ||
* by this instrumenter | ||
*/ | ||
lastFileCoverage: function () { | ||
return this.coverState; | ||
}, | ||
fixColumnPositions: function (coverState) { | ||
@@ -419,0 +430,0 @@ var offset = LEADER_WRAP.length, |
{ | ||
"name": "istanbul", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"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", | ||
@@ -24,3 +24,3 @@ "keywords": [ "coverage", "code coverage", "JS code coverage", "JS coverage" ], | ||
"dependencies": { | ||
"esprima": "0.9.x", | ||
"esprima": "1.0.x", | ||
"escodegen": "0.0.x", | ||
@@ -27,0 +27,0 @@ "handlebars": "1.0.x", |
@@ -81,2 +81,11 @@ /*jslint nomen: true */ | ||
}, | ||
"should save baseline coverage when requested": function (test) { | ||
var covFile = path.resolve(OUTPUT_DIR, 'cov.json'); | ||
run([ 'lib/foo.js', '--save-baseline', '--baseline-file=' + covFile ], function (results) { | ||
test.ok(results.succeeded()); | ||
test.ok(existsSync(covFile)); | ||
test.ok(results.grepOutput(/Saving baseline coverage at/)); | ||
test.done(); | ||
}); | ||
}, | ||
"should barf on no args": function (test) { | ||
@@ -83,0 +92,0 @@ run([], function (results) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7727
351131
101
1
0
- Removedesprima@0.9.9(transitive)
Updatedesprima@1.0.x