smartcli/test/test.ts

186 lines
6.0 KiB
TypeScript
Raw Normal View History

2016-03-14 06:12:00 +00:00
/// <reference path="typings/main.d.ts" />
var smartcli = require("../index.js");
var beautylog = require("beautylog");
2015-10-06 23:07:38 +00:00
var commandsString:string = 'You specified the following commands:';
var commands = smartcli.get.commandArray();
2015-10-06 23:07:38 +00:00
for (var key in commands) {
commandsString = commandsString + ' ' + commands[key];
}
2016-03-14 06:12:00 +00:00
beautylog.log(commandsString);
2015-10-06 23:07:38 +00:00
2015-10-14 18:59:01 +00:00
/* ------------------------------------------------------------------ *
* ------------------- CHECKS TESTS --------------------------------- *
* ------------------------------------------------------------------ */
2015-10-14 18:59:01 +00:00
/**
*
*/
2015-10-14 18:59:01 +00:00
var checkCommandTest = function() {
if (smartcli.check.command('jazz')) {
2016-03-14 06:12:00 +00:00
beautylog.success('One of your commands is jazz. It is supposed to be there. Perfect!');
} else {
2016-03-14 06:12:00 +00:00
beautylog.error('None of your commands is jazz. You need to check this');
process.exit(1);
}
if (!smartcli.check.command('punk')) {
2016-03-14 06:12:00 +00:00
beautylog.success('None of your commands is punk. It is not supposed to be there. Perfect!');
2015-10-14 18:59:01 +00:00
} else {
2016-03-14 06:12:00 +00:00
beautylog.error('One of your commands seems to be punk. Something is wrong here');
process.exit(1);
2015-10-14 18:59:01 +00:00
}
};
checkCommandTest();
2015-10-14 18:59:01 +00:00
2015-10-06 23:07:38 +00:00
var checkCommandPresenceTest = function() {
if (smartcli.check.commandPresence()) {
2016-03-14 06:12:00 +00:00
beautylog.success('There are commands present, like supposed to. Perfect!');
} else {
2016-03-14 06:12:00 +00:00
beautylog.error('There do not seem to be any commands present... This is wrong');
process.exit(1);
}
};
checkCommandPresenceTest();
2015-10-14 18:59:01 +00:00
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!');
} 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();
2015-10-05 21:33:57 +00:00
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);
}
};
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);
};
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();
};
2015-10-05 21:33:57 +00:00
2015-10-14 18:59:01 +00:00