Commit 12639834 by Marcin Cieslak

Use istanbul for test coverage

If there is no coverage at all we get
an empty global variable and the lcov
empty file may cause coveralls failure.

Use mkdirp() to create lib-cov
parent 34db8709
...@@ -5,3 +5,7 @@ build ...@@ -5,3 +5,7 @@ build
lib-cov lib-cov
node_modules node_modules
vendor vendor
test/html-report
test/lcov-report
test/lcov.info
coverage
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
"devDependencies": { "devDependencies": {
"coveralls": "^2.11.2", "coveralls": "^2.11.2",
"cross-spawn": "^1.0.3", "cross-spawn": "^1.0.3",
"jscoverage": "^0.5.9", "istanbul": "^0.3.13",
"jshint": "^2.8.0", "jshint": "^2.8.0",
"mocha": "^2.2.5", "mocha": "^2.2.5",
"mocha-lcov-reporter": "^0.0.2", "mocha-lcov-reporter": "^0.0.2",
......
...@@ -2,62 +2,80 @@ ...@@ -2,62 +2,80 @@
* node-sass: scripts/coverage.js * node-sass: scripts/coverage.js
*/ */
require('../lib/extensions'); var Mocha = require('mocha'),
fs = require('fs'),
path = require('path'),
mkdirp = require('mkdirp'),
coveralls = require('coveralls'),
Instrumenter = require('istanbul').Instrumenter,
Report = require('istanbul').Report,
Collector = new require('istanbul').Collector,
sourcefiles = ['index.js', 'extensions.js', 'render.js'],
summary= Report.create('text-summary'),
lcov = Report.create('lcovonly', { dir: path.join('coverage') }),
html = Report.create('html', { dir: path.join('coverage', 'html') });
var bin = require('path').join.bind(null, __dirname, '..', 'node_modules', '.bin'), function coverage() {
spawn = require('child_process').spawn; var mocha = new Mocha();
var rep = function(runner) {
/** runner.on('end', function(){
* Run test suite var cov = global.__coverage__,
* collector = new Collector();
* @api private if (cov) {
*/ mkdirp(path.join('coverage', 'html'), function(err) {
if (err) { throw err; }
function suite() { collector.add(cov);
summary.writeReport(collector);
html.writeReport(collector);
lcov.on('done', function() {
fs.readFile(path.join('coverage', 'lcov.info'), function(err, data) {
if (err) { console.error(err); }
coveralls.handleInput(data.toString(),
function (err) { if (err) { console.error(err); } });
});
});
lcov.writeReport(collector);
});
} else {
console.warn('No coverage');
}
});
};
var instrumenter = new Instrumenter();
var instrumentedfiles = [];
var processfile = function(source) {
fs.readFile(path.join('lib', source), function(err, data) {
if (err) { throw err; }
mkdirp('lib-cov', function(err) {
if (err) { throw err; }
fs.writeFile(path.join('lib-cov', source),
instrumenter.instrumentSync(data.toString(),
path.join('lib', source)),
function(err) {
if (err) { throw err; }
instrumentedfiles.push(source);
if (instrumentedfiles.length === sourcefiles.length) {
fs.readdirSync('test').filter(function(file){
return file.substr(-6) === 'api.js';
}).forEach(function(file){
mocha.addFile(
path.join('test', file)
);
});
process.env.NODESASS_COV = 1; process.env.NODESASS_COV = 1;
mocha.reporter(rep).run(function(failures) {
var coveralls = spawn(bin('coveralls')); process.on('exit', function () {
process.exit(failures);
var args = [bin('_mocha')].concat(['--reporter', 'mocha-lcov-reporter']);
var mocha = spawn(process.sass.runtime.execPath, args, {
env: process.env
}); });
mocha.on('error', function(err) {
console.error(err);
process.exit(1);
}); });
}
mocha.stderr.setEncoding('utf8');
mocha.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
}); });
mocha.stdout.pipe(coveralls.stdin);
}
/**
* Generate coverage files
*
* @api private
*/
function coverage() {
var jscoverage = spawn(bin('jscoverage'), ['lib', 'lib-cov']);
jscoverage.on('error', function(err) {
console.error(err);
process.exit(1);
}); });
jscoverage.stderr.setEncoding('utf8');
jscoverage.stderr.on('data', function(err) {
console.error(err);
process.exit(1);
}); });
};
jscoverage.on('close', suite); for (var i in sourcefiles) {
processfile(sourcefiles[i]);
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment