Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Print warning for not extended groups without environment set
Browse files Browse the repository at this point in the history
  • Loading branch information
dwittner committed Sep 5, 2013
1 parent 62a3778 commit f35146e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
2 changes: 1 addition & 1 deletion autolint.js
@@ -1,6 +1,6 @@
module.exports = {
paths: [
"lib/*.js",
"lib/**/*.js",
"test/*.js"
],
linterOptions: {
Expand Down
38 changes: 36 additions & 2 deletions lib/buster-cli/config.js
Expand Up @@ -36,6 +36,37 @@ function noGroupsError(cli, file, groups, options) {
return new Error(message);
}

/**
* Checks for groups without an environment set.
* If such a group is found and it is not extended by at least one other group,
* a warning is logged to inform the user, that the group will be ignored.
*
* @param {Object[]} groups Groups to check.
*/
function checkForEnvSet(groups) {

var i, j, extended;
for (i = 0; i < groups.length; i++) {

if (!groups[i].environment) {

extended = false;
for (j = 0; j < groups.length && !extended; j++) {
if (i !== j && groups[j].config["extends"] === groups[i].name) {
extended = true;
}
}

if (!extended) {
this.cli.logger.warn("Warning: " +
"no environment set for group \"" +
groups[i].name +
"\", group will be ignored!");
}
}
}
}

function filterTests(filters, config) {
var matchers = filters.map(function (filter) {
return new Minimatch(filter);
Expand Down Expand Up @@ -121,8 +152,10 @@ module.exports = Config.prototype = {
" did not match any files"));
}
if (files.length === 0) {
return callback(new Error(sig + " not provided, and none of\n[" +
this.defaultFiles.join(", ") + "] exist"));
return callback(new Error(sig +
" not provided, and none of\n[" +
this.defaultFiles.join(", ") +
"] exist"));
}
try {
callback(null, files.map(function (f) {
Expand Down Expand Up @@ -152,6 +185,7 @@ module.exports = Config.prototype = {
return callback(err);
}
var groups = config.groups.slice();
checkForEnvSet.call(this, groups);
this.filter(config, options);
var files = emptyFiles(config);
if (files.length > 0) {
Expand Down
62 changes: 61 additions & 1 deletion test/buster-cli-test.js
Expand Up @@ -356,7 +356,7 @@ buster.testCase("buster-cli", {
}.bind(this));
},

"configuration with --config": {
"with --config": {
setUp: function () {
var json = JSON.stringify({
"Node tests": { environment: "node" },
Expand Down Expand Up @@ -441,6 +441,66 @@ buster.testCase("buster-cli", {
}));
}.bind(this));
}

},

"config validation": {

setUp: function () {
sinon.stub(this.cli.logger, "warn");
},

tearDown: cliHelper.clearFixtures,

"warning for groups without environment set": function (done) {

var json = JSON.stringify({
"Tests1": {},
"Tests2": {},
"Node tests": { environment: "node" },
"Browser tests": { environment: "browser" }
});
cliHelper.writeFile("seaman.js", "module.exports = " + json);

this.cli.parseArgs([], function (errors, options) {
this.cli.loadConfig(options, done(function (err, groups) {
assert.equals(this.cli.logger.warn.callCount, 2);
assert.match(this.cli.logger.warn.args[0], "Warning:");
assert.match(this.cli.logger.warn.args[0],
"no environment set for group \"");
assert.match(this.cli.logger.warn.getCall(0).args[0],
"Tests1");
assert.match(this.cli.logger.warn.getCall(1).args[0],
"Tests2");
assert.match(this.cli.logger.warn.args[0],
"\", group will be ignored!");
}.bind(this)));
}.bind(this));
},

"no warning for missing environment if extended": function (done) {

var json = JSON.stringify({
"Tests1": {},
"Tests2": {},
"Node tests": { environment: "node", "extends": "Tests2" },
"Browser tests": { environment: "browser" }
});
cliHelper.writeFile("seaman.js", "module.exports = " + json);

this.cli.parseArgs([], function (errors, options) {
this.cli.loadConfig(options, done(function (err, groups) {
assert.equals(this.cli.logger.warn.callCount, 1);
assert.match(this.cli.logger.warn.args[0], "Warning:");
assert.match(this.cli.logger.warn.args[0],
"no environment set for group \"");
assert.match(this.cli.logger.warn.args[0], "Tests1");
assert.match(this.cli.logger.warn.args[0],
"\", group will be ignored!");
}.bind(this)));
}.bind(this));
}

},

"config environments": {
Expand Down

0 comments on commit f35146e

Please sign in to comment.