Skip to content

Commit

Permalink
Fix for #120
Browse files Browse the repository at this point in the history
when creating a crawler without any options cause the creation to fail
  • Loading branch information
paulvalla committed Oct 23, 2014
1 parent 5f4a262 commit bf62dda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function useCache(options) {
}

function checkJQueryNaming (options) {
if (typeof options.jquery !== 'undefined' && typeof options.jQuery === 'undefined') {
if (typeof options.jquery !== 'undefined') {
options.jQuery = options.jquery;
delete options.jquery;
}
Expand All @@ -35,16 +35,7 @@ function checkJQueryNaming (options) {
Crawler.prototype.init = function (options) {
var self = this;

// you can use jquery or jQuery
options = checkJQueryNaming(options);

// if using rateLimits we want to use only one connection with delay in between requests
if (options.rateLimits !== 0) {
options.maxConnections = 1;
}

//Default options
self.options = _.extend({
var defaultOptions = {
autoWindowClose: true,
cache: false, //false,true, [ttl?]
forceUTF8: false,
Expand All @@ -64,7 +55,18 @@ Crawler.prototype.init = function (options) {
rateLimits: 0,
referer: false,
incomingEncoding: null
},options);
};

//return defaultOptions with overriden properties from options.
self.options = _.extend(defaultOptions, options);

// you can use jquery or jQuery
self.options = checkJQueryNaming(self.options);

// if using rateLimits we want to use only one connection with delay in between requests
if (self.options.rateLimits !== 0) {
self.options.maxConnections = 1;
}

// Don't make these options persist to individual queries
var globalOnlyOptions = ["maxConnections", "priorityRange", "onDrain"];
Expand Down
12 changes: 12 additions & 0 deletions test/units/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('Simple test', function() {
it('should run the readme examples', function(done) {
c = new Crawler({
maxConnections: 10,
jquery: true,
onDrain: function() {
done();
},
Expand All @@ -141,6 +142,17 @@ describe('Simple test', function() {
});
c.queue('http://google.com');
});
it('should run the with an array queue', function(done) {
c = new Crawler();
c.queue([{
uri: 'http://www.google.com',
jquery: true,
callback : function(error,result,$) {
expect(typeof result.body).to.equal('string');
done();
}
}]);
});
it('should work if uri is a function', function(done) {
var statusCode = 200;
var uriFunction = function(statusCode) {
Expand Down

0 comments on commit bf62dda

Please sign in to comment.