Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Measure coverage for all js tests
Browse files Browse the repository at this point in the history
Instrument spec.js for test coverage
measurement.
  • Loading branch information
saper committed Aug 19, 2015
1 parent 1263983 commit e2a20e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/**
test/coverage/html
38 changes: 20 additions & 18 deletions scripts/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ function coverage() {
collector = new Collector();
if (cov) {
mkdirp(path.join('coverage', 'html'), function(err) {
if (err) { throw err; }
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);
if (err) { throw err; }
collector.add(cov);
summary.writeReport(collector, true);
html.writeReport(collector, true);
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, true);
});
} else {
console.warn('No coverage');
Expand All @@ -44,19 +44,21 @@ function coverage() {
var instrumenter = new Instrumenter();
var instrumentedfiles = [];
var processfile = function(source) {
fs.readFile(path.join('lib', source), function(err, data) {
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(),
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';
return file.substr(-6) === 'api.js' ||
file.substr(-11) === 'runtime.js' ||
file.substr(-7) === 'spec.js';
}).forEach(function(file){
mocha.addFile(
path.join('test', file)
Expand All @@ -69,9 +71,9 @@ function coverage() {
});
});
}
});
});
});
});
});
};
for (var i in sourcefiles) {
processfile(sourcefiles[i]);
Expand Down
4 changes: 3 additions & 1 deletion test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ var assert = require('assert'),
exists = fs.existsSync,
path = require('path'),
read = fs.readFileSync,
sass = require('../lib'),
sass = process.env.NODESASS_COV
? require('../lib-cov')
: require('../lib'),
util = require('./util');

describe('spec', function() {
Expand Down

0 comments on commit e2a20e5

Please # to comment.