Skip to content

Commit

Permalink
Add a test for the recursive queue example in README using cheerio
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvalla committed Nov 8, 2014
1 parent bb50cf4 commit 23476c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
3 changes: 0 additions & 3 deletions lib/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ var zlib = require('zlib');
var fs = require('fs');
var Pool = require('generic-pool').Pool;

var debug = require('./debug');

// Fallback on iconv-lite if we didn't succeed compiling iconv
// https://github.com/sylvinus/node-crawler/pull/29
var iconv, iconvLite;
Expand Down Expand Up @@ -46,7 +44,6 @@ function readJqueryUrl (url, callback) {
callback(err, jq);
});
} else {
debug('Unable to load jquery from file', url);
callback(null, url);
}
}
Expand Down
32 changes: 24 additions & 8 deletions tests/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

var Crawler = require('../lib/crawler');
var expect = require('chai').expect;
var c;
var httpbinHost = 'localhost:8000';
var sinon = require('sinon');
var url = require('url');
var c, spy;

describe('Simple test', function() {
beforeEach(function() {
c = new Crawler({
forceUTF8: true
});
});
afterEach(function() {
c = {};
spy = {};
});
it('should run the readme examples', function(done) {
it('should run the first readme examples', function(done) {
c = new Crawler({
maxConnections: 10,
jquery: true,
onDrain: function() {
done();
},
Expand All @@ -26,6 +24,24 @@ describe('Simple test', function() {
});
c.queue('http://google.com');
});
it('should run the readme examples', function(done) {
c = new Crawler({
maxConnections: 10,
onDrain: function() {
expect(spy.calledTwice).to.be.true;
done();
},
callback: function(error, result, $) {
var baseUrl = result.uri;
$('a').each(function(index, a) {
var toQueueUrl = url.resolve(baseUrl, $(a).attr('href'));
c.queue(toQueueUrl);
});
}
});
spy = sinon.spy(c, 'queue');
c.queue('http://'+httpbinHost+'/links/1/1');
});
it('should run the with an array queue', function(done) {
c = new Crawler();
c.queue([{
Expand Down
2 changes: 1 addition & 1 deletion tests/linksResolving.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Links', function() {
}
}]);
});
it('should resolved links to absolute urls after redirect', function(done) {
it('should resolved links to absolute urls after redirect with jsdom', function(done) {
c.queue([{
uri : 'http://'+httpbinHost+'/redirect-to?url=http://example.com/',
callback: function(error, result) {
Expand Down
2 changes: 1 addition & 1 deletion tests/uriOption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('chai').expect;
var httpbinHost = 'localhost:8000';
var c;

describe('Simple test', function() {
describe('Uri Options', function() {
afterEach(function() {
c = {};
});
Expand Down

0 comments on commit 23476c0

Please sign in to comment.