buster-cli
Advanced tools
Comparing version 0.4.4 to 0.5.0
@@ -1,1 +0,1 @@ | ||
module.exports = {"Node tests":{"environment":"node"},"Browser tests":{"environment":"browser"}} | ||
module.exports = {"Node tests":{"environment":"node","sources":["src/1.js"],"tests":["test/**/*.js"]}} |
@@ -1,385 +0,82 @@ | ||
var busterArgs = require("buster-args"); | ||
var S = require("buster-terminal"); | ||
var stdioLogger = require("buster-stdio-logger"); | ||
var Path = require("path"); | ||
var fs = require("fs"); | ||
var Minimatch = require("minimatch").Minimatch; | ||
var B = require("buster-core"); | ||
var args = require("./buster-cli/args"); | ||
var help = require("./buster-cli/help"); | ||
var logger = require("./buster-cli/logger"); | ||
var config = require("./buster-cli/config"); | ||
var colorOpt = { | ||
"dim": { color: true, bright: false }, | ||
"bright": { color: true, bright: true } | ||
}; | ||
// Public API | ||
var DEFAULT_CONFIG_FILES = ["buster.js", "test/buster.js", "spec/buster.js"]; | ||
module.exports = B.extend(B.create(B.eventEmitter), { | ||
validators: args.validators, | ||
function createHelpOption(cli) { | ||
var helpOpt = cli.opt("-h", "--help", "Show this message.", { | ||
hasValue: true | ||
}); | ||
// To allow for --help with no value when we have help topics. | ||
helpOpt.acceptsValueAbsence = true; | ||
return helpOpt; | ||
} | ||
function createLogLevelOption(cli) { | ||
return cli.opt("-l", "--log-level", "Set logging level.", { | ||
values: cli.logger.levels | ||
}); | ||
} | ||
function createVerboseOption(cli) { | ||
var verbose = cli.opt( | ||
"-v", | ||
"--verbose", | ||
"Increase verbosity level. Include one (log level info) or two time " + | ||
"(e.g. -vv, log level debug)." | ||
); | ||
verbose.addValidator(function (opt, promise) { | ||
if (opt.timesSet > 2) { | ||
promise.reject("-v can only be set two times."); | ||
} else { | ||
promise.resolve(); | ||
} | ||
}); | ||
return verbose; | ||
} | ||
function isExistingFile(file) { | ||
try { | ||
var stat = fs.statSync(file); | ||
return stat.isFile(); | ||
} catch (e) {} | ||
} | ||
function tryFileNames(baseDir, files) { | ||
var i, l; | ||
for (i = 0, l = files.length; i < l; ++i) { | ||
var file = Path.join(baseDir, files[i]); | ||
if (isExistingFile(file)) { return file; } | ||
} | ||
} | ||
function filterTests(cli, config) { | ||
var matchers = cli.testFiles().map(function (fileName) { | ||
return new Minimatch(fileName); | ||
}); | ||
if (matchers.length === 0) { return; } | ||
config.on("load:tests", function (rs) { | ||
rs.filter(function (resource) { | ||
var file = Path.join(rs.rootPath, resource.path); | ||
return matchers.every(function (m) { return !m.match(file); }); | ||
}).forEach(function (resource) { rs.remove(resource.path); }); | ||
}); | ||
} | ||
function loadArgs(cli, argv) { | ||
var argvArr = (argv || []).slice(0); | ||
var env = cli.environmentVariable; | ||
if (env && typeof process.env[env] === "string") { | ||
return argvArr.concat(process.env[env].split(" ")); | ||
} | ||
return argvArr; | ||
} | ||
function setLogLevel(cli) { | ||
if (cli.logLevelOpt.isSet) { | ||
cli.logger.level = cli.logLevelOpt.value; | ||
} | ||
if (cli.verboseOpt.isSet) { | ||
var levels = cli.logger.levels; | ||
var curr = levels.indexOf(cli.logger.level); | ||
cli.logger.level = levels[curr + cli.verboseOpt.timesSet]; | ||
} | ||
} | ||
function printTopicHelp(cli) { | ||
var topic = cli.helpOpt.value; | ||
if (cli.helpTopics.hasOwnProperty(topic)) { | ||
cli.logger.log(cli.helpTopics[topic]); | ||
} else { | ||
cli.logger.error("No such help topic '" + topic + | ||
"'. Try without a specific help topic, or one of: " + | ||
Object.keys(cli.helpTopics).join(",") + "."); | ||
} | ||
} | ||
function hasHelpTopics(cli) { | ||
return typeof cli.helpTopics !== "undefined" && | ||
Object.keys(cli.helpTopics).length > 0; | ||
} | ||
function printHelp(cli) { | ||
if (cli.missionStatement) { | ||
cli.logger.log(cli.missionStatement + "\n"); | ||
} | ||
if (cli.usage) { cli.logger.log("Usage: " + cli.usage); } | ||
if (cli.description) { cli.logger.log(cli.description + "\n"); } | ||
var signatures = cli.options.map(function (o) { return o.signature; }); | ||
var sigWitdh = S.maxWidth(signatures); | ||
var descWidth = 80 - sigWitdh - 4; | ||
cli.options.forEach(function (option) { | ||
var alignedSignature = S.alignLeft(option.signature, sigWitdh); | ||
var helpText = option.helpText; | ||
if (option === cli.helpOpt && hasHelpTopics(cli)) { | ||
var topics = Object.keys(cli.helpTopics); | ||
var topicListText; | ||
if (topics.length === 1) { | ||
topicListText = topics[0]; | ||
} else { | ||
topicListText = "[" + topics.join(",") + "]"; | ||
} | ||
helpText += " See also --help " + topicListText + "."; | ||
} | ||
helpText = S.reflow(helpText, descWidth); | ||
helpText = helpText.split("\n").join("\n" + S.repeat(" ", sigWitdh + 7)); | ||
cli.logger.log(" " + alignedSignature + " " + helpText); | ||
}); | ||
} | ||
function handleOptions(cli, errors) { | ||
if (errors) { return cli.logger.error(errors[0]); } | ||
if (cli.helpOpt.isSet) { | ||
if (cli.helpOpt.value) { | ||
printTopicHelp(cli); | ||
} else { | ||
printHelp(cli); | ||
} | ||
return; | ||
} | ||
setLogLevel(cli); | ||
try { | ||
if (cli.onRun) { cli.onRun(); } | ||
} catch (e) { | ||
cli.logger.error("CLI internal error"); | ||
cli.logger.error(e.stack); | ||
} | ||
} | ||
function loadOptions(cli) { | ||
if (cli.hasLoadedOptions) { return; } | ||
cli.hasLoadedOptions = true; | ||
cli.helpOpt.hasValue = hasHelpTopics(cli); | ||
if (cli.loadOptions) { cli.loadOptions(); } | ||
} | ||
function loadConfig(cli, file) { | ||
var config = require("buster-configuration").create(); | ||
if (!file) { | ||
throw { message: cli.config.signature + " not provided, and " + | ||
"none of\n[" + DEFAULT_CONFIG_FILES.join(", ") + | ||
"] exists" }; | ||
} | ||
try { | ||
config.loadFile(file); | ||
} catch (e) { | ||
e.message = "Error loading configuration " + file + "\n" + e.message; | ||
throw e; | ||
} | ||
return config; | ||
} | ||
function property(name) { | ||
return function (object) { | ||
return object[name]; | ||
}; | ||
} | ||
function noGroupsError(cli, file, groups) { | ||
var groupFilter = cli.groupFilter() && cli.configGroup.value; | ||
var envFilter = cli.environmentFilter(); | ||
var message = file + " contains no configuration groups"; | ||
function nameAndEnvironment(group) { | ||
return group.name + " (" + group.environment + ")"; | ||
} | ||
if (groupFilter && envFilter) { | ||
message += " for environment '" + envFilter + "' that matches '" + | ||
groupFilter + "'\nTry one of:\n " + | ||
groups.map(nameAndEnvironment).join("\n "); | ||
} else if (envFilter) { | ||
message += " for environment '" + envFilter + "'\n" + | ||
"Try one of: " + groups.map(property("environment")).join(", "); | ||
} else if (groupFilter) { | ||
message += " that matches '" + cli.configGroup.value + "'\n" + | ||
"Try one of:\n " + groups.map(property("name")).join("\n "); | ||
} | ||
return { message: message }; | ||
} | ||
module.exports = { | ||
create: function (stdout, stderr) { | ||
var cli = Object.create(this); | ||
cli.logger = stdioLogger(stdout, stderr); | ||
cli.logger.level = "log"; | ||
cli.options = []; | ||
cli.args = Object.create(busterArgs); | ||
cli.helpOpt = createHelpOption(cli); | ||
cli.logLevelOpt = createLogLevelOption(cli); | ||
cli.verboseOpt = createVerboseOption(cli); | ||
// Create a cli helper. Options: | ||
// { | ||
// // Formatting options | ||
// width: 80, // Total width of any printed help | ||
// indent: 4, // Indent from left edge for printed help | ||
// spacing: 3, // Spaces between options and explanations in help | ||
// } | ||
// | ||
create: function (options) { | ||
var cliArgs = B.create(args); | ||
var cli = B.extend(B.create(this), { | ||
args: cliArgs, | ||
opt: B.bind(cliArgs, "opt"), | ||
opd: B.bind(cliArgs, "opd"), | ||
shorthand: B.bind(cliArgs, "addShorthand"), | ||
environmentVariable: options && options.environmentVariable | ||
}); | ||
var cliHelp = help.create(cli, options || {}); | ||
cli.addHelpOption = B.bind(cliHelp, "addHelpOption"); | ||
return cli; | ||
}, | ||
opt: function (shortFlag, longFlag, helpText, options) { | ||
var opt = this.args.createOption(shortFlag, longFlag); | ||
opt.helpText = helpText; | ||
environmentArgs: function () { | ||
var envVar = this.environmentVariable; | ||
if (!process.env[envVar]) { return []; } | ||
return process.env[envVar].split(" "); | ||
}, | ||
options = options || {}; | ||
if (options.hasOwnProperty("values")) { | ||
opt.hasValue = true; | ||
opt.helpText += " One of " + options.values.join(", ") + "."; | ||
opt.addValidator(busterArgs.validators.inEnum(options.values)); | ||
} | ||
if (options.hasOwnProperty("defaultValue")) { | ||
opt.hasValue = true; | ||
opt.helpText += " Default is " + options.defaultValue + "."; | ||
opt.defaultValue = options.defaultValue; | ||
} | ||
if (options.hasOwnProperty("hasValue")) { | ||
opt.hasValue = true; | ||
} | ||
if (options.hasOwnProperty("validators")) { | ||
var validatorName, msg; | ||
for (validatorName in options.validators) { | ||
msg = options.validators[validatorName]; | ||
opt.addValidator(busterArgs.validators[validatorName](msg)); | ||
parseArgs: function (args, callback) { | ||
args = this.environmentArgs().concat(args); | ||
this.args.parse(args, function (errors, options) { | ||
if (errors) { | ||
this.logger.error(errors[0]); | ||
} else { | ||
this.emit("args:parsed", options); | ||
} | ||
} | ||
this.options.push(opt); | ||
return opt; | ||
}, | ||
opd: function (signature, helpText) { | ||
var opd = this.args.createOperand(); | ||
opd.signature = signature; | ||
opd.helpText = helpText; | ||
this.options.push(opd); | ||
return opd; | ||
}, | ||
run: function (argv, callback) { | ||
loadOptions(this); | ||
this.args.handle(loadArgs(this, argv), function (errors) { | ||
handleOptions(this, errors); | ||
if (callback) { callback(); } | ||
callback(errors, options); | ||
}.bind(this)); | ||
}, | ||
err: function err(message) { | ||
this.logger.error(message); | ||
process.exit(1); | ||
createLogger: function (stdout, stderr) { | ||
this.logger = logger.createFor(this, stdout, stderr); | ||
return this.logger; | ||
}, | ||
addConfigOption: function (environment) { | ||
this.config = this.opt("-c", "--config", "Test configuration file", { | ||
hasValue: true | ||
addConfigOption: function (baseName, defaultFiles) { | ||
var cfg = config.create(this, { | ||
baseName: baseName, | ||
defaultFiles: defaultFiles | ||
}); | ||
this.configGroup = this.opt( | ||
"-g", | ||
"--config-group", | ||
"Test configuration group(s) to load", | ||
{ hasValue: true } | ||
); | ||
this.configTests = this.opt( | ||
"-t", | ||
"--tests", | ||
"Test files (within active configuration) to run", | ||
{ hasValue: true } | ||
); | ||
if (environment) { | ||
this.envFilter = environment; | ||
} else { | ||
this.configEnv = this.opt( | ||
"-e", | ||
"--environment", | ||
"Test configuration environment to load", | ||
{ hasValue: true } | ||
); | ||
} | ||
cfg.addGroupOption(); | ||
cfg.addTestsOption(); | ||
cfg.addEnvOption(); | ||
this.loadConfig = B.bind(cfg, "loadConfig"); | ||
}, | ||
groupFilter: function () { | ||
var filter = this.configGroup.value; | ||
return (filter && new RegExp(filter, "i")) || null; | ||
pref: function (prefs, arg, property) { | ||
var argValue = arg.value || arg.isSet; | ||
if (arg.isSet || !prefs) { return argValue; } | ||
return prefs.get(property, argValue); | ||
}, | ||
environmentFilter: function () { | ||
return this.envFilter || this.configEnv.value; | ||
exit: function (code) { | ||
process.exit(code || 0); | ||
}, | ||
testFiles: function () { | ||
if (!this.configTests.value) { return []; } | ||
return this.configTests.value.split(",").map(function (path) { | ||
return Path.resolve(process.cwd(), path); | ||
}); | ||
}, | ||
findConfigFile: function findConfigFile(baseDir, file) { | ||
var fileNames = file ? [file] : DEFAULT_CONFIG_FILES; | ||
while (!file && baseDir !== "/") { | ||
file = tryFileNames(baseDir, fileNames); | ||
baseDir = Path.dirname(baseDir); | ||
} | ||
return isExistingFile(file) ? file : null; | ||
}, | ||
loadConfig: function () { | ||
this.allGroups = []; | ||
var files = this.config.value || ""; | ||
return files.split(",").reduce(function (config, file) { | ||
this.configFile = this.findConfigFile(process.cwd(), file); | ||
if (file && !this.configFile) { | ||
throw new Error(this.config.signature + ": " + file + | ||
" did not match any files"); | ||
} | ||
var conf = loadConfig(this, this.configFile); | ||
this.allGroups = this.allGroups.concat(conf.groups); | ||
conf.filterEnv(this.environmentFilter()); | ||
conf.filterGroup(this.groupFilter()); | ||
filterTests(this, conf); | ||
config.groups = config.groups.concat(conf.groups); | ||
this.config.actualValue = config.groups; | ||
return config; | ||
}.bind(this), { groups: [] }); | ||
}, | ||
onConfig: function (callback) { | ||
var config; | ||
try { | ||
config = this.loadConfig(); | ||
} catch (e) { | ||
return callback(e); | ||
} | ||
if (config.groups.length === 0) { | ||
callback(noGroupsError(this, this.configFile, this.allGroups)); | ||
} else { | ||
callback(undefined, config); | ||
} | ||
err: function (message) { | ||
this.logger.error(message); | ||
this.exit(1); | ||
} | ||
}; | ||
}); |
@@ -1,2 +0,2 @@ | ||
var stdioLogger = require("buster-stdio-logger"); | ||
var streamLogger = require("stream-logger"); | ||
var buster = require("buster"); | ||
@@ -6,3 +6,4 @@ var rmrf = require("rimraf"); | ||
var fs = require("fs"); | ||
var FIXTURES_ROOT = path.resolve(__dirname, "..", "fixtures"); | ||
var FIXTURES_ROOT = path.resolve(__dirname, "..", ".fixtures"); | ||
var join = Array.prototype.join; | ||
@@ -12,13 +13,38 @@ module.exports = { | ||
writableStream: function (name) { | ||
var stream = { | ||
content: "", | ||
write: function () { this.content += join.call(arguments, " "); }, | ||
toString: function () { return this.content; } | ||
}; | ||
buster.assertions.add(name, { | ||
assert: function (expected) { | ||
return buster.assertions.match(stream.toString(), expected); | ||
}, | ||
assertMessage: "${2}Expected " + name + "\n${0}\nto match\n${1}", | ||
refuteMessage: "${2}Expected " + name + "\n${0}\nnot to match\n${1}", | ||
values: function (expected, message) { | ||
return [stream.toString(), expected, message || ""]; | ||
} | ||
}); | ||
return stream; | ||
}, | ||
mockLogger: function mockLogger(context) { | ||
context.stdout = ""; | ||
context.stderr = ""; | ||
var j = Array.prototype.join; | ||
var cli = context.cli; | ||
var level = cli.logger && cli.logger.level; | ||
cli.logger = stdioLogger( | ||
{ write: function () { context.stdout += j.call(arguments, " "); }}, | ||
{ write: function () { context.stderr += j.call(arguments, " "); }} | ||
); | ||
cli.logger = streamLogger({ | ||
write: function () { | ||
context.stdout += join.call(arguments, " "); | ||
} | ||
}, { | ||
write: function () { | ||
context.stderr += join.call(arguments, " "); | ||
} | ||
}); | ||
@@ -54,2 +80,8 @@ if (level) { cli.logger.level = level; } | ||
clearFixtures: function (done) { | ||
var mod; | ||
for (mod in require.cache) { | ||
if (/fixtures/.test(mod)) { | ||
delete require.cache[mod]; | ||
} | ||
} | ||
rmrf(FIXTURES_ROOT, function (err) { | ||
@@ -56,0 +88,0 @@ if (err) { require("buster").log(err.toString()); } |
{ | ||
"name": "buster-cli", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"description": "Internal wrapper and util for creating CLIs in the buster project.", | ||
@@ -21,10 +21,17 @@ "author": { "name": "August Lilleaas and Christian Johansen" }, | ||
}, | ||
"scripts": { | ||
"test": "./run-tests" | ||
}, | ||
"dependencies": { | ||
"buster-args": ">=0.3.1", | ||
"buster-terminal": ">=0.4", | ||
"buster-stdio-logger": ">=0.2.2", | ||
"buster-configuration": ">=0.4.1", | ||
"buster-core": ">=0.6.2", | ||
"posix-argv-parser": ">=0.4", | ||
"buster-terminal": ">=0.4.1", | ||
"stream-logger": ">=0.3.0", | ||
"buster-configuration": ">=0.5.0", | ||
"rimraf": "~1", | ||
"minimatch": "~0.1.5" | ||
"minimatch": ">=0.2" | ||
}, | ||
"devDependencies": { | ||
"buster": "*" | ||
} | ||
} |
var buster = require("buster"); | ||
var busterEventedLogger = require("buster-evented-logger"); | ||
var assert = buster.assert; | ||
var refute = buster.refute; | ||
var busterCli = require("../lib/buster-cli"); | ||
var cliHelper = require("../lib/test-helper"); | ||
var v = busterCli.validators; | ||
@@ -11,78 +9,29 @@ buster.testCase("buster-cli", { | ||
this.cli = busterCli.create(); | ||
this.stub(this.cli, "exit"); | ||
var stdout = this.stdout = cliHelper.writableStream("stdout"); | ||
var stderr = this.stderr = cliHelper.writableStream("stderr"); | ||
this.logger = this.cli.createLogger(this.stdout, this.stderr); | ||
}, | ||
"has logger": function () { | ||
assert(busterEventedLogger.isPrototypeOf(this.cli.logger)); | ||
}, | ||
"logger level": { | ||
"is set to log by default": function () { | ||
this.logger.info("Yo man"); | ||
this.logger.log("Hey"); | ||
"runs without callback": function () { | ||
cliHelper.mockLogger(this); | ||
this.cli.run(["--help"]); | ||
assert(true); | ||
}, | ||
"generic help output": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
refute.stdout("Yo man"); | ||
assert.stdout("Hey"); | ||
}, | ||
"includes mission statement": function (done) { | ||
var self = this; | ||
var statement = "A small CLI that only lives in the test suite."; | ||
this.cli.missionStatement = statement; | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(self.stdout, statement); | ||
})); | ||
}, | ||
"includes description": function (done) { | ||
var self = this; | ||
var desc = "How about that."; | ||
this.cli.description = desc; | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(self.stdout, desc); | ||
})); | ||
}, | ||
"lists help output for all options, including --help": function (done) { | ||
var self = this; | ||
var portOpt = this.cli.opt("-p", "--port", "Help text is here."); | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(self.stdout, /-h\/--help \s*Show this message\./); | ||
assert.match(self.stdout, /-p\/--port \s*Help text is here\./); | ||
})); | ||
} | ||
}, | ||
"log levels": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
}, | ||
"set to log by default": function (done) { | ||
this.cli.onRun = function () { | ||
"is set to info with --log-level": function (done) { | ||
this.cli.parseArgs(["--log-level", "info"], done(function () { | ||
this.logger.info("Yo man"); | ||
this.logger.log("Hey"); | ||
}; | ||
cliHelper.run(this, [], done(function () { | ||
refute.stdout("Yo man"); | ||
assert.stdout("Hey"); | ||
})); | ||
}, | ||
"set to info with --log-level": function (done) { | ||
this.cli.onRun = function () { | ||
this.logger.info("Yo man"); | ||
this.logger.log("Hey"); | ||
}; | ||
cliHelper.run(this, ["--log-level", "info"], done(function () { | ||
assert.stdout("Yo man"); | ||
})); | ||
}.bind(this))); | ||
}, | ||
"include --log-level in help output": function (done) { | ||
cliHelper.run(this, ["-h"], done(function () { | ||
"includes --log-level in help output": function (done) { | ||
this.cli.addHelpOption(); | ||
this.cli.parseArgs(["-h"], done(function () { | ||
assert.stdout("-l/--log-level"); | ||
@@ -93,10 +42,10 @@ assert.stdout("Set logging level"); | ||
"fail if providing -l without argument": function (done) { | ||
cliHelper.run(this, ["-l"], done(function () { | ||
"fails for -l without argument": function (done) { | ||
this.cli.parseArgs(["-l"], done(function () { | ||
assert.stderr("No value specified"); | ||
})); | ||
}.bind(this))); | ||
}, | ||
"fails if providing illegal logging level": function (done) { | ||
cliHelper.run(this, ["-l", "dubious"], done(function () { | ||
this.cli.parseArgs(["-l", "dubious"], done(function () { | ||
assert.stderr("one of [error, warn, log, info, debug], " + | ||
@@ -106,29 +55,25 @@ "got dubious"); | ||
}, | ||
"sets to info with -v": function (done) { | ||
this.cli.onRun = function () { | ||
"//is set to info with -v": function (done) { | ||
this.cli.parseArgs(["-v"], done(function () { | ||
this.logger.debug("Yo man"); | ||
this.logger.info("Hey"); | ||
}; | ||
cliHelper.run(this, ["-v"], done(function () { | ||
refute.stdout("Yo man"); | ||
assert.stdout("Hey"); | ||
})); | ||
}.bind(this))); | ||
}, | ||
"sets to debug with -vv": function (done) { | ||
this.cli.onRun = function () { | ||
"//is set to debug with -vv": function (done) { | ||
this.cli.parseArgs(["-vv"], done(function () { | ||
this.logger.debug("Yo man"); | ||
this.logger.info("Hey"); | ||
}; | ||
cliHelper.run(this, ["-vv"], done(function () { | ||
assert.stdout("Yo man"); | ||
})); | ||
}.bind(this))); | ||
}, | ||
"fails if setting -v more than twice": function (done) { | ||
cliHelper.run(this, ["-vvv"], done(function () { | ||
assert.stderr("-v can only be set two times."); | ||
this.cli.parseArgs(["-vvv"], done(function () { | ||
assert.stderr("-v/--verbose: can only be set 2 times."); | ||
})); | ||
@@ -138,180 +83,197 @@ } | ||
"option": { | ||
setUp: function () { | ||
this.port = this.cli.opt("-p", "--port", "Help text is here.", {}); | ||
"generic help output": { | ||
"includes mission statement": function (done) { | ||
var statement = "A small CLI that only lives in the test suite."; | ||
this.cli.addHelpOption(statement); | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout(statement); | ||
})); | ||
}, | ||
"is addressable by short key": function (done) { | ||
this.cli.run(["-p"], done(function () { | ||
assert(this.port.isSet); | ||
}.bind(this))); | ||
"includes description": function (done) { | ||
var desc = "How about that."; | ||
this.cli.addHelpOption("Yo", desc); | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout(desc); | ||
})); | ||
}, | ||
"is addressable by long key": function (done) { | ||
this.cli.run(["--port"], done(function () { | ||
assert(this.port.isSet); | ||
}.bind(this))); | ||
"lists help output for all options, including --help": function (done) { | ||
var portOpt = this.cli.opt(["-p", "--port"], { | ||
description: "Help text is here." | ||
}); | ||
this.cli.addHelpOption(); | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout(/-h\/--help \s*Show this message\./); | ||
assert.stdout(/-p\/--port \s*Help text is here\./); | ||
})); | ||
} | ||
}, | ||
"calls 'loadOptions' once if present": function (done) { | ||
cliHelper.mockLogger(this); | ||
this.cli.loadOptions = this.spy(); | ||
this.cli.run(["--help"], function () { | ||
this.cli.run(["--help"], done(function () { | ||
assert(this.cli.loadOptions.calledOnce); | ||
}.bind(this))); | ||
}.bind(this)); | ||
}, | ||
"help topics": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.cli.helpTopics = { | ||
this.helpTopics = { | ||
"topic": "This is the text for the topic.", | ||
"other": "Another topic" | ||
}; | ||
this.cli.addHelpOption("Yo", "Here ya go", this.helpTopics); | ||
}, | ||
"is listed with the description of --help": function (done) { | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(this.stdout, "See also --help [topic,other]."); | ||
}.bind(this))); | ||
"are listed with the description of --help": function (done) { | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout("See also -h/--help [topic,other]."); | ||
})); | ||
}, | ||
"prints topic help with --help sometopic": function (done) { | ||
this.cli.run(["--help", "topic"], done(function () { | ||
assert.equals(this.stdout, "This is the text for the topic.\n"); | ||
}.bind(this))); | ||
this.cli.parseArgs(["--help", "topic"], done(function () { | ||
assert.stdout("This is the text for the topic.\n"); | ||
})); | ||
}, | ||
"prints error message with --help noneexistingtopic": function (done) { | ||
this.cli.run(["--help", "doesnotexist"], done(function () { | ||
assert.equals(this.stderr, "No such help topic " + | ||
this.cli.parseArgs(["--help", "doesnotexist"], done(function () { | ||
assert.stderr("No such help topic " + | ||
"'doesnotexist'. Try without a specific help " + | ||
"topic, or one of: topic,other.\n"); | ||
}.bind(this))); | ||
})); | ||
}, | ||
"prints topic unwrapped when just one topic": function (done) { | ||
var self = this; | ||
var cli = busterCli.create(); | ||
cli.createLogger(this.stdout, this.stderr); | ||
cli.addHelpOption( | ||
"", "", { "topic": "This is the text for the topic." } | ||
); | ||
this.cli.helpTopics = { | ||
"topic": "This is the text for the topic." | ||
}; | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(self.stdout, "See also --help topic."); | ||
}.bind(this))); | ||
cli.parseArgs(["--help"], done(function () { | ||
assert.stdout("See also -h/--help topic."); | ||
})); | ||
}, | ||
"should not print topic information when no topics": function (done) { | ||
this.cli.helpTopics = {}; | ||
this.cli.run(["--help"], done(function () { | ||
refute.match(this.stdout, "See also --help []."); | ||
}.bind(this))); | ||
var cli = busterCli.create(); | ||
cli.createLogger(this.stdout, this.stderr); | ||
cli.addHelpOption( | ||
"", "", { "topic": "This is the text for the topic." } | ||
); | ||
cli.parseArgs(["--help"], done(function () { | ||
refute.stdout("See also --help []."); | ||
})); | ||
} | ||
}, | ||
"option restricted to list of values": { | ||
"options": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.aaaOpt = this.cli.opt("-a", "--aaa", "Aaaaa!", { | ||
values: ["foo", "bar", "baz"] | ||
}); | ||
this.cli.addHelpOption(); | ||
}, | ||
"lists available options in help output": function (done) { | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(this.stdout, "One of foo, bar, baz."); | ||
}.bind(this))); | ||
"are addressable by short key": function (done) { | ||
this.cli.opt(["-p", "--port"], { | ||
description: "Help text is here." | ||
}); | ||
this.cli.parseArgs(["-p"], done(function (errors, options) { | ||
assert(options["-p"].isSet); | ||
})); | ||
}, | ||
"gets value set when value passed to it": function (done) { | ||
this.cli.run(["-a", "bar"], done(function () { | ||
assert.equals(this.aaaOpt.value, "bar"); | ||
}.bind(this))); | ||
"is addressable by long key": function (done) { | ||
this.cli.opt(["-p", "--port"], { | ||
description: "Help text is here." | ||
}); | ||
this.cli.parseArgs(["--port"], done(function (errors, options) { | ||
assert(options["-p"].isSet); | ||
})); | ||
}, | ||
"errors when getting a value not in the list": function (done) { | ||
this.cli.run(["-a", "lolcat"], done(function () { | ||
// The actual error message comes from buster-args. | ||
// TODO: Find a better way to test the error msg here. | ||
refute.equals(this.stderr, ""); | ||
}.bind(this))); | ||
} | ||
}, | ||
"restricted to list of values": { | ||
setUp: function () { | ||
this.cli.opt(["-a", "--aaa"], { | ||
description: "Aaaaa!", | ||
values: ["foo", "bar", "baz"] | ||
}); | ||
}, | ||
"option with default value": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.aaaOpt = this.cli.opt("-f", "--ffff", "Fffffuuu", { | ||
defaultValue: "DRM" | ||
}); | ||
}, | ||
"lists available options in help output": function (done) { | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout("One of foo, bar, baz."); | ||
}.bind(this))); | ||
}, | ||
"prints default value in help text": function (done) { | ||
this.cli.run(["--help"], done(function () { | ||
assert.match(this.stdout, "Default is DRM."); | ||
}.bind(this))); | ||
}, | ||
"gets passed value": function (done) { | ||
this.cli.parseArgs(["-a", "bar"], done(function (errors, options) { | ||
assert.equals(options["-a"].value, "bar"); | ||
}.bind(this))); | ||
}, | ||
"should have default value": function (done) { | ||
var self = this; | ||
this.cli.run([], function () { | ||
assert.equals(self.aaaOpt.value, "DRM"); | ||
done(); | ||
}); | ||
"errors for value not in the list": function (done) { | ||
this.cli.parseArgs(["-a", "lolcat"], done(function () { | ||
refute.stderr(/^$/); | ||
})); | ||
} | ||
}, | ||
"should provide overridden value": function (done) { | ||
var self = this; | ||
this.cli.run(["-f", "gaming consoles"], function () { | ||
assert.equals(self.aaaOpt.value, "gaming consoles"); | ||
done(); | ||
}); | ||
}, | ||
"with default value": { | ||
setUp: function () { | ||
this.aaaOpt = this.cli.opt(["-f", "--ffff"], { | ||
description: "Fffffuuu", | ||
defaultValue: "DRM" | ||
}); | ||
}, | ||
" should fail with no value": function (done) { | ||
// Not failing. Probably a flaw in buster-args. | ||
var self = this; | ||
this.cli.run(["-f"], function () { | ||
refute.equals(self.stderr, ""); | ||
done(); | ||
}); | ||
} | ||
}, | ||
"prints default in help text": function (done) { | ||
this.cli.parseArgs(["--help"], done(function () { | ||
assert.stdout("Default is DRM."); | ||
})); | ||
}, | ||
"option with value": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.someOpt = this.cli.opt("-s", "--ss", "A creeper.", { | ||
hasValue: true | ||
}); | ||
"has default value": function (done) { | ||
this.cli.parseArgs([], done(function (errors, options) { | ||
assert.equals(options["-f"].value, "DRM"); | ||
}.bind(this))); | ||
}, | ||
"provides overridden value": function (done) { | ||
this.cli.parseArgs(["-f", "gaming consoles"], done(function (e, options) { | ||
assert.equals(options["-f"].value, "gaming consoles"); | ||
}.bind(this))); | ||
}, | ||
"fails with no value": function (done) { | ||
this.cli.parseArgs(["-f"], done(function () { | ||
refute.stderr(/^$/); | ||
})); | ||
} | ||
}, | ||
"should get value assigned": function (done) { | ||
var self = this; | ||
this.cli.run(["-s", "ssssssBOOOOOM!"], function () { | ||
assert.equals(self.someOpt.value, "ssssssBOOOOOM!"); | ||
done(); | ||
}); | ||
} | ||
}, | ||
"with value": { | ||
setUp: function () { | ||
this.cli.opt(["-s", "--ss"], { | ||
description: "A creeper.", | ||
hasValue: true | ||
}); | ||
}, | ||
"option with validator": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.anOpt = this.cli.opt("-c", "--character", "The character.", { | ||
validators: {"required": "Here's a custom error msg."} | ||
}); | ||
"gets value assigned": function (done) { | ||
this.cli.parseArgs(["-s", "ssssBOOOOOM!"], done(function (e, options) { | ||
assert.equals(options["-s"].value, "ssssBOOOOOM!"); | ||
}.bind(this))); | ||
} | ||
}, | ||
"should perform validation": function (done) { | ||
var self = this; | ||
this.cli.run([], function () { | ||
assert.match(self.stderr, "Here's a custom error msg."); | ||
done(); | ||
}); | ||
"with validator": { | ||
setUp: function () { | ||
this.cli.opt(["-c", "--character"], { | ||
description: "Character.", | ||
validators: [v.required("Here's a custom error msg.")] | ||
}); | ||
}, | ||
"validates": function (done) { | ||
this.cli.parseArgs([], done(function () { | ||
assert.stderr("Here's a custom error msg."); | ||
})); | ||
} | ||
} | ||
@@ -322,63 +284,25 @@ }, | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.fooOpd = this.cli.opd("Foo", "Does a foo."); | ||
this.cli.addHelpOption(); | ||
this.cli.opd("Foo", { description: "Does a foo." }); | ||
}, | ||
"should be listed in --help output": function (done) { | ||
var self = this; | ||
this.cli.run(["--help"], function () { | ||
assert.match(self.stdout, /Foo + {3}Does a foo/); | ||
done(); | ||
}); | ||
"is listed in --help output": function (done) { | ||
this.cli.parseArgs(["-h"], done(function () { | ||
assert.stdout(/Foo + {3}Does a foo/); | ||
})); | ||
}, | ||
"should get value assigned": function (done) { | ||
var self = this; | ||
this.cli.run(["some value"], function () { | ||
assert.equals(self.fooOpd.value, "some value"); | ||
done(); | ||
}); | ||
"gets value assigned": function (done) { | ||
this.cli.parseArgs(["some value"], done(function (errors, options) { | ||
assert.equals(options.Foo.value, "some value"); | ||
}.bind(this))); | ||
} | ||
}, | ||
"should call onRun when there are no errors": function (done) { | ||
this.cli.onRun = done(function () { | ||
assert(true); | ||
}); | ||
this.cli.run([], function () {}); | ||
}, | ||
"should not call onRun when there are errors": function () { | ||
var self = this; | ||
cliHelper.mockLogger(this); | ||
this.cli.onRun = this.spy(); | ||
var someOpt = this.cli.opt("-a", "--aa", "Aaaaa"); | ||
someOpt.addValidator(function (arg, promise) { | ||
promise.reject("An error."); | ||
}); | ||
this.cli.run(["-a"], function () { | ||
refute(self.cli.onRun.called); | ||
done(); | ||
}); | ||
}, | ||
"panicking": { | ||
setUp: function () { | ||
cliHelper.mockLogger(this); | ||
this.stub(process, "exit"); | ||
}, | ||
"logs to stderr": function () { | ||
this.cli.err("Uh-oh! Trouble!"); | ||
"should logg to stderr": function (done) { | ||
var self = this; | ||
this.cli.onRun = function () { | ||
this.err("Uh-oh! Trouble!"); | ||
}; | ||
this.cli.run([], function () { | ||
assert.equals(self.stdout, ""); | ||
assert.match(self.stderr, "Uh-oh! Trouble!"); | ||
done(); | ||
}); | ||
assert.stdout(/^$/); | ||
assert.stderr("Uh-oh! Trouble!"); | ||
} | ||
@@ -390,42 +314,23 @@ }, | ||
cliHelper.cdFixtures(); | ||
cliHelper.mockLogger(this); | ||
this.cli.addConfigOption(); | ||
this.cli.addConfigOption("seaman"); | ||
}, | ||
tearDown: function (done) { | ||
var mod; | ||
for (mod in require.cache) { | ||
if (/fixtures/.test(mod)) { | ||
delete require.cache[mod]; | ||
} | ||
} | ||
cliHelper.clearFixtures(done); | ||
}, | ||
tearDown: cliHelper.clearFixtures, | ||
"fails if config does not exist": function (done) { | ||
this.cli.run(["-c", "file.js"], function () { | ||
this.cli.onConfig(done(function (err) { | ||
this.cli.parseArgs(["-c", "file.js"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err) { | ||
assert.match(err.message, "-c/--config: file.js did not match any files"); | ||
}.bind(this))); | ||
})); | ||
}.bind(this)); | ||
}, | ||
"fails if config is a directory": function (done) { | ||
cliHelper.mkdir("buster"); | ||
this.cli.run(["-c", "buster"], function () { | ||
this.cli.onConfig(done(function (err) { | ||
assert.match(err.message, "-c/--config: buster did not match any files"); | ||
}.bind(this))); | ||
}.bind(this)); | ||
}, | ||
"fails if default config does not exist": function (done) { | ||
this.cli.run([], function () { | ||
this.cli.onConfig(done(function (err) { | ||
assert(err); | ||
this.cli.parseArgs([], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err) { | ||
assert.defined(err); | ||
assert.match(err.message, | ||
"-c/--config not provided, and none of\n" + | ||
"[buster.js, test/buster.js, spec/buster.js]" + | ||
" exists"); | ||
"-c/--config: No file provided, and none of\n" + | ||
"[seaman.js, test/seaman.js, spec/seaman.js]" + | ||
" exist"); | ||
})); | ||
@@ -435,23 +340,10 @@ }.bind(this)); | ||
"fails if config contains errors": function (done) { | ||
cliHelper.writeFile("buster.js", "modul.exports"); | ||
this.cli.run(["-c", "buster.js"], done(function () { | ||
this.cli.onConfig(function (err) { | ||
assert.match(err.message, | ||
"Error loading configuration buster.js"); | ||
assert.match(err.message, "modul is not defined"); | ||
assert.match(err.stack, /\d+:\d+/); | ||
}); | ||
}.bind(this))); | ||
}, | ||
"fails if configuration has no groups": function (done) { | ||
cliHelper.writeFile("buster.js", ""); | ||
cliHelper.writeFile("seaman.js", ""); | ||
this.cli.run([], function () { | ||
this.cli.onConfig(done(function (err) { | ||
this.cli.parseArgs([], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err) { | ||
assert(err); | ||
assert.match(err.message, | ||
"buster.js contains no configuration"); | ||
"seaman.js contains no configuration"); | ||
})); | ||
@@ -467,12 +359,10 @@ }.bind(this)); | ||
}); | ||
cliHelper.writeFile("buster.js", "module.exports = " + json); | ||
cliHelper.writeFile("buster2.js", "module.exports = " + json); | ||
cliHelper.writeFile("seaman.js", "module.exports = " + json); | ||
cliHelper.writeFile("seaman2.js", "module.exports = " + json); | ||
}, | ||
"loads configuration": function (done) { | ||
var self = this; | ||
this.cli.run(["-c", "buster.js"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.defined(config); | ||
this.cli.parseArgs(["-c", "seaman.js"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert.defined(groups); | ||
})); | ||
@@ -483,61 +373,19 @@ }.bind(this)); | ||
"loads multiple configuration files": function (done) { | ||
var self = this; | ||
this.cli.run(["-c", "buster.js,buster2.js"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 4); | ||
this.cli.parseArgs(["-c", "seaman.js,seaman2.js"], function (e, opts) { | ||
this.cli.loadConfig(opts, done(function (err, groups) { | ||
assert.equals(groups.length, 4); | ||
})); | ||
}.bind(this)); | ||
} | ||
}, | ||
"smart configuration loading": { | ||
setUp: function () { | ||
cliHelper.mkdir("somewhere/nested/place"); | ||
this.assertConfigLoaded = function (done) { | ||
this.cli.run([], function () { | ||
this.cli.onConfig(function (err) { | ||
refute.defined(err); | ||
done(); | ||
}); | ||
}.bind(this)); | ||
}; | ||
}, | ||
tearDown: cliHelper.clearFixtures, | ||
"fails if one of many configuration files has no groups": function (done) { | ||
cliHelper.writeFile("seaman3.js", ""); | ||
"with config in root directory": { | ||
setUp: function () { | ||
var cfg = { environment: "node" }; | ||
cliHelper.writeFile("buster.js", "module.exports = " + | ||
JSON.stringify({ "Node tests": cfg })); | ||
}, | ||
"finds configuration in parent directory": function (done) { | ||
process.chdir("somewhere"); | ||
this.assertConfigLoaded(done); | ||
}, | ||
"finds configuration three levels down": function (done) { | ||
process.chdir("somewhere/nested/place"); | ||
this.assertConfigLoaded(done); | ||
} | ||
}, | ||
"with config in root/test directory": { | ||
setUp: function () { | ||
var cfg = { environment: "node" }; | ||
cliHelper.mkdir("test"); | ||
cliHelper.writeFile("test/buster.js", "module.exports = " + | ||
JSON.stringify({ "Node tests": cfg })); | ||
}, | ||
"finds configuration in parent directory": function (done) { | ||
process.chdir("somewhere"); | ||
this.assertConfigLoaded(done); | ||
}, | ||
"finds configuration three levels down": function (done) { | ||
process.chdir("somewhere/nested/place"); | ||
this.assertConfigLoaded(done); | ||
} | ||
this.cli.parseArgs(["-c", "seaman.js,seaman3.js"], function (e, opts) { | ||
this.cli.loadConfig(opts, done(function (err) { | ||
assert(err); | ||
assert.match(err.message, | ||
"seaman3.js contains no configuration"); | ||
})); | ||
}.bind(this)); | ||
} | ||
@@ -552,3 +400,3 @@ }, | ||
}); | ||
cliHelper.writeFile("buster.js", "module.exports = " + json); | ||
cliHelper.writeFile("seaman.js", "module.exports = " + json); | ||
}, | ||
@@ -559,8 +407,6 @@ | ||
"should only yield config for provided group": function (done) { | ||
var self = this; | ||
this.cli.run(["-g", "Browser tests"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].name, "Browser tests"); | ||
this.cli.parseArgs(["-g", "Browser tests"], function (err, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert.equals(groups.length, 1); | ||
assert.equals(groups[0].name, "Browser tests"); | ||
})); | ||
@@ -571,7 +417,6 @@ }.bind(this)); | ||
"only yields config for fuzzily matched group": function (done) { | ||
var self = this; | ||
this.cli.run(["-g", "browser"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].name, "Browser tests"); | ||
this.cli.parseArgs(["-g", "browser"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert.equals(groups.length, 1); | ||
assert.equals(groups[0].name, "Browser tests"); | ||
})); | ||
@@ -582,6 +427,6 @@ }.bind(this)); | ||
"fails if no groups match": function (done) { | ||
this.cli.run(["-g", "stuff"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
this.cli.parseArgs(["-g", "stuff"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert.match(err.message, | ||
"buster.js contains no configuration " + | ||
"seaman.js contains no configuration " + | ||
"groups that matches 'stuff'"); | ||
@@ -602,11 +447,10 @@ assert.match(err.message, "Try one of"); | ||
}); | ||
cliHelper.writeFile("buster.js", "module.exports = " + json); | ||
cliHelper.writeFile("seaman.js", "module.exports = " + json); | ||
}, | ||
"only yields config for provided environment": function (done) { | ||
var self = this; | ||
this.cli.run(["-e", "node"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].name, "Node tests"); | ||
this.cli.parseArgs(["-e", "node"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert.equals(groups.length, 1); | ||
assert.equals(groups[0].name, "Node tests"); | ||
})); | ||
@@ -617,8 +461,6 @@ }.bind(this)); | ||
"matches config environments with --environment": function (done) { | ||
var self = this; | ||
this.cli.run(["--environment", "browser"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].name, "Browser tests"); | ||
this.cli.parseArgs(["--environment", "browser"], function (e, opts) { | ||
this.cli.loadConfig(opts, done(function (err, groups) { | ||
assert.equals(groups.length, 1); | ||
assert.equals(groups[0].name, "Browser tests"); | ||
})); | ||
@@ -629,7 +471,7 @@ }.bind(this)); | ||
"fails if no environments match": function (done) { | ||
this.cli.run(["-e", "places"], function () { | ||
this.cli.onConfig(done(function (err, config) { | ||
this.cli.parseArgs(["-e", "places"], function (errors, options) { | ||
this.cli.loadConfig(options, done(function (err, groups) { | ||
assert(err); | ||
assert.match(err.message, | ||
"buster.js contains no configuration " + | ||
"seaman.js contains no configuration " + | ||
"groups for environment 'places'"); | ||
@@ -644,7 +486,7 @@ assert.match(err.message, "Try one of"); | ||
"fails if no groups match environment and group": function (done) { | ||
this.cli.run(["-e", "node", "-g", "browser"], function () { | ||
this.cli.onConfig(done(function (err) { | ||
this.cli.parseArgs(["-e", "node", "-g", "browser"], function (e, opt) { | ||
this.cli.loadConfig(opt, done(function (err) { | ||
assert(err); | ||
assert.match(err.message, | ||
"buster.js contains no configuration " + | ||
"seaman.js contains no configuration " + | ||
"groups for environment 'node' that " + | ||
@@ -669,4 +511,3 @@ "matches 'browser'"); | ||
}); | ||
cliHelper.writeFile("buster.js", "module.exports = " + json); | ||
cliHelper.writeFile("seaman.js", "module.exports = " + json); | ||
cliHelper.writeFile("src/1.js", "Src #1"); | ||
@@ -682,5 +523,5 @@ cliHelper.writeFile("test/1.js", "Test #1"); | ||
"strips unmatched files in tests": function (done) { | ||
this.cli.run(["--tests", "test/1.js"], function () { | ||
this.cli.onConfig(function (err, config) { | ||
config.groups[0].resolve().then(done(function (rs) { | ||
this.cli.parseArgs(["--tests", "test/1.js"], function (errors, opts) { | ||
this.cli.loadConfig(opts, function (err, groups) { | ||
groups[0].resolve().then(done(function (rs) { | ||
assert.equals(rs.loadPath.paths().length, 2); | ||
@@ -694,5 +535,5 @@ refute.defined(rs.get("test2.js")); | ||
"matches directories in tests": function (done) { | ||
this.cli.run(["--tests", "test/other/**"], function () { | ||
this.cli.onConfig(function (err, config) { | ||
config.groups[0].resolve().then(done(function (rs) { | ||
this.cli.parseArgs(["--tests", "test/other/**"], function (err, opts) { | ||
this.cli.loadConfig(opts, function (err, groups) { | ||
groups[0].resolve().then(done(function (rs) { | ||
assert.equals(rs.loadPath.paths().length, 3); | ||
@@ -706,25 +547,12 @@ assert.defined(rs.get("test/other/1.js")); | ||
"fails on non-existent tests": "Don't know where to do this - " + | ||
"the error spawns in the load:tests handler.\nMust keep " + | ||
"state to handle properly(?)", | ||
"resolves relative paths": function (done) { | ||
var cwd = process.cwd(); | ||
process.chdir(".."); | ||
this.cli.run(["-c", "fixtures/buster.js", | ||
"--tests", "fixtures/test/1.js"], function () { | ||
this.cli.onConfig(function (err, config) { | ||
config.groups[0].resolve().then(done(function (rs) { | ||
assert.equals(rs.loadPath.paths().length, 2); | ||
refute.defined(rs.get("test2.js")); | ||
})); | ||
}); | ||
}.bind(this)); | ||
}, | ||
var dir = cwd.replace(process.cwd() + "/", ""); | ||
"//finds config in dir specified by --tests": function (done) { | ||
process.chdir(".."); | ||
this.cli.run(["--tests", "fixtures/test/1.js"], function () { | ||
this.cli.onConfig(function (err, config) { | ||
config.resolveGroups(done(function (err, groups) { | ||
var rs = groups[0].resourceSet; | ||
var args = ["-c", dir + "/seaman.js", | ||
"--tests", dir + "/test/1.js"]; | ||
this.cli.parseArgs(args, function (e, opt) { | ||
this.cli.loadConfig(opt, function (err, groups) { | ||
groups[0].resolve().then(done(function (rs) { | ||
assert.equals(rs.loadPath.paths().length, 2); | ||
@@ -739,46 +567,2 @@ refute.defined(rs.get("test2.js")); | ||
"configuration with specified environment": { | ||
setUp: function () { | ||
cliHelper.cdFixtures(); | ||
cliHelper.mockLogger(this); | ||
var json = JSON.stringify({ | ||
"Node tests": { environment: "node" }, | ||
"Browser tests": { environment: "browser" } | ||
}); | ||
cliHelper.writeFile("buster.js", "module.exports = " + json); | ||
}, | ||
"set to browser": { | ||
setUp: function () { | ||
this.cli.addConfigOption("browser"); | ||
}, | ||
"should only contain browser groups": function (done) { | ||
var self = this; | ||
this.cli.run([], function () { | ||
self.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].environment, "browser"); | ||
})); | ||
}); | ||
} | ||
}, | ||
"set to node": { | ||
setUp: function () { | ||
this.cli.addConfigOption("node"); | ||
}, | ||
"should only contain node groups": function (done) { | ||
var self = this; | ||
this.cli.run([], function () { | ||
self.cli.onConfig(done(function (err, config) { | ||
assert.equals(config.groups.length, 1); | ||
assert.equals(config.groups[0].environment, "node"); | ||
})); | ||
}); | ||
} | ||
} | ||
}, | ||
"cli customization": { | ||
@@ -794,7 +578,7 @@ setUp: function () { | ||
"adds command-line options set with environment variable": function () { | ||
var stub = this.stub(this.cli.args, "handle"); | ||
var stub = this.stub(this.cli.args, "parse"); | ||
this.cli.environmentVariable = "BUSTER_OPT"; | ||
process.env.BUSTER_OPT = "--color none -r specification"; | ||
this.cli.run([]); | ||
this.cli.parseArgs([]); | ||
@@ -805,6 +589,6 @@ assert.calledWith(stub, ["--color", "none", "-r", "specification"]); | ||
"does not add cli options when no env variable is set": function () { | ||
var stub = this.stub(this.cli.args, "handle"); | ||
var stub = this.stub(this.cli.args, "parse"); | ||
process.env.BUSTER_OPT = "--color none -r specification"; | ||
this.cli.run([]); | ||
this.cli.parseArgs([]); | ||
@@ -811,0 +595,0 @@ assert.calledWith(stub, []); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
20
1
6
40690
7
1
982
1
+ Addedbuster-core@>=0.6.2
+ Addedposix-argv-parser@>=0.4
+ Addedstream-logger@>=0.3.0
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedevented-logger@1.0.1(transitive)
+ Addedminimatch@10.0.1(transitive)
+ Addedposix-argv-parser@2.0.0(transitive)
+ Addedstream-logger@1.0.1(transitive)
- Removedbuster-args@>=0.3.1
- Removedbuster-stdio-logger@>=0.2.2
- Removedbuster-args@0.3.1(transitive)
- Removedbuster-evented-logger@0.4.5(transitive)
- Removedbuster-stdio-logger@0.2.2(transitive)
- Removedlru-cache@1.0.6(transitive)
- Removedminimatch@0.1.5(transitive)
Updatedbuster-configuration@>=0.5.0
Updatedbuster-terminal@>=0.4.1
Updatedminimatch@>=0.2