Permalink
Browse files

work in progress...

  • Loading branch information...
1 parent bef3793 commit 7c6efcda52a97eb839f309a29e7a93e59bd077d8 @victorjonsson committed Dec 12, 2011
Showing with 45 additions and 28 deletions.
  1. +1 −1 README.md
  2. +29 −12 cli
  3. +15 −15 dokimon
View
@@ -38,7 +38,7 @@ will search for a file named config.json in current working directory if not spe
{
"host" : "api.myservice.com",
"verbose" : false,
- "testdir" : "./tests"
+ "testdir" : "/Users/john/projects/dokimontests"
}
```
View
41 cli
@@ -45,25 +45,35 @@ var dokimon = require('./dokimon'),
// Separate requested scripts from arguments
if(process.argv.length > 3) {
for(i=3; i < process.argv.length; i++) {
+
+ // argument
if(process.argv[i].substring(0,1) == '-') {
- var argVal = '';
+ var argVal = true;
+
+ // requires val
if(arraySearch(process.argv[i], argsRequiringValue) !== false) {
if(process.argv[i+1] == undefined) {
console.log('Value for argument '+process.argv[i]+' missing');
process.exit();
}
argVal = process.argv[i+1];
}
+ else if(arraySearch(process.argv[i], availableArgs) === false) {
+ console.log('Unknown argument '+process.argv[i]);
+ process.exit(0);
+ }
+
args[process.argv[i]] = argVal;
- if(argVal)
+ if(argVal !== true) // value given from command line
i++;
}
+
+ // script
else
scripts.push(process.argv[i]);
}
}
-
// Load configuration and override configuration variables with command line args
if(command != COMMAND.HELP && command != COMMAND.HELP_SHORT) {
if(args[COMMAND.ARG_CONFIG] == undefined)
@@ -76,6 +86,8 @@ if(command != COMMAND.HELP && command != COMMAND.HELP_SHORT) {
config[ argsRequiringValue[i].substr(1, argsRequiringValue[i].length) ] = args[argsRequiringValue[i]];
}
config.testdir = fixPath(config.testdir);
+ if(args[COMMAND.ARG_VERBOSE] != undefined)
+ config.verbose = true;
var testManager = new dokimon.TestManager(config);
}
@@ -95,7 +107,10 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
else {
var testFileName = testManager.scriptNameToPath(process.argv[3]);
console.log('# Will run '+testFileName+'::'+process.argv[4]);
- testManager.setTests(require(testFileName));
+ var t = require(testFileName);
+ if(t instanceof dokimon.Test)
+ t = [t];
+ testManager.setTests(t);
testManager.runTest(process.argv[4]);
}
}
@@ -105,15 +120,17 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
console.log('##-> RUNNING ALL TESTS');
testManager.loadScriptsInDir(config.testdir).forEach(function(script) {
console.log('# Will run '+script);
- var t = require(config.testdir+'/'+script+dokimon.TEST_EXTENSION);
- for(var j=0; j < t.tests.length; j++)0
- collectedTests.push( t.tests[j] );
+ var t = require(config.testdir +'/'+ script + dokimon.TEST_EXTENSION);
+ if(t instanceof dokimon.Test)
+ t = [t];
+ for(var j=0; j < t.length; j++)
+ collectedTests.push( t[j] );
});
testManager.setTests(collectedTests);
testManager.run();
}
- // Run all scripts
+ // Run tests in specified scripts
else {
for(i=0; i < scripts.length; i++) {
try {
@@ -122,7 +139,7 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
var t = require(testFileName);
if(!(t instanceof dokimon.Test)) {
for(var j=0; j < t.length; j++)
- collectedTests.push( t.tests[j] );
+ collectedTests.push( t[j] );
}
else
collectedTests.push(t);
@@ -185,18 +202,18 @@ else if(command == COMMAND.SHOW) {
*/
else if(command == COMMAND.HELP_SHORT || command == COMMAND.HELP) {
console.log('More help available at https://github.com/victorjonsson/dokimon/');
- console.log('Usage dokimon [command] [script | scripts] [arguments]');
+ console.log("Usage:\ndokimon [command] [script | scripts] [arguments]");
console.log('');
console.log('Commands:');
console.log('-r\tRun all scripts or one specified script (e.g. "dokimon -r" or "dokimon -r myscript")');
console.log('-rs\tRun a specific test (e.g. "dokimon -rs myscript sometest")');
- console.log('-l\tList all test scripts and containing tests');
+ console.log('-l\tList all available test scripts and containing tests');
console.log('-s\tList all tests in specified script (e.g. "dokimon -s myscript")');
console.log('');
console.log('Optional arguments:');
console.log('-verbose\tGet a more verbose output when running tests');
console.log('-host \tOverride the host defined in config.json (e.g. "dokimon -r -host test.mysite.com")');
- console.log('-testdir\tUse another test directory then the one defined in config.json (e.g. "dokimon -r -testdir test/production/")');
+ console.log('-testdir\tUse another test directory than the one defined in config.json (e.g. "dokimon -r -testdir ./test/production/")');
console.log('-config \tUse another config file then the one that is automatically loaded by dokimon');
console.log('');
}
View
30 dokimon
@@ -162,10 +162,10 @@ var TestManager = function(config, testFinishCallback) {
};
/**
- * @param {Test[]|Test} tests
+ * @param {Test[]} tests
*/
this.setTests = function(tests) {
- this.tests = util.isArray(tests) ? tests:[tests];
+ this.tests = tests;
};
/**
@@ -320,11 +320,11 @@ var Test = function(testName, options, callback, blocking) {
this.name = testName;
/**
- * @param {TestManager} testManager
+ * @param {TestManager} manager
* @param {Boolean} verbose - Optional
* @param {Function} exeFinishCallback - Optional, will be called when request is finished and test callback is called
*/
- this.execute = function(host, testManager, verbose, exeFinishCallback) {
+ this.execute = function(host, manager, verbose, exeFinishCallback) {
options.host = host;
@@ -339,21 +339,21 @@ var Test = function(testName, options, callback, blocking) {
});
res.on('end', function() {
try {
- callback(res, collectedBody, verbose);
- testManager.registerSuccessfullTest({name : testName, message:''});
- if(typeof exeFinishCallback == 'function')
- exeFinishCallback();
- }
- catch(e) {
- testManager.registerFailedtest({name : testName, message:e.message}, e);
- if(typeof exeFinishCallback == 'function')
- exeFinishCallback();
- }
+ callback(res, collectedBody, verbose);
+ manager.registerSuccessfullTest({name : testName, message:''});
+ if(typeof exeFinishCallback == 'function')
+ exeFinishCallback();
+ }
+ catch(e) {
+ manager.registerFailedtest({name : testName, message:e.message}, e);
+ if(typeof exeFinishCallback == 'function')
+ exeFinishCallback();
+ }
});
});
req.on('error', function(e) {
- testManager.registerFailedtest({name : testName, message:''}, e);
+ manager.registerFailedtest({name : testName, message:''}, e);
});
req.write(options.write);

0 comments on commit 7c6efcd

Please sign in to comment.