smartcli/test/test.js

153 lines
20 KiB
JavaScript
Raw Normal View History

2016-05-23 02:09:06 +00:00
/// <reference path="../ts/typings/index.d.ts" />
2016-03-18 17:08:26 +00:00
var smartcli = require("../dist/index.js");
2016-05-11 00:11:40 +00:00
var beautylog = require("beautylog");
var should = require("should");
/* ------------------------------------------------------------------ *
* ------------------- CHECKS TESTS --------------------------------- *
* ------------------------------------------------------------------ */
2016-04-04 23:22:11 +00:00
describe("smartcli", function () {
describe(".check", function () {
describe(".command", function () {
it("should return true when specified command is found", function () {
smartcli.check.command("jazz").should.be.true();
});
it("should return false when specified command is NOT found", function () {
smartcli.check.command("rock").should.be.false();
});
});
describe(".commandPresence", function () {
});
});
});
var checkCommandArgumentTest = function () {
if (smartcli.check.commandArgument("jam", 1)) {
2016-03-14 06:12:00 +00:00
beautylog.success('There is a level 1 argument! Perfect!');
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgument("session", 2)) {
2016-03-14 06:12:00 +00:00
beautylog.success('There is no level 2 argument with the name of "session"! Perfect!');
2015-10-14 18:59:01 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('There seems to be a level 2 argument with the name of "session"! This is wrong');
process.exit(1);
2015-10-14 18:59:01 +00:00
}
};
checkCommandArgumentTest();
var checkCommandArgumentPresenceTest = function () {
if (smartcli.check.commandArgumentPresence(1)) {
2016-03-14 06:12:00 +00:00
beautylog.success('There is a level 1 argument! Perfect!');
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('There seems to be no level 1 argument... This is wrong');
process.exit(1);
}
if (!smartcli.check.commandArgumentPresence(2)) {
2016-03-14 06:12:00 +00:00
beautylog.success('There is no level 2 argument! Perfect!');
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('There seems to be a level 2 argument... This is wrong');
process.exit(1);
}
2015-10-14 18:59:01 +00:00
};
checkCommandArgumentPresenceTest();
/* ------------------------------------------------------------------ *
* ------------------- GETTERS TESTS -------------------------------- *
* ------------------------------------------------------------------ */
2015-11-09 03:02:46 +00:00
var getCommandTest = function () {
var cliCommand = smartcli.get.command();
if (cliCommand.name == "jazz") {
2016-03-14 06:12:00 +00:00
beautylog.success('The specified command name is "jazz". Perfect!');
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('The specified command name is not "jazz". Something is wrong!');
2015-11-09 03:02:46 +00:00
process.exit(1);
}
};
getCommandTest();
var getCommandArgumentTest = function () {
var cliArgument = smartcli.get.commandArgument(1);
var cliArgument2 = smartcli.get.commandArgument(2);
if (cliArgument.name == "jam") {
2016-03-14 06:12:00 +00:00
beautylog.success('The first specified command argument name is "jam". Perfect!');
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('The first specified command argument name is not "jam". Something is wrong!');
2015-11-09 03:02:46 +00:00
process.exit(1);
}
if (cliArgument2.name == "undefined") {
2016-03-14 06:12:00 +00:00
beautylog.success('The second specified command argument name is "undefined". Perfect!');
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error('The second specified command argument name is not "undefined". Something is wrong!');
2015-11-09 03:02:46 +00:00
process.exit(1);
}
};
getCommandArgumentTest();
var getCommandArgsTest = function () {
var commandArgs = smartcli.get.commandArgs();
if (commandArgs[0].name == "jam") {
2016-03-14 06:12:00 +00:00
beautylog.success("first command argument is 'jam'. Perfect!");
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error("first command argument is not 'jam'. Something is wromg!");
2015-11-09 03:02:46 +00:00
console.log(commandArgs[0].name);
process.exit(1);
}
};
getCommandArgsTest();
var getOptionTest = function () {
var cliOption = smartcli.get.option("awesome");
var cliOption2 = smartcli.get.option("terrific");
if (cliOption.specified) {
2016-03-14 06:12:00 +00:00
beautylog.success("awesome is specified. Perfect!");
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error("awesome is not specified. Somehthing is wrong");
2015-11-09 03:02:46 +00:00
process.exit(1);
}
if (!cliOption2.specified) {
2016-03-14 06:12:00 +00:00
beautylog.success("terrific is not specified. Perfect!");
2015-11-09 03:02:46 +00:00
}
else {
2016-03-14 06:12:00 +00:00
beautylog.error("terrific is specified. Somehthing is wrong");
2015-11-09 03:02:46 +00:00
process.exit(1);
}
};
getOptionTest();
var getCwdTest = function () {
2016-03-14 06:12:00 +00:00
beautylog.info('The current directory is: ' + smartcli.get.cwd().path);
2015-10-14 18:59:01 +00:00
};
getCwdTest();
/* ------------------------------------------------------------------ *
* ------------------- INTERACTION TESTS ---------------------------- *
* ------------------------------------------------------------------ */
var interactionGetAnswerTest = function () {
smartcli.interaction.getAnswer('How do you feel?', function (answer) {
2015-10-05 21:33:57 +00:00
console.log('The answer is: ' + answer);
interactionGetChoiceTest();
2015-10-05 21:33:57 +00:00
});
};
var interactionGetChoiceTest = function () {
smartcli.interaction.getChoice('What music do you like to hear?', ['Jazz', 'Blues', 'Classical'], function (answer) {
2015-10-05 21:33:57 +00:00
console.log('The answer is: ' + answer);
endTests();
2015-10-05 21:33:57 +00:00
});
};
var endTests = function () {
2016-03-14 06:12:00 +00:00
beautylog.ok("No more tests!");
beautylog.success("Tests completed successfully!");
};
if (!smartcli.check.option("silent")) {
interactionGetAnswerTest();
}
else {
2016-03-14 06:12:00 +00:00
beautylog.info("--silent option is specified, thus we are not running interaction tests.");
endTests();
}
;
2016-05-10 01:18:40 +00:00
2016-05-23 02:09:06 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsaURBQWlEO0FBQ2pELElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzNDLElBQUksU0FBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ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