Skip to content

Commit

Permalink
added script to test all versions of jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascloud committed Aug 2, 2013
1 parent 3bdab27 commit e1714ee
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 118 deletions.
118 changes: 59 additions & 59 deletions lib/amplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,19 @@ amplify.request = function( resourceId, data, callback ) {
success = settings.success || noop,
error = settings.error || noop;

settings.success = async( function( data, status ) {
status = status || "success";
amplify.publish( "request.success", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
success( data, status );
});

settings.error = async( function( data, status ) {
status = status || "error";
amplify.publish( "request.error", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
error( data, status );
});
settings.success = async( function( data, status ) {
status = status || "success";
amplify.publish( "request.success", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
success( data, status );
});

settings.error = async( function( data, status ) {
status = status || "error";
amplify.publish( "request.error", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
error( data, status );
});

if ( !resource ) {
if ( !settings.resourceId ) {
Expand Down Expand Up @@ -517,7 +517,7 @@ amplify.request.define = function( resourceId, type, settings ) {
'use strict';

var xhrProps = [ "status", "statusText", "responseText", "responseXML", "readyState" ],
rurlData = /\{([^\}]+)\}/g;
rurlData = /\{([^\}]+)\}/g;

amplify.request.types.ajax = function( defnSettings ) {
defnSettings = $.extend({
Expand Down Expand Up @@ -593,31 +593,31 @@ amplify.request.types.ajax = function( defnSettings ) {
defnSettings, settings, ajaxSettings, ampXHR );

$.extend( ajaxSettings, {
isJSONP: function () {
return (/jsonp/gi).test(this.dataType);
},
cacheURL: function () {
if (!this.isJSONP()) {
return this.url;
}

var callbackName = 'callback';

// possible for the callback function name to be overridden
if (this.hasOwnProperty('jsonp')) {
if (this.jsonp !== false) {
callbackName = this.jsonp;
} else {
if (this.hasOwnProperty('jsonpCallback')) {
callbackName = this.jsonpCallback;
}
}
}

// search and replace callback parameter in query string with empty string
var callbackRegex = new RegExp('&?' + callbackName + '=[^&]*&?', 'gi');
return this.url.replace(callbackRegex, '');
},
isJSONP: function () {
return (/jsonp/gi).test(this.dataType);
},
cacheURL: function () {
if (!this.isJSONP()) {
return this.url;
}

var callbackName = 'callback';

// possible for the callback function name to be overridden
if (this.hasOwnProperty('jsonp')) {
if (this.jsonp !== false) {
callbackName = this.jsonp;
} else {
if (this.hasOwnProperty('jsonpCallback')) {
callbackName = this.jsonpCallback;
}
}
}

// search and replace callback parameter in query string with empty string
var callbackRegex = new RegExp('&?' + callbackName + '=[^&]*&?', 'gi');
return this.url.replace(callbackRegex, '');
},
success: function( data, status ) {
handleResponse( data, status );
},
Expand All @@ -634,12 +634,12 @@ amplify.request.types.ajax = function( defnSettings ) {
}
});

// cache all JSONP requests
if (ajaxSettings.isJSONP()) {
$.extend(ajaxSettings, {
cache: true
});
}
// cache all JSONP requests
if (ajaxSettings.isJSONP()) {
$.extend(ajaxSettings, {
cache: true
});
}

$.ajax( ajaxSettings );

Expand Down Expand Up @@ -705,25 +705,25 @@ amplify.subscribe( "request.ajax.preprocess", function( defnSettings, settings,
var cache = amplify.request.cache = {
_key: function( resourceId, url, data ) {
data = url + data;
var length = data.length,
var length = data.length,
i = 0;

/*jshint bitwise:false*/
function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}
/*jshint bitwise:false*/
function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}

var checksum = chunk();
while ( i < length ) {
checksum ^= chunk();
}
/*jshint bitwise:true*/
var checksum = chunk();
while ( i < length ) {
checksum ^= chunk();
}
/*jshint bitwise:true*/

return "request-" + resourceId + "-" + checksum;
},
},

_default: (function() {
var memoryStore = {};
Expand Down
118 changes: 59 additions & 59 deletions lib/amplify.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ amplify.request = function( resourceId, data, callback ) {
success = settings.success || noop,
error = settings.error || noop;

settings.success = async( function( data, status ) {
status = status || "success";
amplify.publish( "request.success", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
success( data, status );
});

settings.error = async( function( data, status ) {
status = status || "error";
amplify.publish( "request.error", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
error( data, status );
});
settings.success = async( function( data, status ) {
status = status || "success";
amplify.publish( "request.success", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
success( data, status );
});

settings.error = async( function( data, status ) {
status = status || "error";
amplify.publish( "request.error", settings, data, status );
amplify.publish( "request.complete", settings, data, status );
error( data, status );
});

if ( !resource ) {
if ( !settings.resourceId ) {
Expand Down Expand Up @@ -111,7 +111,7 @@ amplify.request.define = function( resourceId, type, settings ) {
'use strict';

var xhrProps = [ "status", "statusText", "responseText", "responseXML", "readyState" ],
rurlData = /\{([^\}]+)\}/g;
rurlData = /\{([^\}]+)\}/g;

amplify.request.types.ajax = function( defnSettings ) {
defnSettings = $.extend({
Expand Down Expand Up @@ -187,31 +187,31 @@ amplify.request.types.ajax = function( defnSettings ) {
defnSettings, settings, ajaxSettings, ampXHR );

$.extend( ajaxSettings, {
isJSONP: function () {
return (/jsonp/gi).test(this.dataType);
},
cacheURL: function () {
if (!this.isJSONP()) {
return this.url;
}

var callbackName = 'callback';

// possible for the callback function name to be overridden
if (this.hasOwnProperty('jsonp')) {
if (this.jsonp !== false) {
callbackName = this.jsonp;
} else {
if (this.hasOwnProperty('jsonpCallback')) {
callbackName = this.jsonpCallback;
}
}
}

// search and replace callback parameter in query string with empty string
var callbackRegex = new RegExp('&?' + callbackName + '=[^&]*&?', 'gi');
return this.url.replace(callbackRegex, '');
},
isJSONP: function () {
return (/jsonp/gi).test(this.dataType);
},
cacheURL: function () {
if (!this.isJSONP()) {
return this.url;
}

var callbackName = 'callback';

// possible for the callback function name to be overridden
if (this.hasOwnProperty('jsonp')) {
if (this.jsonp !== false) {
callbackName = this.jsonp;
} else {
if (this.hasOwnProperty('jsonpCallback')) {
callbackName = this.jsonpCallback;
}
}
}

// search and replace callback parameter in query string with empty string
var callbackRegex = new RegExp('&?' + callbackName + '=[^&]*&?', 'gi');
return this.url.replace(callbackRegex, '');
},
success: function( data, status ) {
handleResponse( data, status );
},
Expand All @@ -228,12 +228,12 @@ amplify.request.types.ajax = function( defnSettings ) {
}
});

// cache all JSONP requests
if (ajaxSettings.isJSONP()) {
$.extend(ajaxSettings, {
cache: true
});
}
// cache all JSONP requests
if (ajaxSettings.isJSONP()) {
$.extend(ajaxSettings, {
cache: true
});
}

$.ajax( ajaxSettings );

Expand Down Expand Up @@ -299,25 +299,25 @@ amplify.subscribe( "request.ajax.preprocess", function( defnSettings, settings,
var cache = amplify.request.cache = {
_key: function( resourceId, url, data ) {
data = url + data;
var length = data.length,
var length = data.length,
i = 0;

/*jshint bitwise:false*/
function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}
/*jshint bitwise:false*/
function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}

var checksum = chunk();
while ( i < length ) {
checksum ^= chunk();
}
/*jshint bitwise:true*/
var checksum = chunk();
while ( i < length ) {
checksum ^= chunk();
}
/*jshint bitwise:true*/

return "request-" + resourceId + "-" + checksum;
},
},

_default: (function() {
var memoryStore = {};
Expand Down
54 changes: 54 additions & 0 deletions test-jquery-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';
var path = require('path' ),
fs = require('fs' ),
exec = require('child_process' ).exec,
EOL = require('os' ).EOL,
async = require('async' );

var PORT = process.argv[2] || 1982, //1982 is strata default
EXEC_DELAY = process.argv[3] || 10000; //10 seconds between exection by default; gives tests time to run

var EXTERNAL_DIR = path.join(__dirname, 'external' ),
JQUERY_REGEX = /^jquery-([\d]+\.[\d](?:\.[\d]+)?)\.js$/,
TEST_URL = 'http://localhost:' + PORT + '/test/index.html?jquery=';

function isNotWhitespace(str) {
return str.trim().length > 0;
}

if (!fs.existsSync(EXTERNAL_DIR)) {
console.error('cannot locate jquery files');
process.exit(1);
}

fs.readdir(EXTERNAL_DIR, function (err, files) {
if (err) {
return console.error(err);
}
files = files.filter(function (file) {
return JQUERY_REGEX.test(file);
});
var handlers = files.map(function (file) {
var jqueryVersion = JQUERY_REGEX.exec(file)[1];
JQUERY_REGEX.lastIndex = 0;
var testURL = TEST_URL + jqueryVersion;

return function (cb) {
console.log('opening ' + testURL);
exec('open ' + testURL, function (err, stdout, stderr) {
setTimeout(function () {
if (err) {
return cb(err.code + ': ' + stderr.toString());
}
cb(null, stdout.toString());
}, EXEC_DELAY);
});
};
});
async.series(handlers, function (err, results) {
if (err) {
return console.error(err);
}
console.log(results.filter(isNotWhitespace ).join(EOL));
});
});

0 comments on commit e1714ee

Please sign in to comment.