Permalink
Browse files

closing in on a beta release

  • Loading branch information...
1 parent 7c6efcd commit 66f81a621d7420e1a8de88a71b5ce41533076255 @victorjonsson committed Dec 13, 2011
Showing with 42 additions and 142 deletions.
  1. +3 −3 README.md
  2. +9 −8 cli
  3. +23 −130 dokimon
  4. +7 −1 package.json
View
@@ -26,7 +26,8 @@ This file should contain a JSON object with the properties "host", "verbose" and
- <strong>host</strong> (String) — Specifies against which host you're going to run the tests.
- <strong>verbose</strong> (Boolean) — Makes it possible to get a more verbose output when running the tests
- - <strong>testdir</strong> (String) — Path to the directory where you have your test scripts
+ - <strong>testdir</strong> (String) — Relative path to the directory where you have your test scripts.
+ This directory should be placed in the project directory.
It's possible to change all of these paremeters on the fly when using the command line interface. It's also
possible to completely switch to another configuration file when using the command line interface. Dokimon
@@ -38,9 +39,8 @@ will search for a file named config.json in current working directory if not spe
{
"host" : "api.myservice.com",
"verbose" : false,
- "testdir" : "/Users/john/projects/dokimontests"
+ "testdir" : "dokimontests"
}
-
```
## Writing tests
View
17 cli
@@ -37,11 +37,13 @@ var dokimon = require('./dokimon'),
},
fixPath = function(path) {
var fl = path.substr(0,1);
- return fl == '.' || fl == '/' ? path : './'+path;
+ if(fl == '.' || fl == '/')
+ return path;
+
+ return process.cwd()+'/'+path;
},
command = process.argv.length > 2 ? process.argv[2]:COMMAND.HELP;
-
// Separate requested scripts from arguments
if(process.argv.length > 3) {
for(i=3; i < process.argv.length; i++) {
@@ -85,7 +87,6 @@ if(command != COMMAND.HELP && command != COMMAND.HELP_SHORT) {
if(args[argsRequiringValue[i]] != undefined)
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;
@@ -107,7 +108,7 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
else {
var testFileName = testManager.scriptNameToPath(process.argv[3]);
console.log('# Will run '+testFileName+'::'+process.argv[4]);
- var t = require(testFileName);
+ var t = require(fixPath(testFileName));
if(t instanceof dokimon.Test)
t = [t];
testManager.setTests(t);
@@ -120,7 +121,7 @@ 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);
+ var t = require(fixPath(config.testdir +'/'+ script + dokimon.TEST_EXTENSION));
if(t instanceof dokimon.Test)
t = [t];
for(var j=0; j < t.length; j++)
@@ -136,7 +137,7 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
try {
var testFileName = testManager.scriptNameToPath(scripts[i]);
console.log('# Will run '+testFileName);
- var t = require(testFileName);
+ var t = require(fixPath(testFileName));
if(!(t instanceof dokimon.Test)) {
for(var j=0; j < t.length; j++)
collectedTests.push( t[j] );
@@ -173,7 +174,7 @@ if(command == COMMAND.RUN || command == COMMAND.RUN_SPECIFIED) {
else if(command == COMMAND.LIST) {
testManager.loadScriptsInDir(config.testdir).forEach(function(script) {
console.log(script);
- var t = require(config.testdir+'/'+script+dokimon.TEST_EXTENSION);
+ var t = require(fixPath(config.testdir+'/'+script+dokimon.TEST_EXTENSION));
if(t instanceof dokimon.Test)
t = [t];
for(var j=0; j < t.length; j++)
@@ -189,7 +190,7 @@ else if(command == COMMAND.SHOW) {
console.log('To few arguments, dokimon '+COMMAND.SHOW+' myscript');
}
else {
- var t = require(testManager.scriptNameToPath(process.argv[3]));
+ var t = require(fixPath(testManager.scriptNameToPath(process.argv[3])));
if(t instanceof dokimon.Test)
t = [t];
for(var j=0; j < t.length; j++)
View
153 dokimon
@@ -3,136 +3,29 @@ var filesystem = require('fs'),
querystring = require('querystring');
/**
- * Utility function for extending object properties
- * @author tanepiper (github)
- */
-function extend() {
-
- var toString = Object.prototype.toString,
- hasOwn = Object.prototype.hasOwnProperty,
- // [[Class]] -> type pairs
- class2type = {};
-
- // Populate the class2type map
- "Boolean Number String Function Array Date RegExp Object".split(" ").forEach(function(name) {
- class2type[ "[object " + name + "]" ] = name.toLowerCase();
- });
-
- function type(obj){
- return obj == null ?
- String( obj ) :
- class2type[ toString.call(obj) ] || "object";
- }
-
- function isPlainObject( obj ) {
- if ( !obj || type(obj) !== "object") {
- return false;
- }
-
- // Not own constructor property must be Object
- if ( obj.constructor &&
- !hasOwn.call(obj, "constructor") &&
- !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
- return false;
- }
-
- // Own properties are enumerated firstly, so to speed up,
- // if last one is own, then all properties are own.
-
- var key;
- for ( key in obj ) {}
-
- return key === undefined || hasOwn.call( obj, key );
- }
-
- var options, name, src, copy, copyIsArray, clone,
- target = arguments[0] || {},
- i = 1,
- length = arguments.length,
- deep = false;
-
- // Handle a deep copy situation
- if ( typeof target === "boolean" ) {
- deep = target;
- target = arguments[1] || {};
- // skip the boolean and the target
- i = 2;
- }
-
- // Handle case when target is a string or something (possible in deep copy)
- if ( typeof target !== "object" && type(target) !== "function") {
- target = {};
- }
-
- // extend jQuery itself if only one argument is passed
- if ( length === i ) {
- target = this;
- --i;
- }
-
- for ( ; i < length; i++ ) {
- // Only deal with non-null/undefined values
- if ( (options = arguments[ i ]) != null ) {
- // Extend the base object
- for ( name in options ) {
- src = target[ name ];
- copy = options[ name ];
-
- // Prevent never-ending loop
- if ( target === copy ) {
- continue;
- }
-
- // Recurse if we're merging plain objects or arrays
- if ( deep && copy && ( isPlainObject(copy) || (copyIsArray = type(copy) === "array") ) ) {
- if ( copyIsArray ) {
- copyIsArray = false;
- clone = src && type(src) === "array" ? src : [];
-
- } else {
- clone = src && isPlainObject(src) ? src : {};
- }
-
- // Never move original objects, clone them
- target[ name ] = extend( deep, clone, copy );
-
- // Don't bring in undefined values
- } else if ( copy !== undefined ) {
- target[ name ] = copy;
- }
- }
- }
- }
-
- // Return the modified object
- return target;
-}
-
-/**
* @param {Object} options
* @return {Object}
*/
function mergeWithDefaultOptions(options) {
- var o = extend({
- port : 80,
- method : 'GET',
- headers : {},
- write : ''
- }, options);
- if(o.headers['Content-Length'] == undefined && typeof o.write == 'string')
- o.headers['Content-Length'] = Buffer.byteLength(o.write, 'utf8');
-
- if(o.url == undefined)
+ if(options.url == undefined)
throw new Error('property url missing from options');
- if(typeof o.url == 'object')
- o.path = querystring.stringify(o.url);
+ if(options.port == undefined)
+ options.port = 80;
+ if(options.headers == undefined)
+ options.headers = {};
+ if(options.write == undefined)
+ options.write = '';
+ if(options.method == undefined)
+ options.method = 'GET';
+ if(options.headers['Content-Length'] == undefined && typeof options.write == 'string')
+ options.headers['Content-Length'] = Buffer.byteLength(options.write, 'utf8');
+ if(typeof options.url == 'object')
+ options.path = querystring.stringify(options.url);
else
- o.path = o.url;
-
- if(o.headers['User-Agent'] == undefined)
- o['User-Agent'] = 'node dokimon 0.1';
+ options.path = options.url;
- return o;
+ if(options.headers['User-Agent'] == undefined)
+ options['User-Agent'] = 'node dokimon scraper';
}
@@ -242,10 +135,6 @@ var TestManager = function(config, testFinishCallback) {
if(!_hasDokimonExtension(testFileName))
testFileName += TestManager.TEST_EXTENSION;
- var firsLetter = testFileName.substr(0,1);
- if(firsLetter != '.' && firsLetter != '/')
- testFileName = './'+testFileName;
-
return testFileName;
};
@@ -314,7 +203,7 @@ TestManager.TEST_EXTENSION = '.dokimon';
* * * * * * * * * * * * * * * * * * * * * * * * */
var Test = function(testName, options, callback, blocking) {
- options = mergeWithDefaultOptions(options);
+ mergeWithDefaultOptions(options);
this.blocking = blocking;
this.name = testName;
@@ -370,8 +259,7 @@ var Test = function(testName, options, callback, blocking) {
* @param {Boolean} blocking - Optional, whether or not this test is supposed to finish before running any other tests
* * * * * * * * * * * * * * * * * * * * * * * * */
var TestFormPost = function(testName, options, callback, blocking) {
-
- options = mergeWithDefaultOptions(options);
+ mergeWithDefaultOptions(options);
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
if(typeof(options.write) == 'object')
options.write = querystring.stringify(options.write);
@@ -398,6 +286,11 @@ module.exports = {
Test : Test,
/**
+ * @return {TestFormPost}
+ */
+ TestFormPost: TestFormPost,
+
+ /**
* @param {Test} t
*/
runTest : function(t, config, testFinishCallback) {
View
@@ -2,7 +2,13 @@
"author": "Victor Jonsson <kontakt@victorjonsson.se> (http://victorjonsson.se)",
"name": "dokimon",
"description": "A simple framework that is used for test automation. Write tests for a website or web service and manage them with a command line interface",
- "version": "0.0.1",
+ "version": "0.0.12",
+ "homepage": "https://github.com/victorjonsson/dokimon",
+ "keywords": ["test","tests","scraping","node.js", "automation", "testing"],
+ "licenses": [{
+ "type": "MIT",
+ "url": "https://raw.github.com/mmstud/scribe-node/master/LICENSE"
+ }],
"repository": {
"type": "git",
"url": "git@github.com:victorjonsson/dokimon.git"

0 comments on commit 66f81a6

Please sign in to comment.