2 * node-sass: scripts/coverage.js
5 var Mocha = require('mocha'),
7 path = require('path'),
8 mkdirp = require('mkdirp'),
9 coveralls = require('coveralls'),
10 istanbul = require('istanbul'),
11 sourcefiles = ['index.js', 'extensions.js', 'render.js', 'errors.js'],
12 summary= istanbul.Report.create('text-summary'),
13 lcov = istanbul.Report.create('lcovonly', { dir: path.join('coverage') }),
14 html = istanbul.Report.create('html', { dir: path.join('coverage', 'html') });
17 var mocha = new Mocha();
18 var rep = function(runner) {
19 runner.on('end', function(){
20 var cov = global.__coverage__,
21 collector = new istanbul.Collector();
23 mkdirp(path.join('coverage', 'html'), function(err) {
24 if (err) { throw err; }
26 summary.writeReport(collector, true);
27 html.writeReport(collector, true);
28 lcov.on('done', function() {
29 fs.readFile(path.join('coverage', 'lcov.info'), function(err, data) {
30 if (err) { console.error(err); }
31 coveralls.handleInput(data.toString(),
32 function (err) { if (err) { console.error(err); } });
35 lcov.writeReport(collector, true);
38 console.warn('No coverage');
42 var instrumenter = new istanbul.Instrumenter();
43 var instrumentedfiles = [];
44 var processfile = function(source) {
45 fs.readFile(path.join('lib', source), function(err, data) {
46 if (err) { throw err; }
47 mkdirp('lib-cov', function(err) {
48 if (err) { throw err; }
49 fs.writeFile(path.join('lib-cov', source),
50 instrumenter.instrumentSync(data.toString(),
51 path.join('lib', source)),
53 if (err) { throw err; }
54 instrumentedfiles.push(source);
55 if (instrumentedfiles.length === sourcefiles.length) {
56 fs.readdirSync('test').filter(function(file){
57 return file.substr(-6) === 'api.js' ||
58 file.substr(-11) === 'runtime.js' ||
59 file.substr(-7) === 'spec.js';
60 }).forEach(function(file){
62 path.join('test', file)
65 process.env.NODESASS_COV = 1;
66 mocha.reporter(rep).run(function(failures) {
67 process.on('exit', function () {
68 process.exit(failures);
76 for (var i in sourcefiles) {
77 processfile(sourcefiles[i]);