diff --git a/lib/extension.js b/lib/extension.js index 3c9fde4..e0e015c 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -3,14 +3,17 @@ var fs = require('fs'); var coverageHelpers = require('coverage-helpers'); var coverageExclusions = []; -function processor(resource, content) { +function processor(resource, content, rootPath) { + if (typeof rootPath === 'undefined') { + rootPath = process.cwd(); + } for (var i = 0; i < coverageExclusions.length; i++) { if (resource.path.indexOf(coverageExclusions[i]) !== -1) { return content; } } var contentBuffer = new Buffer(content, resource.encoding); - var fullPath = path.join(process.cwd(), resource.path); + var fullPath = path.join(rootPath, resource.path); return coverageHelpers.instrument(contentBuffer, fullPath).toString(resource.encoding); } @@ -30,9 +33,14 @@ module.exports = { configure: function (config) { this.config_name = config.name; + if (typeof config.rootPath !== 'undefined') { + this.outputDirectory = path.join(config.rootPath, this.outputDirectory); + } config.on('load:sources', function (resourceSet) { - resourceSet.addProcessor(processor); + resourceSet.addProcessor(function (resource, content) { + return processor(resource, content, resourceSet.rootPath) + }); }); config.on('load:framework', function (resourceSet) {