Browse files

new release, v 0.0.17

  • Loading branch information...
1 parent 83bb576 commit 9b45b3e8c8159d2986960c36380eac7268334e2e @victorjonsson committed Feb 28, 2012
Showing with 48 additions and 9 deletions.
  1. +4 −3 CHANGELOG.md
  2. +43 −5 dokimon
  3. +1 −1 package.json
View
7 CHANGELOG.md
@@ -4,8 +4,7 @@
First beta release
## v. 0.0.15
-Moved callback into a class function to make it possible for
-extending class to override the execute() function
+Moved callback into a class function to make it possible for extending class to override the execute() function
## v 0.0.16
- Added comments
@@ -15,4 +14,6 @@ extending class to override the execute() function
## v 0.0.17
- Added comments
- - Fixed bug, callback function did not run on request error
+ - Now following redirects
+ - Fixed bug, callback function did not run on request error
+ - Fixed bug, not possible to use the same cookies for several tests
View
48 dokimon
@@ -254,7 +254,7 @@ var Test = function(testName, options, callback, blocking) {
manager.log(testName+" recieved response from "+options.host+options.path+" "+_formatJSON(res.headers)+"\n");
if(res.headers['set-cookie'] != undefined)
- Test.lastCookies = _setToGetCookies(res.headers['set-cookie']);
+ Test.lastCookies = _setToGetCookies(res.headers['set-cookie'], Test.lastCookies ? Test.lastCookies:'');
var loc = res.headers.location == undefined ? res.headers.Location : res.headers.location;
if(loc != undefined) {
@@ -268,6 +268,7 @@ var Test = function(testName, options, callback, blocking) {
options.path = loc;
if(options.path.indexOf(options.host) > -1) {
options.path = options.path.split(options.host)[1];
+ options.url = options.path;
}
self.execute(options.host, manager, verbose, exeFinishCallback);
@@ -319,14 +320,51 @@ var Test = function(testName, options, callback, blocking) {
/**
* @access private
* @param {Array} responseCookies
+ * @param {String} currentCookies
* @return {String}
*/
- var _setToGetCookies = function(responseCookies) {
- var cookies = '';
- for(var i=0; i < responseCookies.length; i++) {
- cookies += ', '+responseCookies[i].split(';')[0];
+ var _setToGetCookies = function(responseCookies, currentCookies) {
+ var currentCookiesObj = {};
+ var currentCookieParts = currentCookies.split(';');
+ var cookies = '', i;
+
+ // Build up an object with all current cookies
+ for(i=0; i < currentCookieParts.length; i++) {
+ var p = currentCookieParts[i].split('=');
+ if(p.length > 1)
+ currentCookiesObj[p[0].trim()] = p[1].trim();
}
+
+ // Go through repsonse cookies and determine which
+ // has expired or new cookies
+ var now = new Date().getTime();
+ for(i=0; i < responseCookies.length; i++) {
+ var cookieParts = responseCookies[i].split(';');
+ var cookieName = cookieParts[0].split('=')[0];
+ if(typeof currentCookiesObj[cookieName] != 'undefined') {
+ // maybe expired
+ for(var j=0; j < cookieParts.length; j++) {
+ var cookieArgs = cookieParts[j].split('=');
+ if(cookieArgs[0] == 'expires') {
+ var d = new Date(cookieArgs[0]);
+ if(d.getTime() < now) {
+ currentCookiesObj[cookieName] = false;
+ }
+ }
+ }
+ }
+
+ cookies += '; '+cookieParts[0];
+ }
+
+ // Append previous cookies (which is not deleted by expire argument)
+ Object.keys(currentCookiesObj).forEach(function(k) {
+ var val = currentCookiesObj[k];
+ if(val)
+ cookies += '; '+k+'='+val;
+ });
+
return cookies.length == 0 ? '': cookies.substr(2, cookies.length);
};
View
2 package.json
@@ -2,7 +2,7 @@
"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.16",
+ "version": "0.0.17",
"homepage": "https://github.com/victorjonsson/nodejs-dokimon",
"keywords": ["test","tests","scraping","node.js", "automation", "testing"],
"licenses": [{

0 comments on commit 9b45b3e

Please sign in to comment.