diff --git a/conf/docs/index.mustache b/conf/docs/index.mustache index 7bf9e34..d4318a3 100644 --- a/conf/docs/index.mustache +++ b/conf/docs/index.mustache @@ -483,5 +483,12 @@ I've added a `--lint-stderr` config option which forces all lint output to `stde
- Adding `--recursive` to the `--walk` command will tell `shifter` to walk the directories recursively looking for `build.json` files. + Adding `--recursive` to the `--walk` command will tell `shifter` to walk the directories recursively looking for `build.json` files.
+When building recursively, if you want to produce usable coverage instrumentation, you must also create a .shifter.json file with the coverageRelativeToConfig set to true.
+ +``` +{ + coverageRelativeToConfig: true +} +``` diff --git a/lib/index.js b/lib/index.js index f6f3e89..19c7d6e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,6 +103,12 @@ exports.init = function (opts, initCallback) { } } }); + + if (options.coverageRelativeToConfig) { + // Since we found a path to the config file, we can build relative to it. + // This is important for coverage reports in recursive builds. + exports.relativeTo = path.resolve(path.dirname(file), './'); + } } }); } diff --git a/lib/module.js b/lib/module.js index 562db4f..3cabe3e 100644 --- a/lib/module.js +++ b/lib/module.js @@ -382,7 +382,15 @@ var buildCoverage = function (mod, name, callback) { logger: log, registry: registry }), - fileName = mod.basefilename || name; + fileName = mod.basefilename || name, + // The path to the build directory. + buildPath = 'build'; + if (shifter.relativeTo) { + // If shifter is being run relative to a .shifter.json, we can make + // the coverage file report with relativity to that configuration. + // This is required in recursive builds for code coverage generation. + buildPath = path.relative(shifter.relativeTo, mod.buildDir); + } queue.read([ path.join(mod.buildDir, fileName, fileName + '.js') @@ -391,7 +399,7 @@ var buildCoverage = function (mod, name, callback) { .coverage({ type: coverageType, charset: 'utf8', - name: 'build/' + fileName + '/' + fileName + '.js' + name: buildPath + '/' + fileName + '/' + fileName + '.js' }) .replace(replaceOptions) .check()