diff --git a/autolint.js b/autolint.js index a756ddd..b94bf3d 100644 --- a/autolint.js +++ b/autolint.js @@ -1,6 +1,6 @@ module.exports = { paths: [ - "lib/*.js", + "lib/**/*.js", "test/*.js" ], linterOptions: { diff --git a/lib/buster-cli/config.js b/lib/buster-cli/config.js index fbe8482..749c4f6 100644 --- a/lib/buster-cli/config.js +++ b/lib/buster-cli/config.js @@ -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); @@ -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) { @@ -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) { diff --git a/test/buster-cli-test.js b/test/buster-cli-test.js index 8fb3117..ed15bc8 100644 --- a/test/buster-cli-test.js +++ b/test/buster-cli-test.js @@ -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" }, @@ -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": {