Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for coverage files relative to shifter config #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion conf/docs/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,12 @@ I've added a `--lint-stderr` config option which forces all lint output to `stde
<h3 id="exp.cli.recursive">Recursive Building</h3>

<p>
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.
</p>
<p>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.</p>

```
{
coverageRelativeToConfig: true
}
```
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), './');
}
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down