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'),
var bin = require('path').join.bind(null, __dirname, '..', 'node_modules', '.bin'), path = require('path'),
spawn = require('child_process').spawn; mkdirp = require('mkdirp'),
coveralls = require('coveralls'),
/** Instrumenter = require('istanbul').Instrumenter,
* Run test suite Report = require('istanbul').Report,
* Collector = new require('istanbul').Collector,
* @api private sourcefiles = ['index.js', 'extensions.js', 'render.js'],
*/ summary= Report.create('text-summary'),
lcov = Report.create('lcovonly', { dir: path.join('coverage') }),
function suite() { html = Report.create('html', { dir: path.join('coverage', 'html') });
process.env.NODESASS_COV = 1;
var coveralls = spawn(bin('coveralls'));
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() { function coverage() {
var jscoverage = spawn(bin('jscoverage'), ['lib', 'lib-cov']); var mocha = new Mocha();
var rep = function(runner) {
jscoverage.on('error', function(err) { runner.on('end', function(){
console.error(err); var cov = global.__coverage__,
process.exit(1); collector = new Collector();
}); if (cov) {
mkdirp(path.join('coverage', 'html'), function(err) {
jscoverage.stderr.setEncoding('utf8'); if (err) { throw err; }
jscoverage.stderr.on('data', function(err) { collector.add(cov);
console.error(err); summary.writeReport(collector);
process.exit(1); html.writeReport(collector);
}); lcov.on('done', function() {
fs.readFile(path.join('coverage', 'lcov.info'), function(err, data) {
jscoverage.on('close', suite); 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;
mocha.reporter(rep).run(function(failures) {
process.on('exit', function () {
process.exit(failures);
});
});
}
});
});
});
};
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